diff --git a/DrinkRateAPI/Contexts/ApplicationDbContext.cs b/DrinkRateAPI/Contexts/ApplicationDbContext.cs index 604ff93..f59b044 100644 --- a/DrinkRateAPI/Contexts/ApplicationDbContext.cs +++ b/DrinkRateAPI/Contexts/ApplicationDbContext.cs @@ -1,10 +1,11 @@ using DrinkRateAPI.DbEntities; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace DrinkRateAPI.Contexts; -public class ApplicationDbContext : IdentityDbContext +public class ApplicationDbContext : IdentityDbContext, Guid> { public DbSet Companies { get; set; } public DbSet CompanyRatings { get; set; } @@ -180,11 +181,11 @@ public class ApplicationDbContext : IdentityDbContext entity.HasMany(up => up.UserProfileCompanyTableStats) .WithOne(upcts => upcts.UserProfile) - .HasForeignKey(upcts => upcts.UserId); + .HasForeignKey(upcts => upcts.UserProfileId); entity.HasMany(up => up.UserProfileProductTableStats) .WithOne(uppts => uppts.UserProfile) - .HasForeignKey(uppts => uppts.UserId); + .HasForeignKey(uppts => uppts.UserProfileId); entity.HasIndex(up => up.UserName) .IsUnique(); @@ -197,7 +198,7 @@ public class ApplicationDbContext : IdentityDbContext // User Company Table Stat modelBuilder.Entity(entity => { - entity.HasKey(upcts => new { upcts.UserId, upcts.CompanyTableId }); + entity.HasKey(upcts => new { UserId = upcts.UserProfileId, upcts.CompanyTableId }); entity.HasOne(upcts => upcts.UserProfile) .WithMany(up => up.UserProfileCompanyTableStats); @@ -209,7 +210,7 @@ public class ApplicationDbContext : IdentityDbContext // User Product Table Stat modelBuilder.Entity(entity => { - entity.HasKey(uppts => new { uppts.UserId, uppts.ProductTableId }); + entity.HasKey(uppts => new { UserId = uppts.UserProfileId, uppts.ProductTableId }); entity.HasOne(uppts => uppts.UserProfile) .WithMany(up => up.UserProfileProductTableStats); diff --git a/DrinkRateAPI/DbEntities/DbApplicationUser.cs b/DrinkRateAPI/DbEntities/DbApplicationUser.cs index eef7d73..77f1b46 100644 --- a/DrinkRateAPI/DbEntities/DbApplicationUser.cs +++ b/DrinkRateAPI/DbEntities/DbApplicationUser.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Identity; namespace DrinkRateAPI.DbEntities; -public class DbApplicationUser : IdentityUser +public class DbApplicationUser : IdentityUser { public virtual DbUserProfile UserProfile { get; set; } } \ No newline at end of file diff --git a/DrinkRateAPI/DbEntities/DbUserProfile.cs b/DrinkRateAPI/DbEntities/DbUserProfile.cs index 94fd746..d53d20c 100644 --- a/DrinkRateAPI/DbEntities/DbUserProfile.cs +++ b/DrinkRateAPI/DbEntities/DbUserProfile.cs @@ -21,7 +21,7 @@ public class DbUserProfile public bool IsDeleted { get; set; } - public string ApplicationUserId { get; set; } + public Guid ApplicationUserId { get; set; } public virtual DbApplicationUser ApplicationUser { get; set; } } \ No newline at end of file diff --git a/DrinkRateAPI/DbEntities/DbUserProfileCompanyTableStat.cs b/DrinkRateAPI/DbEntities/DbUserProfileCompanyTableStat.cs index 4466d92..a87e1cd 100644 --- a/DrinkRateAPI/DbEntities/DbUserProfileCompanyTableStat.cs +++ b/DrinkRateAPI/DbEntities/DbUserProfileCompanyTableStat.cs @@ -2,7 +2,7 @@ namespace DrinkRateAPI.DbEntities; public class DbUserProfileCompanyTableStat { - public Guid UserId { get; set; } + public Guid UserProfileId { get; set; } public DbUserProfile UserProfile { get; set; } public Guid CompanyTableId { get; set; } diff --git a/DrinkRateAPI/DbEntities/DbUserProfileProductTableStat.cs b/DrinkRateAPI/DbEntities/DbUserProfileProductTableStat.cs index d222070..6331ccb 100644 --- a/DrinkRateAPI/DbEntities/DbUserProfileProductTableStat.cs +++ b/DrinkRateAPI/DbEntities/DbUserProfileProductTableStat.cs @@ -2,7 +2,7 @@ namespace DrinkRateAPI.DbEntities; public class DbUserProfileProductTableStat { - public Guid UserId { get; set; } + public Guid UserProfileId { get; set; } public DbUserProfile UserProfile { get; set; } public Guid ProductTableId { get; set; } diff --git a/DrinkRateAPI/Migrations/20250809145003_init.Designer.cs b/DrinkRateAPI/Migrations/20250809154816_ChangeApplicationUserIdType.Designer.cs similarity index 94% rename from DrinkRateAPI/Migrations/20250809145003_init.Designer.cs rename to DrinkRateAPI/Migrations/20250809154816_ChangeApplicationUserIdType.Designer.cs index a4e6100..4c567e6 100644 --- a/DrinkRateAPI/Migrations/20250809145003_init.Designer.cs +++ b/DrinkRateAPI/Migrations/20250809154816_ChangeApplicationUserIdType.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace DrinkRateAPI.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20250809145003_init")] - partial class init + [Migration("20250809154816_ChangeApplicationUserIdType")] + partial class ChangeApplicationUserIdType { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -87,8 +87,9 @@ namespace DrinkRateAPI.Migrations modelBuilder.Entity("DrinkRateAPI.DbEntities.DbApplicationUser", b => { - b.Property("Id") - .HasColumnType("text"); + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); b.Property("AccessFailedCount") .HasColumnType("integer"); @@ -320,9 +321,8 @@ namespace DrinkRateAPI.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("ApplicationUserId") - .IsRequired() - .HasColumnType("text"); + b.Property("ApplicationUserId") + .HasColumnType("uuid"); b.Property("IsAdmin") .HasColumnType("boolean"); @@ -393,10 +393,11 @@ namespace DrinkRateAPI.Migrations b.ToTable("UserProfileProductTableStats"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { - b.Property("Id") - .HasColumnType("text"); + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() @@ -419,7 +420,7 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetRoles", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -433,9 +434,8 @@ namespace DrinkRateAPI.Migrations b.Property("ClaimValue") .HasColumnType("text"); - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); + b.Property("RoleId") + .HasColumnType("uuid"); b.HasKey("Id"); @@ -444,7 +444,7 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetRoleClaims", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -458,9 +458,8 @@ namespace DrinkRateAPI.Migrations b.Property("ClaimValue") .HasColumnType("text"); - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); b.HasKey("Id"); @@ -469,7 +468,7 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetUserClaims", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasColumnType("text"); @@ -480,9 +479,8 @@ namespace DrinkRateAPI.Migrations b.Property("ProviderDisplayName") .HasColumnType("text"); - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); b.HasKey("LoginProvider", "ProviderKey"); @@ -491,13 +489,13 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetUserLogins", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { - b.Property("UserId") - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); - b.Property("RoleId") - .HasColumnType("text"); + b.Property("RoleId") + .HasColumnType("uuid"); b.HasKey("UserId", "RoleId"); @@ -506,10 +504,10 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetUserRoles", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { - b.Property("UserId") - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); b.Property("LoginProvider") .HasColumnType("text"); @@ -702,16 +700,16 @@ namespace DrinkRateAPI.Migrations b.Navigation("UserProfile"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.HasOne("DrinkRateAPI.DbEntities.DbApplicationUser", null) .WithMany() @@ -720,7 +718,7 @@ namespace DrinkRateAPI.Migrations .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.HasOne("DrinkRateAPI.DbEntities.DbApplicationUser", null) .WithMany() @@ -729,9 +727,9 @@ namespace DrinkRateAPI.Migrations .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) @@ -744,7 +742,7 @@ namespace DrinkRateAPI.Migrations .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.HasOne("DrinkRateAPI.DbEntities.DbApplicationUser", null) .WithMany() diff --git a/DrinkRateAPI/Migrations/20250809145003_init.cs b/DrinkRateAPI/Migrations/20250809154816_ChangeApplicationUserIdType.cs similarity index 97% rename from DrinkRateAPI/Migrations/20250809145003_init.cs rename to DrinkRateAPI/Migrations/20250809154816_ChangeApplicationUserIdType.cs index 406f9c4..348973d 100644 --- a/DrinkRateAPI/Migrations/20250809145003_init.cs +++ b/DrinkRateAPI/Migrations/20250809154816_ChangeApplicationUserIdType.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace DrinkRateAPI.Migrations { /// - public partial class init : Migration + public partial class ChangeApplicationUserIdType : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -16,7 +16,7 @@ namespace DrinkRateAPI.Migrations name: "AspNetRoles", columns: table => new { - Id = table.Column(type: "text", nullable: false), + Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), ConcurrencyStamp = table.Column(type: "text", nullable: true) @@ -30,7 +30,7 @@ namespace DrinkRateAPI.Migrations name: "AspNetUsers", columns: table => new { - Id = table.Column(type: "text", nullable: false), + Id = table.Column(type: "uuid", nullable: false), UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), @@ -103,7 +103,7 @@ namespace DrinkRateAPI.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "text", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, @@ -124,7 +124,7 @@ namespace DrinkRateAPI.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "text", nullable: false), + UserId = table.Column(type: "uuid", nullable: false), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, @@ -146,7 +146,7 @@ namespace DrinkRateAPI.Migrations LoginProvider = table.Column(type: "text", nullable: false), ProviderKey = table.Column(type: "text", nullable: false), ProviderDisplayName = table.Column(type: "text", nullable: true), - UserId = table.Column(type: "text", nullable: false) + UserId = table.Column(type: "uuid", nullable: false) }, constraints: table => { @@ -163,8 +163,8 @@ namespace DrinkRateAPI.Migrations name: "AspNetUserRoles", columns: table => new { - UserId = table.Column(type: "text", nullable: false), - RoleId = table.Column(type: "text", nullable: false) + UserId = table.Column(type: "uuid", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false) }, constraints: table => { @@ -187,7 +187,7 @@ namespace DrinkRateAPI.Migrations name: "AspNetUserTokens", columns: table => new { - UserId = table.Column(type: "text", nullable: false), + UserId = table.Column(type: "uuid", nullable: false), LoginProvider = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false), Value = table.Column(type: "text", nullable: true) @@ -211,7 +211,7 @@ namespace DrinkRateAPI.Migrations UserName = table.Column(type: "text", nullable: false), IsAdmin = table.Column(type: "boolean", nullable: false), IsDeleted = table.Column(type: "boolean", nullable: false), - ApplicationUserId = table.Column(type: "text", nullable: false) + ApplicationUserId = table.Column(type: "uuid", nullable: false) }, constraints: table => { diff --git a/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs b/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs index 7a193e4..fabb4ed 100644 --- a/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs @@ -84,8 +84,9 @@ namespace DrinkRateAPI.Migrations modelBuilder.Entity("DrinkRateAPI.DbEntities.DbApplicationUser", b => { - b.Property("Id") - .HasColumnType("text"); + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); b.Property("AccessFailedCount") .HasColumnType("integer"); @@ -317,9 +318,8 @@ namespace DrinkRateAPI.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("ApplicationUserId") - .IsRequired() - .HasColumnType("text"); + b.Property("ApplicationUserId") + .HasColumnType("uuid"); b.Property("IsAdmin") .HasColumnType("boolean"); @@ -390,10 +390,11 @@ namespace DrinkRateAPI.Migrations b.ToTable("UserProfileProductTableStats"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { - b.Property("Id") - .HasColumnType("text"); + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() @@ -416,7 +417,7 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetRoles", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -430,9 +431,8 @@ namespace DrinkRateAPI.Migrations b.Property("ClaimValue") .HasColumnType("text"); - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); + b.Property("RoleId") + .HasColumnType("uuid"); b.HasKey("Id"); @@ -441,7 +441,7 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetRoleClaims", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -455,9 +455,8 @@ namespace DrinkRateAPI.Migrations b.Property("ClaimValue") .HasColumnType("text"); - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); b.HasKey("Id"); @@ -466,7 +465,7 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetUserClaims", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasColumnType("text"); @@ -477,9 +476,8 @@ namespace DrinkRateAPI.Migrations b.Property("ProviderDisplayName") .HasColumnType("text"); - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); b.HasKey("LoginProvider", "ProviderKey"); @@ -488,13 +486,13 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetUserLogins", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { - b.Property("UserId") - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); - b.Property("RoleId") - .HasColumnType("text"); + b.Property("RoleId") + .HasColumnType("uuid"); b.HasKey("UserId", "RoleId"); @@ -503,10 +501,10 @@ namespace DrinkRateAPI.Migrations b.ToTable("AspNetUserRoles", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { - b.Property("UserId") - .HasColumnType("text"); + b.Property("UserId") + .HasColumnType("uuid"); b.Property("LoginProvider") .HasColumnType("text"); @@ -699,16 +697,16 @@ namespace DrinkRateAPI.Migrations b.Navigation("UserProfile"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.HasOne("DrinkRateAPI.DbEntities.DbApplicationUser", null) .WithMany() @@ -717,7 +715,7 @@ namespace DrinkRateAPI.Migrations .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.HasOne("DrinkRateAPI.DbEntities.DbApplicationUser", null) .WithMany() @@ -726,9 +724,9 @@ namespace DrinkRateAPI.Migrations .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) @@ -741,7 +739,7 @@ namespace DrinkRateAPI.Migrations .IsRequired(); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.HasOne("DrinkRateAPI.DbEntities.DbApplicationUser", null) .WithMany() diff --git a/DrinkRateAPI/Program.cs b/DrinkRateAPI/Program.cs index 6078b3c..7d4ddbc 100644 --- a/DrinkRateAPI/Program.cs +++ b/DrinkRateAPI/Program.cs @@ -1,7 +1,5 @@ using DrinkRateAPI.Contexts; using DrinkRateAPI.DbEntities; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args);