features/api-cleanup #15

Merged
jtom38 merged 13 commits from features/api-cleanup into main 2023-07-29 09:47:30 -07:00
5 changed files with 7 additions and 9 deletions
Showing only changes of commit fa14562fd4 - Show all commits

View File

@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newsbot.Collector.Api.Authentication; using Newsbot.Collector.Api.Authentication;
using Newsbot.Collector.Api.Middleware;
using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Interfaces;

View File

@ -1,14 +1,9 @@
namespace Newsbot.Collector.Api.Authentication; namespace Newsbot.Collector.Api.Middleware;
public static class JwtUserIdExtension public static class JwtUserIdExtension
{ {
public static string GetUserId(this HttpContext context) public static string GetUserId(this HttpContext context)
{ {
if (context.User == null)
{
return string.Empty;
}
return context.User.Claims.Single(x => x.Type == "id").Value; return context.User.Claims.Single(x => x.Type == "id").Value;
} }
} }

View File

@ -4,6 +4,8 @@
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -35,7 +35,7 @@ GlobalConfiguration.Configuration.UseSerilogLogProvider();
// Build Health Checks // Build Health Checks
builder.Services.AddHealthChecks() builder.Services.AddHealthChecks()
.AddNpgSql(config.GetValue<string>(ConfigConnectionStringConst.Database) ?? ""); .AddNpgSql(config.GetValue<string>(ConfigConst.ConnectionStringDatabase) ?? "");
builder.Services.AddControllers(); builder.Services.AddControllers();
@ -109,7 +109,7 @@ static IConfiguration GetConfiguration()
static ILogger GetLogger(IConfiguration configuration) static ILogger GetLogger(IConfiguration configuration)
{ {
var otel = configuration.GetValue<string>(ConfigConnectionStringConst.OpenTelemetry) ?? ""; var otel = configuration.GetValue<string>(ConfigConst.ConnectionStringOpenTelemetry) ?? "";
if (otel == "") if (otel == "")
return Log.Logger = new LoggerConfiguration() return Log.Logger = new LoggerConfiguration()

View File

@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newsbot.Collector.Api.Domain; using Newsbot.Collector.Api.Domain;
using Newsbot.Collector.Api.Services;
using Newsbot.Collector.Database; using Newsbot.Collector.Database;
using Newsbot.Collector.Database.Repositories; using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Services;
namespace Newsbot.Collector.Api.Startup; namespace Newsbot.Collector.Api.Startup;