Skip to content

Commit

Permalink
feat(users): add entities configurations and dbcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Jun 6, 2021
1 parent d6538cb commit 8bd200d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Armory.Users.Domain;
using Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace Armory.Users.Infrastructure.Persistence.EntityFramework
{
public class ArmoryUserDbContext : IdentityDbContext<ArmoryUser, ArmoryRole, string>
{
public ArmoryUserDbContext(DbContextOptions<ArmoryUserDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);

builder.ApplyConfiguration(new ArmoryRoleConfiguration());
builder.ApplyConfiguration(new ArmoryUserConfiguration());
builder.ApplyConfiguration(new ArmoryUserLogin());
builder.ApplyConfiguration(new ArmoryUserTokenConfiguration());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Armory.Users.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations
{
public class ArmoryRoleConfiguration : IEntityTypeConfiguration<ArmoryRole>
{
public void Configure(EntityTypeBuilder<ArmoryRole> builder)
{
builder.Property(p => p.Id).HasMaxLength(255);
builder.Property(p => p.Name).HasMaxLength(255);
builder.Property(p => p.NormalizedName).HasMaxLength(255);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Armory.Users.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations
{
public class ArmoryUserConfiguration : IEntityTypeConfiguration<ArmoryUser>
{
public void Configure(EntityTypeBuilder<ArmoryUser> builder)
{
builder.Property(p => p.Id).HasMaxLength(255);
builder.Property(p => p.UserName).HasMaxLength(15);
builder.Property(p => p.NormalizedUserName).HasMaxLength(15);
builder.Property(p => p.PasswordHash).HasMaxLength(255);
builder.Property(p => p.PhoneNumber).HasMaxLength(10);
builder.Property(p => p.Email).HasMaxLength(127);
builder.Property(p => p.NormalizedEmail).HasMaxLength(127);

builder.HasIndex(p => p.Email).IsUnique();
builder.HasIndex(p => p.PhoneNumber).IsUnique();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations
{
public class ArmoryUserLogin : IEntityTypeConfiguration<IdentityUserLogin<string>>
{
public void Configure(EntityTypeBuilder<IdentityUserLogin<string>> builder)
{
builder.Property(p => p.LoginProvider).HasMaxLength(255);
builder.Property(p => p.ProviderKey).HasMaxLength(255);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations
{
public class ArmoryUserTokenConfiguration : IEntityTypeConfiguration<IdentityUserToken<string>>
{
public void Configure(EntityTypeBuilder<IdentityUserToken<string>> builder)
{
builder.Property(p => p.LoginProvider).HasMaxLength(255);
builder.Property(p => p.Name).HasMaxLength(255);
}
}
}

0 comments on commit 8bd200d

Please sign in to comment.