Refactoring V2

This commit is contained in:
Sergey Karmanov 2024-06-19 05:02:35 +03:00
parent 75ca4337b9
commit 183728647e
12 changed files with 23 additions and 31 deletions

View File

@ -2,8 +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.Auth.EfCore;
namespace HackathonPreparing.ApiService.UserSlice.EfCore.EntityTypeConfigurations;
public class IdentityRoleEntityTypeConfiguration : IEntityTypeConfiguration<IdentityRole<int>> public class IdentityRoleEntityTypeConfiguration : IEntityTypeConfiguration<IdentityRole<int>>
{ {

View File

@ -1,12 +1,10 @@
using HackathonPreparing.ApiService.UserSlice.EfCore.Models;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.Auth.EfCore;
namespace HackathonPreparing.ApiService.UserSlice.EfCore; public class UserContext : IdentityDbContext<Auth.User, IdentityRole<int>, int>
public class UserContext : IdentityDbContext<User, IdentityRole<int>, int>
{ {
public UserContext (DbContextOptions<UserContext> options) : base(options) {} public UserContext (DbContextOptions<UserContext> options) : base(options) {}

View File

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

View File

@ -3,8 +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.Auth;
namespace HackathonPreparing.ApiService.UserSlice.OpenApi;
public class UserOpenApiSchemeFilter : ISchemaFilter public class UserOpenApiSchemeFilter : ISchemaFilter
{ {

View File

@ -1,5 +1,3 @@
using HackathonPreparing.ApiService.UserSlice.EfCore.Models;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -55,8 +53,8 @@ public static class DbHelpersEndpointsExtensions
return Results.Ok(); return Results.Ok();
}); });
group.MapPost("/add-moderator", async ([FromServices]UserManager<User> userManager) => { group.MapPost("/add-moderator", async ([FromServices]UserManager<Auth.User> userManager) => {
var user = new User{ var user = new Auth.User{
Email = "m@gmail.com", Email = "m@gmail.com",
UserName = "m@gmail.com" UserName = "m@gmail.com"
}; };

View File

@ -1,9 +1,9 @@
using HackathonPreparing.ApiService.Auth;
using HackathonPreparing.ApiService.Auth.EfCore;
using HackathonPreparing.ApiService.GlobalHelpers; using HackathonPreparing.ApiService.GlobalHelpers;
using HackathonPreparing.ApiService.UserSlice.EfCore; using HackathonPreparing.ApiService.WeatherForecast;
using HackathonPreparing.ApiService.UserSlice.EfCore.Models; using HackathonPreparing.ApiService.WeatherForecast.EfCore;
using HackathonPreparing.ApiService.UserSlice.OpenApi; using HackathonPreparing.ServiceDefaults;
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore;
using HackathonPreparing.ApiService.WeatherForecastSlice.Endpoints;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;

View File

@ -1,7 +1,6 @@
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.WeatherForecastSlice.EfCore; namespace HackathonPreparing.ApiService.WeatherForecast.EfCore;
public sealed class WeatherForecastContext : DbContext public sealed class WeatherForecastContext : DbContext
{ {
@ -11,7 +10,7 @@ public sealed class WeatherForecastContext : DbContext
} }
public DbSet<WeatherForecast> Forecasts => Set<WeatherForecast>(); public DbSet<WeatherForecast> Forecasts => Set<ApiService.WeatherForecast.WeatherForecast>();
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)
{ {

View File

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

View File

@ -1,8 +1,7 @@
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore; using HackathonPreparing.ApiService.WeatherForecast.EfCore;
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.WeatherForecastSlice.Endpoints; namespace HackathonPreparing.ApiService.WeatherForecast;
public static class WeatherForecastEndpointsExtensions public static class WeatherForecastEndpointsExtensions
{ {
@ -23,14 +22,14 @@ public static class WeatherForecastEndpointsExtensions
return Results.NoContent(); return Results.NoContent();
}).RequireAuthorization("moderator"); }).RequireAuthorization("moderator");
group.MapPost("/", async (WeatherForecastContext db, WeatherForecast forecast) => group.MapPost("/", async (WeatherForecastContext db, ApiService.WeatherForecast.WeatherForecast forecast) =>
{ {
db.Forecasts.Add(forecast); db.Forecasts.Add(forecast);
await db.SaveChangesAsync(); await db.SaveChangesAsync();
return Results.Created($"/weatherforecast/{forecast.Id}", forecast); return Results.Created($"/weatherforecast/{forecast.Id}", forecast);
}); });
group.MapPut("/{id}", async (WeatherForecastContext db, int id, WeatherForecast forecast) => group.MapPut("/{id}", async (WeatherForecastContext db, int id, ApiService.WeatherForecast.WeatherForecast forecast) =>
{ {
if (id != forecast.Id) if (id != forecast.Id)
{ {

View File

@ -1,5 +1,4 @@
namespace HackathonPreparing.ApiService.WeatherForecast;
namespace HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
public class WeatherForecast public class WeatherForecast
{ {

View File

@ -2,12 +2,13 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenTelemetry; using OpenTelemetry;
using OpenTelemetry.Metrics; using OpenTelemetry.Metrics;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
namespace Microsoft.Extensions.Hosting; namespace HackathonPreparing.ServiceDefaults;
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry. // Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution. // This project should be referenced by each service project in your solution.

View File

@ -1,3 +1,4 @@
using HackathonPreparing.ServiceDefaults;
using HackathonPreparing.Web; using HackathonPreparing.Web;
using HackathonPreparing.Web.Components; using HackathonPreparing.Web.Components;