Commit 645aa86d authored by Eric Dieckman's avatar Eric Dieckman
Browse files

Alter AppUser to be property bag

parent a5b10c7d
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
using Cals.Visor.Models;
using Cals.Visor.Models.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata;
@@ -21,7 +20,6 @@ public class ApplicationDbContext : DbContext
    }

    public DbSet<AppUser> Users => Set<AppUser>();
    
    public DbSet<Area> Areas => Set<Area>();
    public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
    public DbSet<InfobloxDomain> InfobloxDomains => Set<InfobloxDomain>();
@@ -41,7 +39,6 @@ public class ApplicationDbContext : DbContext
    public DbSet<WiscNicGroup> WiscNicGroups => Set<WiscNicGroup>();
    public DbSet<WiscNicGroupMembershipType> WiscNicGroupMembershipTypes => Set<WiscNicGroupMembershipType>();


    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ namespace Cals.Visor.Infrastructure.Database;
internal sealed class TableNames
{
#pragma warning disable IDE1006 // Naming Styles - no "_" in internal const
    internal const string Users = "appuser";
    internal const string Users = "app_users";
    internal const string OutboxMessages = "outbox";
    internal const string InternalCommands = "internal_command";
    internal const string Areas = "areas";
+0 −35
Original line number Diff line number Diff line
using Cals.Visor.Application.Identity;
using Cals.Visor.Models.Identity;
using Cals.Visor.Infrastructure.Contexts;
using Microsoft.EntityFrameworkCore;

namespace Cals.KeyTrack.Infrastructure.Identity;

public class UserRepository : IUserRepository
{
    private ApplicationDbContext _dbContext;

    public UserRepository(ApplicationDbContext dbContext)
    {
        _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
    }

    public async Task AddAsync(AppUser user, CancellationToken cancellationToken = default)
    {
        await _dbContext.Users.AddAsync(user, cancellationToken);
    }

    public async Task<AppUser?> GetByUniqueIdAsync(string uniqueId, CancellationToken cancellationToken = default)
    {
        return await _dbContext.Users
            .SingleOrDefaultAsync(e => e.UniqueID == uniqueId, cancellationToken)
            .ConfigureAwait(false);
    }

    public async Task<AppUser?> GetByUsernameAsync(string username, CancellationToken cancellationToken = default)
    {
        return await _dbContext.Users
            .SingleOrDefaultAsync(e => e.Username == username, cancellationToken)
            .ConfigureAwait(false);
    }
}
+13 −20
Original line number Diff line number Diff line
using Cals.Visor.Infrastructure.Database;
using Cals.Visor.Models.Identity;
using Cals.Visor.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Cals.Visor.Infrastructure.Domain.Identity;
namespace Cals.Visor.Infrastructure.Models;

public class AppUserEntityTypeConfiguration : IEntityTypeConfiguration<AppUser>
{
@@ -11,31 +11,24 @@ public class AppUserEntityTypeConfiguration : IEntityTypeConfiguration<AppUser>
    {
        builder.ToTable(TableNames.Users);

        builder.Property<int>("id")
            .HasColumnName("id")
            .ValueGeneratedOnAdd();

        builder.HasKey("id");
        builder.HasKey(e => e.AppUserId);

        builder.Property(e => e.UniqueID)
            .HasColumnName("unique_id")
            .IsUnicode(false)
            .HasMaxLength(20);
            .HasMaxLength(255);

        builder.Property(e => e.Username)
            .IsUnicode(false)
            .HasMaxLength(50);

        builder.Property(e => e.Email)
            .IsUnicode(false)
            .HasMaxLength(100);
            .HasMaxLength(255);

        builder.Property(e => e.FirstName)
            .HasMaxLength(50)
            .HasColumnName("first_name");
            .HasMaxLength(255);

        builder.Property(e => e.LastName)
            .HasMaxLength(50)
            .HasColumnName("last_name");
            .HasMaxLength(255);

        builder.Property(e => e.Email)
            .HasMaxLength(255);

        builder.Property(e => e.DisplayName)
            .HasMaxLength(512);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ CREATE TABLE `app_users` (
  `username` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Represents NetID',
  `first_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `last_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `display_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
Loading