Refactoring V3

This commit is contained in:
Sergey Karmanov 2024-06-20 00:24:57 +03:00
parent 0f710abf3c
commit 34eaf01df0
16 changed files with 25 additions and 41 deletions

View File

@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace HackathonPreparing.ApiService.AuthFeature.EfCore; namespace HackathonPreparing.ApiService.Features.AuthFeature.EfCore;
public class IdentityRoleEntityTypeConfiguration : IEntityTypeConfiguration<IdentityRole<int>> public class IdentityRoleEntityTypeConfiguration : IEntityTypeConfiguration<IdentityRole<int>>
{ {

View File

@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.AuthFeature.EfCore; namespace HackathonPreparing.ApiService.Features.AuthFeature.EfCore;
public class UserContext : IdentityDbContext<User, IdentityRole<int>, int> public class UserContext : IdentityDbContext<User, IdentityRole<int>, int>
{ {
@ -11,8 +11,6 @@ public class UserContext : IdentityDbContext<User, IdentityRole<int>, int>
} }
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)
{ {
base.OnModelCreating(builder); base.OnModelCreating(builder);

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
namespace HackathonPreparing.ApiService.AuthFeature; namespace HackathonPreparing.ApiService.Features.AuthFeature;
public class User : IdentityUser<int> public class User : IdentityUser<int>
{ {

View File

@ -3,7 +3,7 @@ using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
namespace HackathonPreparing.ApiService.AuthFeature; namespace HackathonPreparing.ApiService.Features.AuthFeature;
public class UserOpenApiSchemeFilter : ISchemaFilter public class UserOpenApiSchemeFilter : ISchemaFilter
{ {

View File

@ -1,11 +1,10 @@
using HackathonPreparing.ApiService.Features.AuthFeature;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.SwaggerGen;
using static HackathonPreparing.ApiService.Features.DevFeature.ReflectionHelpers; using static HackathonPreparing.ApiService.Features.DevFeature.ReflectionHelpers;
namespace HackathonPreparing.ApiService.Features.DevFeature;
namespace HackathonPreparing.ApiService.DevFeature;
public static class DbHelpersEndpointsExtensions public static class DbHelpersEndpointsExtensions
{ {
@ -70,8 +69,8 @@ public static class DbHelpersEndpointsExtensions
}); });
group.MapPost("/add-moderator", async ([FromServices]UserManager<AuthFeature.User> userManager) => { group.MapPost("/add-moderator", async ([FromServices]UserManager<User> userManager) => {
var user = new AuthFeature.User{ var user = new User{
Email = "m@gmail.com", Email = "m@gmail.com",
UserName = "m@gmail.com" UserName = "m@gmail.com"
}; };

View File

@ -1,7 +1,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.Features.DevFeature;
namespace HackathonPreparing.ApiService.DevFeature;
public static class ServicesExtensions public static class ServicesExtensions
{ {

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; namespace HackathonPreparing.ApiService.Features.WeatherForecastFeature.EfCore;
public sealed class WeatherForecastContext : DbContext public sealed class WeatherForecastContext : DbContext
{ {

View File

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; namespace HackathonPreparing.ApiService.Features.WeatherForecastFeature.EfCore;
public class WeatherForecastEntityTypeConfiguration : IEntityTypeConfiguration<WeatherForecast> public class WeatherForecastEntityTypeConfiguration : IEntityTypeConfiguration<WeatherForecast>
{ {

View File

@ -1,8 +1,8 @@
using HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; using HackathonPreparing.ApiService.Features.WeatherForecastFeature.EfCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.WeatherForecastFeature; namespace HackathonPreparing.ApiService.Features.WeatherForecastFeature;
public static class WeatherForecastEndpointsExtensions public static class WeatherForecastEndpointsExtensions
{ {

View File

@ -1,4 +1,4 @@
namespace HackathonPreparing.ApiService.WeatherForecastFeature; namespace HackathonPreparing.ApiService.Features.WeatherForecastFeature;
public class WeatherForecast public class WeatherForecast
{ {

View File

@ -1,6 +1,6 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using HackathonPreparing.ApiService.AuthFeature.EfCore; using HackathonPreparing.ApiService.Features.AuthFeature.EfCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;

View File

@ -1,6 +1,6 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using HackathonPreparing.ApiService.AuthFeature.EfCore; using HackathonPreparing.ApiService.Features.AuthFeature.EfCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

View File

@ -1,6 +1,6 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; using HackathonPreparing.ApiService.Features.WeatherForecastFeature.EfCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;

View File

@ -1,5 +1,4 @@
using System; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable #nullable disable

View File

@ -1,6 +1,6 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; using HackathonPreparing.ApiService.Features.WeatherForecastFeature.EfCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

View File

@ -1,8 +1,8 @@
using HackathonPreparing.ApiService.AuthFeature; using HackathonPreparing.ApiService.Features.AuthFeature;
using HackathonPreparing.ApiService.AuthFeature.EfCore; using HackathonPreparing.ApiService.Features.AuthFeature.EfCore;
using HackathonPreparing.ApiService.DevFeature; using HackathonPreparing.ApiService.Features.DevFeature;
using HackathonPreparing.ApiService.WeatherForecastFeature; using HackathonPreparing.ApiService.Features.WeatherForecastFeature;
using HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; using HackathonPreparing.ApiService.Features.WeatherForecastFeature.EfCore;
using HackathonPreparing.ServiceDefaults; using HackathonPreparing.ServiceDefaults;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
@ -38,11 +38,7 @@ builder.Services.AddSwaggerGen(c =>
//we dont need it now //we dont need it now
//builder.AddServiceDefaults(); //builder.AddServiceDefaults();
builder.Services.AddAuthorization(); builder.Services.AddAuthorization();
builder.Services.AddAuthentication().AddBearerToken(); builder.Services.AddAuthentication().AddBearerToken();
builder.Services builder.Services
@ -57,8 +53,6 @@ builder.AddDbContextWithDefaultConfiguration<UserContext>();
var app = builder.Build(); var app = builder.Build();
app.UsePathBase("/api"); app.UsePathBase("/api");
app.UseRouting(); app.UseRouting();
@ -73,20 +67,15 @@ if (app.Environment.IsDevelopment())
app.AddDbHelpersEndpoints(); app.AddDbHelpersEndpoints();
} }
//Configure the HTTP request pipeline. //Configure the HTTP request pipeline.
app.UseExceptionHandler(); app.UseExceptionHandler();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.AddWeatherForecastEndpoints(); app.AddWeatherForecastEndpoints();
app.MapDefaultEndpoints(); app.MapDefaultEndpoints();
app.MapGroup("user") app.MapGroup("user")
.MapIdentityApi<User>() .MapIdentityApi<User>()
.WithTags("user"); .WithTags("user");