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.Metadata.Builders;
namespace HackathonPreparing.ApiService.UserSlice.EfCore.EntityTypeConfigurations;
namespace HackathonPreparing.ApiService.Auth.EfCore;
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.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.Auth.EfCore;
namespace HackathonPreparing.ApiService.UserSlice.EfCore;
public class UserContext : IdentityDbContext<User, IdentityRole<int>, int>
public class UserContext : IdentityDbContext<Auth.User, IdentityRole<int>, int>
{
public UserContext (DbContextOptions<UserContext> options) : base(options) {}

View File

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

View File

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

View File

@ -1,5 +1,3 @@
using HackathonPreparing.ApiService.UserSlice.EfCore.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -55,8 +53,8 @@ public static class DbHelpersEndpointsExtensions
return Results.Ok();
});
group.MapPost("/add-moderator", async ([FromServices]UserManager<User> userManager) => {
var user = new User{
group.MapPost("/add-moderator", async ([FromServices]UserManager<Auth.User> userManager) => {
var user = new Auth.User{
Email = "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.UserSlice.EfCore;
using HackathonPreparing.ApiService.UserSlice.EfCore.Models;
using HackathonPreparing.ApiService.UserSlice.OpenApi;
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore;
using HackathonPreparing.ApiService.WeatherForecastSlice.Endpoints;
using HackathonPreparing.ApiService.WeatherForecast;
using HackathonPreparing.ApiService.WeatherForecast.EfCore;
using HackathonPreparing.ServiceDefaults;
using Microsoft.AspNetCore.Identity;
using Microsoft.OpenApi.Models;

View File

@ -1,7 +1,6 @@
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.WeatherForecastSlice.EfCore;
namespace HackathonPreparing.ApiService.WeatherForecast.EfCore;
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)
{

View File

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

View File

@ -1,8 +1,7 @@
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore;
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
using HackathonPreparing.ApiService.WeatherForecast.EfCore;
using Microsoft.EntityFrameworkCore;
namespace HackathonPreparing.ApiService.WeatherForecastSlice.Endpoints;
namespace HackathonPreparing.ApiService.WeatherForecast;
public static class WeatherForecastEndpointsExtensions
{
@ -23,14 +22,14 @@ public static class WeatherForecastEndpointsExtensions
return Results.NoContent();
}).RequireAuthorization("moderator");
group.MapPost("/", async (WeatherForecastContext db, WeatherForecast forecast) =>
group.MapPost("/", async (WeatherForecastContext db, ApiService.WeatherForecast.WeatherForecast forecast) =>
{
db.Forecasts.Add(forecast);
await db.SaveChangesAsync();
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)
{

View File

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

View File

@ -2,12 +2,13 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
namespace Microsoft.Extensions.Hosting;
namespace HackathonPreparing.ServiceDefaults;
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// 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.Components;