Refactoring
This commit is contained in:
parent
304e7bf5f5
commit
75ca4337b9
@ -1,10 +1,12 @@
|
||||
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using HackathonPreparing.ApiService.UserSlice.EfCore.Models;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace HackathonPreparing.ApiService.GlobalHelpers;
|
||||
|
||||
public static class DbHelpersEndpointsExtensions
|
||||
{
|
||||
public static RouteGroupBuilder AddDbHelpersEndpoints(this WebApplication app)
|
@ -1,9 +1,8 @@
|
||||
|
||||
|
||||
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
namespace HackathonPreparing.ApiService.GlobalHelpers;
|
||||
|
||||
public static class ServicesExtensions
|
||||
{
|
||||
|
@ -1,4 +1,9 @@
|
||||
using HackathonPreparing.ApiService;
|
||||
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 Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
|
@ -1,12 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
//Example how add Fluent Building in project
|
||||
public class UserEntityTypeConfiguration : IEntityTypeConfiguration<User>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<User> builder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HackathonPreparing.ApiService.User
|
||||
{
|
||||
public class UserController : Controller
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,9 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
namespace HackathonPreparing.ApiService.UserSlice.EfCore.EntityTypeConfigurations;
|
||||
|
||||
public class IdentityRoleEntityTypeConfiguration : IEntityTypeConfiguration<IdentityRole<int>>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IdentityRole<int>> builder)
|
@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace HackathonPreparing.ApiService.UserSlice.EfCore.Models;
|
||||
|
||||
public class User : IdentityUser<int>
|
||||
{
|
||||
public string? AboutMe { get; set; }
|
@ -1,9 +1,11 @@
|
||||
|
||||
|
||||
using HackathonPreparing.ApiService.UserSlice.EfCore.Models;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
namespace HackathonPreparing.ApiService.UserSlice.EfCore;
|
||||
|
||||
public class UserContext : IdentityDbContext<User, IdentityRole<int>, int>
|
||||
{
|
||||
public UserContext (DbContextOptions<UserContext> options) : base(options) {}
|
@ -1,11 +1,11 @@
|
||||
|
||||
|
||||
using HackathonPreparing.ApiService.Migrations;
|
||||
using Microsoft.AspNetCore.Identity.Data;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
|
||||
namespace HackathonPreparing.ApiService.UserSlice.OpenApi;
|
||||
|
||||
public class UserOpenApiSchemeFilter : ISchemaFilter
|
||||
{
|
||||
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
||||
@ -14,13 +14,11 @@ public class UserOpenApiSchemeFilter : ISchemaFilter
|
||||
{
|
||||
schema.Example = new OpenApiObject()
|
||||
{
|
||||
["email"] = new OpenApiString("email@gmail.com"),
|
||||
["email"] = new OpenApiString("m@gmail.com"),
|
||||
["password"] = new OpenApiString("PassPass123_"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (context.Type == typeof(RegisterRequest))
|
||||
{
|
||||
schema.Example = new OpenApiObject()
|
@ -1,41 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HackathonPreparing.ApiService;
|
||||
|
||||
public sealed class WeatherForecastContext : DbContext
|
||||
{
|
||||
public WeatherForecastContext(DbContextOptions<WeatherForecastContext> options)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DbSet<WeatherForecast> Forecasts => Set<WeatherForecast>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<WeatherForecast>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
|
||||
// Generate data
|
||||
var summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
var forecast = Enumerable.Range(1, 5).Select(index =>
|
||||
new WeatherForecast
|
||||
(
|
||||
index,
|
||||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
Random.Shared.Next(-20, 55),
|
||||
summaries[Random.Shared.Next(summaries.Length)]
|
||||
))
|
||||
.ToArray();
|
||||
entity.HasData(forecast);
|
||||
});
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.EntityTypeConfigurations;
|
||||
|
||||
public class WeatherForecastEntityTypeConfiguration : IEntityTypeConfiguration<WeatherForecast>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<WeatherForecast> builder)
|
||||
{
|
||||
builder.HasKey(e => e.Id);
|
||||
builder.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
|
||||
// Generate data
|
||||
var summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
var forecast = Enumerable.Range(1, 5).Select(index =>
|
||||
new WeatherForecast
|
||||
(
|
||||
index,
|
||||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
Random.Shared.Next(-20, 55),
|
||||
summaries[Random.Shared.Next(summaries.Length)]
|
||||
))
|
||||
.ToArray();
|
||||
builder.HasData(forecast);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
namespace HackathonPreparing.ApiService;
|
||||
|
||||
namespace HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
@ -0,0 +1,22 @@
|
||||
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HackathonPreparing.ApiService.WeatherForecastSlice.EfCore;
|
||||
|
||||
public sealed class WeatherForecastContext : DbContext
|
||||
{
|
||||
public WeatherForecastContext(DbContextOptions<WeatherForecastContext> options)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DbSet<WeatherForecast> Forecasts => Set<WeatherForecast>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
builder.ApplyConfigurationsFromAssembly(typeof(Program).Assembly);
|
||||
builder.HasDefaultSchema("weatherforecast");
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
|
||||
|
||||
|
||||
using HackathonPreparing.ApiService;
|
||||
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore;
|
||||
using HackathonPreparing.ApiService.WeatherForecastSlice.EfCore.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public static class WeatherForecastExtensions
|
||||
namespace HackathonPreparing.ApiService.WeatherForecastSlice.Endpoints;
|
||||
|
||||
public static class WeatherForecastEndpointsExtensions
|
||||
{
|
||||
public static void AddWeatherForecastEndpoints (this WebApplication app)
|
||||
{
|
Loading…
x
Reference in New Issue
Block a user