This commit is contained in:
Халимов Рустам
2026-02-09 23:54:03 +03:00
parent c98c96e408
commit ee40b38968
65 changed files with 6157 additions and 957 deletions
@@ -0,0 +1,34 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Nashel.Modules.Identity.Domain.Aggregates;
using Nashel.Modules.Identity.Domain.Enums;
namespace Nashel.Modules.Identity.Infrastructure.Persistence.Configurations;
public class AccountConfiguration : IEntityTypeConfiguration<Account>
{
public void Configure(EntityTypeBuilder<Account> builder)
{
builder.ToTable("Accounts", "identity");
builder.HasKey(x => x.Id);
builder.Property(x => x.Phone)
.IsRequired()
.HasMaxLength(20);
builder.HasIndex(x => x.Phone)
.IsUnique();
builder.Property(x => x.PasswordHash)
.IsRequired();
// Хранение ролей как JSONB для простоты и совместимости с AOT (используя генерацию кода System.Text.Json при необходимости)
builder.Property(x => x.Roles)
.HasConversion(
v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
v => JsonSerializer.Deserialize<List<Role>>(v, (JsonSerializerOptions?)null) ?? new List<Role>())
.HasColumnType("jsonb");
}
}
@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using Nashel.Modules.Identity.Domain.Aggregates;
using Nashel.Modules.Identity.Infrastructure.Persistence.Configurations;
namespace Nashel.Modules.Identity.Infrastructure.Persistence;
public class IdentityDbContext : DbContext
{
public IdentityDbContext(DbContextOptions<IdentityDbContext> options) : base(options)
{
}
public DbSet<Account> Accounts { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new AccountConfiguration());
base.OnModelCreating(modelBuilder);
}
}