From 87c4f27de5ce92ea83f402c481a8fdccaaa20b4d Mon Sep 17 00:00:00 2001 From: lumijiez <59575049+lumijiez@users.noreply.github.com> Date: Fri, 6 Jun 2025 22:27:55 +0300 Subject: [PATCH] Absolute garbage, trying to forward JWT, bad idea --- .../Imprink.Application.csproj | 1 - .../Users/Roles/AddUserToRoleHandler.cs | 39 + .../Users/Roles/RemoveUserFromRoleHandler.cs | 32 + src/Imprink.Domain/Common/Models/Auth0User.cs | 12 + src/Imprink.Domain/Entities/Users/User.cs | 4 +- src/Imprink.Domain/Entities/Users/UserRole.cs | 1 + .../Configuration/Users/UserConfiguration.cs | 12 +- .../Users/UserRoleConfiguration.cs | 5 + .../Database/ApplicationDbContext.cs | 3 + .../20250603173128_InitialSetup.Designer.cs | 853 -------------- .../Migrations/20250606161235_AddUserRoles.cs | 152 --- ...606162608_RelateUsersAndOrders.Designer.cs | 1033 ----------------- .../20250606162608_RelateUsersAndOrders.cs | 30 - ...> 20250606173957_InitialSetup.Designer.cs} | 52 +- ...etup.cs => 20250606173957_InitialSetup.cs} | 160 ++- .../ApplicationDbContextModelSnapshot.cs | 38 +- .../Repositories/RoleRepository.cs | 36 + .../Repositories/UserRepository.cs | 181 +++ .../Repositories/UserRoleRepository.cs | 60 + .../Controllers/Users/UserController.cs | 30 + src/Imprink.WebApi/Imprink.WebApi.csproj | 1 - src/Imprink.WebApi/Startup.cs | 3 + webui/src/app/page.js | 45 +- 23 files changed, 581 insertions(+), 2202 deletions(-) create mode 100644 src/Imprink.Application/Users/Roles/AddUserToRoleHandler.cs create mode 100644 src/Imprink.Application/Users/Roles/RemoveUserFromRoleHandler.cs create mode 100644 src/Imprink.Domain/Common/Models/Auth0User.cs delete mode 100644 src/Imprink.Infrastructure/Migrations/20250603173128_InitialSetup.Designer.cs delete mode 100644 src/Imprink.Infrastructure/Migrations/20250606161235_AddUserRoles.cs delete mode 100644 src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.Designer.cs delete mode 100644 src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.cs rename src/Imprink.Infrastructure/Migrations/{20250606161235_AddUserRoles.Designer.cs => 20250606173957_InitialSetup.Designer.cs} (96%) rename src/Imprink.Infrastructure/Migrations/{20250603173128_InitialSetup.cs => 20250606173957_InitialSetup.cs} (85%) create mode 100644 src/Imprink.Infrastructure/Repositories/RoleRepository.cs create mode 100644 src/Imprink.Infrastructure/Repositories/UserRepository.cs create mode 100644 src/Imprink.Infrastructure/Repositories/UserRoleRepository.cs create mode 100644 src/Imprink.WebApi/Controllers/Users/UserController.cs diff --git a/src/Imprink.Application/Imprink.Application.csproj b/src/Imprink.Application/Imprink.Application.csproj index d0d26c3..892e1ef 100644 --- a/src/Imprink.Application/Imprink.Application.csproj +++ b/src/Imprink.Application/Imprink.Application.csproj @@ -21,7 +21,6 @@ - diff --git a/src/Imprink.Application/Users/Roles/AddUserToRoleHandler.cs b/src/Imprink.Application/Users/Roles/AddUserToRoleHandler.cs new file mode 100644 index 0000000..9beb472 --- /dev/null +++ b/src/Imprink.Application/Users/Roles/AddUserToRoleHandler.cs @@ -0,0 +1,39 @@ +using Imprink.Domain.Entities.Users; +using Imprink.Domain.Repositories; +using MediatR; + +namespace Imprink.Application.Users.Roles; + +public record AddUserToRoleCommand(string UserId, Guid RoleId) : IRequest; + +public class AddUserToRoleCommandHandler( + IUserRoleRepository userRoleRepository, + IRoleRepository roleRepository, + IUserRepository userRepository) + : IRequestHandler +{ + public async Task Handle(AddUserToRoleCommand request, CancellationToken cancellationToken) + { + var userExists = await userRepository.UserExistsAsync(request.UserId, cancellationToken); + if (!userExists) + return false; + + var roleExists = await roleRepository.RoleExistsAsync(request.RoleId, cancellationToken); + if (!roleExists) + return false; + + var isAlreadyInRole = await userRoleRepository.IsUserInRoleAsync(request.UserId, request.RoleId, cancellationToken); + if (isAlreadyInRole) + return true; + + var userRole = new UserRole + { + UserId = request.UserId, + RoleId = request.RoleId + }; + + await userRoleRepository.AddUserRoleAsync(userRole, cancellationToken); + + return true; + } +} \ No newline at end of file diff --git a/src/Imprink.Application/Users/Roles/RemoveUserFromRoleHandler.cs b/src/Imprink.Application/Users/Roles/RemoveUserFromRoleHandler.cs new file mode 100644 index 0000000..2cf237b --- /dev/null +++ b/src/Imprink.Application/Users/Roles/RemoveUserFromRoleHandler.cs @@ -0,0 +1,32 @@ +using Imprink.Domain.Repositories; +using MediatR; + +namespace Imprink.Application.Users.Roles; + +public record RemoveUserFromRoleCommand(string UserId, Guid RoleId) : IRequest; + +public class RemoveUserFromRoleCommandHandler( + IUserRoleRepository userRoleRepository, + IRoleRepository roleRepository, + IUserRepository userRepository) + : IRequestHandler +{ + public async Task Handle(RemoveUserFromRoleCommand request, CancellationToken cancellationToken) + { + var userExists = await userRepository.UserExistsAsync(request.UserId, cancellationToken); + if (!userExists) + return false; + + var roleExists = await roleRepository.RoleExistsAsync(request.RoleId, cancellationToken); + if (!roleExists) + return false; + + var userRole = await userRoleRepository.GetUserRoleAsync(request.UserId, request.RoleId, cancellationToken); + if (userRole == null) + return true; + + await userRoleRepository.RemoveUserRoleAsync(userRole, cancellationToken); + + return true; + } +} \ No newline at end of file diff --git a/src/Imprink.Domain/Common/Models/Auth0User.cs b/src/Imprink.Domain/Common/Models/Auth0User.cs new file mode 100644 index 0000000..5c8b7a1 --- /dev/null +++ b/src/Imprink.Domain/Common/Models/Auth0User.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; + +namespace Imprink.Domain.Common.Models; + +public class Auth0User +{ + public string Sub { get; set; } = null!; + public string Name { get; set; } = null!; + public string Nickname { get; set; } = null!; + public string Email { get; set; } = null!; + public bool EmailVerified { get; set; } +} \ No newline at end of file diff --git a/src/Imprink.Domain/Entities/Users/User.cs b/src/Imprink.Domain/Entities/Users/User.cs index 3e5eb31..8f81a99 100644 --- a/src/Imprink.Domain/Entities/Users/User.cs +++ b/src/Imprink.Domain/Entities/Users/User.cs @@ -2,9 +2,9 @@ using Imprink.Domain.Entities.Orders; namespace Imprink.Domain.Entities.Users; -public class User : EntityBase +public class User { - public new string Id { get; set; } = null!; + public string Id { get; set; } = null!; public required string Email { get; set; } public required string FirstName { get; set; } public required string LastName { get; set; } diff --git a/src/Imprink.Domain/Entities/Users/UserRole.cs b/src/Imprink.Domain/Entities/Users/UserRole.cs index b6de7cc..de4c4b1 100644 --- a/src/Imprink.Domain/Entities/Users/UserRole.cs +++ b/src/Imprink.Domain/Entities/Users/UserRole.cs @@ -6,4 +6,5 @@ public class UserRole public Guid RoleId { get; set; } public virtual Role Role { get; set; } = null!; + public virtual User User { get; set; } = null!; } \ No newline at end of file diff --git a/src/Imprink.Infrastructure/Configuration/Users/UserConfiguration.cs b/src/Imprink.Infrastructure/Configuration/Users/UserConfiguration.cs index 404f00d..31c74a7 100644 --- a/src/Imprink.Infrastructure/Configuration/Users/UserConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/Users/UserConfiguration.cs @@ -4,12 +4,10 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Imprink.Infrastructure.Configuration.Users; -public class UserConfiguration : EntityBaseConfiguration +public class UserConfiguration : IEntityTypeConfiguration { - public override void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { - base.Configure(builder); - builder.Property(u => u.Id) .HasMaxLength(450) .ValueGeneratedNever(); @@ -51,12 +49,6 @@ public class UserConfiguration : EntityBaseConfiguration .HasForeignKey(a => a.UserId) .HasPrincipalKey(u => u.Id) .OnDelete(DeleteBehavior.Cascade); - - builder.HasMany(u => u.UserRoles) - .WithOne() - .HasForeignKey(ur => ur.UserId) - .HasPrincipalKey(u => u.Id) - .OnDelete(DeleteBehavior.Cascade); builder.Ignore(u => u.FullName); builder.Ignore(u => u.DefaultAddress); diff --git a/src/Imprink.Infrastructure/Configuration/Users/UserRoleConfiguration.cs b/src/Imprink.Infrastructure/Configuration/Users/UserRoleConfiguration.cs index d68a698..3dbd9f6 100644 --- a/src/Imprink.Infrastructure/Configuration/Users/UserRoleConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/Users/UserRoleConfiguration.cs @@ -27,5 +27,10 @@ public class UserRoleConfiguration : IEntityTypeConfiguration .WithMany(r => r.UserRoles) .HasForeignKey(ur => ur.RoleId) .OnDelete(DeleteBehavior.Restrict); + + builder.HasOne(ur => ur.User) + .WithMany(u => u.UserRoles) + .HasForeignKey(ur => ur.UserId) + .OnDelete(DeleteBehavior.Cascade); } } \ No newline at end of file diff --git a/src/Imprink.Infrastructure/Database/ApplicationDbContext.cs b/src/Imprink.Infrastructure/Database/ApplicationDbContext.cs index e4e072e..0896482 100644 --- a/src/Imprink.Infrastructure/Database/ApplicationDbContext.cs +++ b/src/Imprink.Infrastructure/Database/ApplicationDbContext.cs @@ -20,6 +20,9 @@ public class ApplicationDbContext(DbContextOptions options public DbSet
Addresses { get; set; } public DbSet OrderStatuses { get; set; } public DbSet ShippingStatuses { get; set; } + public DbSet Users { get; set; } + public DbSet UserRoles { get; set; } + public DbSet Roles { get; set; } public DbSet Categories { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/src/Imprink.Infrastructure/Migrations/20250603173128_InitialSetup.Designer.cs b/src/Imprink.Infrastructure/Migrations/20250603173128_InitialSetup.Designer.cs deleted file mode 100644 index 30ee08f..0000000 --- a/src/Imprink.Infrastructure/Migrations/20250603173128_InitialSetup.Designer.cs +++ /dev/null @@ -1,853 +0,0 @@ -// -using System; -using Imprink.Infrastructure.Database; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Imprink.Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20250603173128_InitialSetup")] - partial class InitialSetup - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Notes") - .IsRequired() - .HasMaxLength(1000) - .HasColumnType("nvarchar(1000)"); - - b.Property("OrderDate") - .HasColumnType("datetime2"); - - b.Property("OrderNumber") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("OrderStatusId") - .HasColumnType("int"); - - b.Property("ShippingStatusId") - .HasColumnType("int"); - - b.Property("TotalPrice") - .HasColumnType("decimal(18,2)"); - - b.Property("UserId") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Order_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Order_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Order_ModifiedAt"); - - b.HasIndex("OrderDate") - .HasDatabaseName("IX_Order_OrderDate"); - - b.HasIndex("OrderNumber") - .IsUnique() - .HasDatabaseName("IX_Order_OrderNumber"); - - b.HasIndex("OrderStatusId") - .HasDatabaseName("IX_Order_OrderStatusId"); - - b.HasIndex("ShippingStatusId") - .HasDatabaseName("IX_Order_ShippingStatusId"); - - b.HasIndex("UserId") - .HasDatabaseName("IX_Order_UserId"); - - b.HasIndex("UserId", "OrderDate") - .HasDatabaseName("IX_Order_User_Date"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderAddress", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("City") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.Property("PostalCode") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); - - b.Property("State") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Street") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_OrderAddress_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_OrderAddress_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_OrderAddress_ModifiedAt"); - - b.HasIndex("OrderId") - .IsUnique() - .HasDatabaseName("IX_OrderAddress_OrderId"); - - b.ToTable("OrderAddresses"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("CustomizationDescription") - .IsRequired() - .HasMaxLength(2000) - .HasColumnType("nvarchar(2000)"); - - b.Property("CustomizationImageUrl") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.Property("ProductId") - .HasColumnType("uniqueidentifier"); - - b.Property("ProductVariantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Quantity") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasDefaultValue(1); - - b.Property("TotalPrice") - .HasColumnType("decimal(18,2)"); - - b.Property("UnitPrice") - .HasColumnType("decimal(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_OrderItem_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_OrderItem_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_OrderItem_ModifiedAt"); - - b.HasIndex("OrderId") - .HasDatabaseName("IX_OrderItem_OrderId"); - - b.HasIndex("ProductId") - .HasDatabaseName("IX_OrderItem_ProductId"); - - b.HasIndex("ProductVariantId") - .HasDatabaseName("IX_OrderItem_ProductVariantId"); - - b.HasIndex("OrderId", "ProductId") - .HasDatabaseName("IX_OrderItem_Order_Product"); - - b.ToTable("OrderItems"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderStatus", b => - { - b.Property("Id") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique() - .HasDatabaseName("IX_OrderStatus_Name"); - - b.ToTable("OrderStatuses"); - - b.HasData( - new - { - Id = 0, - Name = "Pending" - }, - new - { - Id = 1, - Name = "Processing" - }, - new - { - Id = 2, - Name = "Completed" - }, - new - { - Id = 3, - Name = "Cancelled" - }); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.ShippingStatus", b => - { - b.Property("Id") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique() - .HasDatabaseName("IX_ShippingStatus_Name"); - - b.ToTable("ShippingStatuses"); - - b.HasData( - new - { - Id = 0, - Name = "Prepping" - }, - new - { - Id = 1, - Name = "Packaging" - }, - new - { - Id = 2, - Name = "Shipped" - }, - new - { - Id = 3, - Name = "Delivered" - }); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Description") - .IsRequired() - .HasMaxLength(2000) - .HasColumnType("nvarchar(2000)"); - - b.Property("ImageUrl") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("ParentCategoryId") - .HasColumnType("uniqueidentifier"); - - b.Property("SortOrder") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasDefaultValue(0); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Category_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Category_CreatedBy"); - - b.HasIndex("IsActive") - .HasDatabaseName("IX_Category_IsActive"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Category_ModifiedAt"); - - b.HasIndex("Name") - .HasDatabaseName("IX_Category_Name"); - - b.HasIndex("ParentCategoryId") - .HasDatabaseName("IX_Category_ParentCategoryId"); - - b.HasIndex("IsActive", "SortOrder") - .HasDatabaseName("IX_Category_Active_SortOrder"); - - b.HasIndex("ParentCategoryId", "SortOrder") - .HasDatabaseName("IX_Category_Parent_SortOrder"); - - b.ToTable("Categories"); - - b.HasData( - new - { - Id = new Guid("11111111-1111-1111-1111-111111111111"), - CreatedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - CreatedBy = "system@printbase.com", - Description = "Textile and fabric-based products", - IsActive = true, - ModifiedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - ModifiedBy = "system@printbase.com", - Name = "Textile", - SortOrder = 1 - }, - new - { - Id = new Guid("22222222-2222-2222-2222-222222222222"), - CreatedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - CreatedBy = "system@printbase.com", - Description = "Products for hard surface printing", - IsActive = true, - ModifiedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - ModifiedBy = "system@printbase.com", - Name = "Hard Surfaces", - SortOrder = 2 - }, - new - { - Id = new Guid("33333333-3333-3333-3333-333333333333"), - CreatedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - CreatedBy = "system@printbase.com", - Description = "Paper-based printing products", - IsActive = true, - ModifiedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - ModifiedBy = "system@printbase.com", - Name = "Paper", - SortOrder = 3 - }); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("BasePrice") - .HasColumnType("decimal(18,2)"); - - b.Property("CategoryId") - .HasColumnType("uniqueidentifier"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Description") - .HasMaxLength(2000) - .HasColumnType("nvarchar(2000)"); - - b.Property("ImageUrl") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("IsCustomizable") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(false); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId") - .HasDatabaseName("IX_Product_CategoryId"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Product_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Product_CreatedBy"); - - b.HasIndex("IsActive") - .HasDatabaseName("IX_Product_IsActive"); - - b.HasIndex("IsCustomizable") - .HasDatabaseName("IX_Product_IsCustomizable"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Product_ModifiedAt"); - - b.HasIndex("Name") - .HasDatabaseName("IX_Product_Name"); - - b.HasIndex("CategoryId", "IsActive") - .HasDatabaseName("IX_Product_Category_Active"); - - b.HasIndex("IsActive", "IsCustomizable") - .HasDatabaseName("IX_Product_Active_Customizable"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("Color") - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("ImageUrl") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.Property("ProductId") - .HasColumnType("uniqueidentifier"); - - b.Property("Size") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("Sku") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("StockQuantity") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasDefaultValue(0); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_ProductVariant_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_ProductVariant_CreatedBy"); - - b.HasIndex("IsActive") - .HasDatabaseName("IX_ProductVariant_IsActive"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_ProductVariant_ModifiedAt"); - - b.HasIndex("ProductId") - .HasDatabaseName("IX_ProductVariant_ProductId"); - - b.HasIndex("Sku") - .IsUnique() - .HasDatabaseName("IX_ProductVariant_SKU"); - - b.HasIndex("ProductId", "Size", "Color") - .IsUnique() - .HasDatabaseName("IX_ProductVariant_Product_Size_Color") - .HasFilter("[Color] IS NOT NULL"); - - b.ToTable("ProductVariants"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("AddressType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("City") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("IsDefault") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(false); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("PostalCode") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); - - b.Property("State") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Street") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("UserId") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Address_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Address_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Address_ModifiedAt"); - - b.HasIndex("UserId") - .HasDatabaseName("IX_Address_UserId"); - - b.HasIndex("UserId", "AddressType") - .HasDatabaseName("IX_Address_User_Type"); - - b.HasIndex("UserId", "IsDefault") - .HasDatabaseName("IX_Address_User_Default"); - - b.ToTable("Addresses"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => - { - b.HasOne("Imprink.Domain.Entities.Orders.OrderStatus", "OrderStatus") - .WithMany("Orders") - .HasForeignKey("OrderStatusId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Orders.ShippingStatus", "ShippingStatus") - .WithMany("Orders") - .HasForeignKey("ShippingStatusId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("OrderStatus"); - - b.Navigation("ShippingStatus"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderAddress", b => - { - b.HasOne("Imprink.Domain.Entities.Orders.Order", "Order") - .WithOne("OrderAddress") - .HasForeignKey("Imprink.Domain.Entities.Orders.OrderAddress", "OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Order"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderItem", b => - { - b.HasOne("Imprink.Domain.Entities.Orders.Order", "Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Product.Product", "Product") - .WithMany("OrderItems") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Product.ProductVariant", "ProductVariant") - .WithMany("OrderItems") - .HasForeignKey("ProductVariantId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Order"); - - b.Navigation("Product"); - - b.Navigation("ProductVariant"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Category", b => - { - b.HasOne("Imprink.Domain.Entities.Product.Category", "ParentCategory") - .WithMany("SubCategories") - .HasForeignKey("ParentCategoryId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("ParentCategory"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => - { - b.HasOne("Imprink.Domain.Entities.Product.Category", "Category") - .WithMany("Products") - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("Category"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => - { - b.HasOne("Imprink.Domain.Entities.Product.Product", "Product") - .WithMany("ProductVariants") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => - { - b.Navigation("OrderAddress") - .IsRequired(); - - b.Navigation("OrderItems"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderStatus", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.ShippingStatus", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Category", b => - { - b.Navigation("Products"); - - b.Navigation("SubCategories"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => - { - b.Navigation("OrderItems"); - - b.Navigation("ProductVariants"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => - { - b.Navigation("OrderItems"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Imprink.Infrastructure/Migrations/20250606161235_AddUserRoles.cs b/src/Imprink.Infrastructure/Migrations/20250606161235_AddUserRoles.cs deleted file mode 100644 index 04ab268..0000000 --- a/src/Imprink.Infrastructure/Migrations/20250606161235_AddUserRoles.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace Imprink.Infrastructure.Migrations -{ - /// - public partial class AddUserRoles : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Role", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - RoleName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Role", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "User", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false, defaultValueSql: "NEWID()"), - Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), - FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - PhoneNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), - DateOfBirth = table.Column(type: "date", nullable: true), - IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), - LastLoginAt = table.Column(type: "datetime2", nullable: true), - CreatedAt = table.Column(type: "datetime2", nullable: false), - ModifiedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), - CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), - ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_User", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "UserRole", - columns: table => new - { - UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), - RoleId = table.Column(type: "uniqueidentifier", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserRole", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_UserRole_Role_RoleId", - column: x => x.RoleId, - principalTable: "Role", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_UserRole_User_UserId", - column: x => x.UserId, - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.InsertData( - table: "Role", - columns: new[] { "Id", "RoleName" }, - values: new object[,] - { - { new Guid("11111111-1111-1111-1111-111111111111"), "User" }, - { new Guid("22222222-2222-2222-2222-222222222222"), "Merchant" }, - { new Guid("33333333-3333-3333-3333-333333333333"), "Admin" } - }); - - migrationBuilder.CreateIndex( - name: "IX_Role_RoleName", - table: "Role", - column: "RoleName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_User_CreatedAt", - table: "User", - column: "CreatedAt"); - - migrationBuilder.CreateIndex( - name: "IX_User_CreatedBy", - table: "User", - column: "CreatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_User_Email", - table: "User", - column: "Email", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_User_IsActive", - table: "User", - column: "IsActive"); - - migrationBuilder.CreateIndex( - name: "IX_User_ModifiedAt", - table: "User", - column: "ModifiedAt"); - - migrationBuilder.CreateIndex( - name: "IX_UserRole_RoleId", - table: "UserRole", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "IX_UserRole_UserId", - table: "UserRole", - column: "UserId"); - - migrationBuilder.AddForeignKey( - name: "FK_Addresses_User_UserId", - table: "Addresses", - column: "UserId", - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Addresses_User_UserId", - table: "Addresses"); - - migrationBuilder.DropTable( - name: "UserRole"); - - migrationBuilder.DropTable( - name: "Role"); - - migrationBuilder.DropTable( - name: "User"); - } - } -} diff --git a/src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.Designer.cs b/src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.Designer.cs deleted file mode 100644 index beadbed..0000000 --- a/src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.Designer.cs +++ /dev/null @@ -1,1033 +0,0 @@ -// -using System; -using Imprink.Infrastructure.Database; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Imprink.Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20250606162608_RelateUsersAndOrders")] - partial class RelateUsersAndOrders - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Notes") - .IsRequired() - .HasMaxLength(1000) - .HasColumnType("nvarchar(1000)"); - - b.Property("OrderDate") - .HasColumnType("datetime2"); - - b.Property("OrderNumber") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("OrderStatusId") - .HasColumnType("int"); - - b.Property("ShippingStatusId") - .HasColumnType("int"); - - b.Property("TotalPrice") - .HasColumnType("decimal(18,2)"); - - b.Property("UserId") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Order_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Order_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Order_ModifiedAt"); - - b.HasIndex("OrderDate") - .HasDatabaseName("IX_Order_OrderDate"); - - b.HasIndex("OrderNumber") - .IsUnique() - .HasDatabaseName("IX_Order_OrderNumber"); - - b.HasIndex("OrderStatusId") - .HasDatabaseName("IX_Order_OrderStatusId"); - - b.HasIndex("ShippingStatusId") - .HasDatabaseName("IX_Order_ShippingStatusId"); - - b.HasIndex("UserId") - .HasDatabaseName("IX_Order_UserId"); - - b.HasIndex("UserId", "OrderDate") - .HasDatabaseName("IX_Order_User_Date"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderAddress", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("City") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.Property("PostalCode") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); - - b.Property("State") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Street") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_OrderAddress_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_OrderAddress_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_OrderAddress_ModifiedAt"); - - b.HasIndex("OrderId") - .IsUnique() - .HasDatabaseName("IX_OrderAddress_OrderId"); - - b.ToTable("OrderAddresses"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("CustomizationDescription") - .IsRequired() - .HasMaxLength(2000) - .HasColumnType("nvarchar(2000)"); - - b.Property("CustomizationImageUrl") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.Property("ProductId") - .HasColumnType("uniqueidentifier"); - - b.Property("ProductVariantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Quantity") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasDefaultValue(1); - - b.Property("TotalPrice") - .HasColumnType("decimal(18,2)"); - - b.Property("UnitPrice") - .HasColumnType("decimal(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_OrderItem_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_OrderItem_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_OrderItem_ModifiedAt"); - - b.HasIndex("OrderId") - .HasDatabaseName("IX_OrderItem_OrderId"); - - b.HasIndex("ProductId") - .HasDatabaseName("IX_OrderItem_ProductId"); - - b.HasIndex("ProductVariantId") - .HasDatabaseName("IX_OrderItem_ProductVariantId"); - - b.HasIndex("OrderId", "ProductId") - .HasDatabaseName("IX_OrderItem_Order_Product"); - - b.ToTable("OrderItems"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderStatus", b => - { - b.Property("Id") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique() - .HasDatabaseName("IX_OrderStatus_Name"); - - b.ToTable("OrderStatuses"); - - b.HasData( - new - { - Id = 0, - Name = "Pending" - }, - new - { - Id = 1, - Name = "Processing" - }, - new - { - Id = 2, - Name = "Completed" - }, - new - { - Id = 3, - Name = "Cancelled" - }); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.ShippingStatus", b => - { - b.Property("Id") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique() - .HasDatabaseName("IX_ShippingStatus_Name"); - - b.ToTable("ShippingStatuses"); - - b.HasData( - new - { - Id = 0, - Name = "Prepping" - }, - new - { - Id = 1, - Name = "Packaging" - }, - new - { - Id = 2, - Name = "Shipped" - }, - new - { - Id = 3, - Name = "Delivered" - }); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Description") - .IsRequired() - .HasMaxLength(2000) - .HasColumnType("nvarchar(2000)"); - - b.Property("ImageUrl") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("ParentCategoryId") - .HasColumnType("uniqueidentifier"); - - b.Property("SortOrder") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasDefaultValue(0); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Category_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Category_CreatedBy"); - - b.HasIndex("IsActive") - .HasDatabaseName("IX_Category_IsActive"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Category_ModifiedAt"); - - b.HasIndex("Name") - .HasDatabaseName("IX_Category_Name"); - - b.HasIndex("ParentCategoryId") - .HasDatabaseName("IX_Category_ParentCategoryId"); - - b.HasIndex("IsActive", "SortOrder") - .HasDatabaseName("IX_Category_Active_SortOrder"); - - b.HasIndex("ParentCategoryId", "SortOrder") - .HasDatabaseName("IX_Category_Parent_SortOrder"); - - b.ToTable("Categories"); - - b.HasData( - new - { - Id = new Guid("11111111-1111-1111-1111-111111111111"), - CreatedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - CreatedBy = "system@printbase.com", - Description = "Textile and fabric-based products", - IsActive = true, - ModifiedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - ModifiedBy = "system@printbase.com", - Name = "Textile", - SortOrder = 1 - }, - new - { - Id = new Guid("22222222-2222-2222-2222-222222222222"), - CreatedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - CreatedBy = "system@printbase.com", - Description = "Products for hard surface printing", - IsActive = true, - ModifiedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - ModifiedBy = "system@printbase.com", - Name = "Hard Surfaces", - SortOrder = 2 - }, - new - { - Id = new Guid("33333333-3333-3333-3333-333333333333"), - CreatedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - CreatedBy = "system@printbase.com", - Description = "Paper-based printing products", - IsActive = true, - ModifiedAt = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), - ModifiedBy = "system@printbase.com", - Name = "Paper", - SortOrder = 3 - }); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("BasePrice") - .HasColumnType("decimal(18,2)"); - - b.Property("CategoryId") - .HasColumnType("uniqueidentifier"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Description") - .HasMaxLength(2000) - .HasColumnType("nvarchar(2000)"); - - b.Property("ImageUrl") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("IsCustomizable") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(false); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId") - .HasDatabaseName("IX_Product_CategoryId"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Product_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Product_CreatedBy"); - - b.HasIndex("IsActive") - .HasDatabaseName("IX_Product_IsActive"); - - b.HasIndex("IsCustomizable") - .HasDatabaseName("IX_Product_IsCustomizable"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Product_ModifiedAt"); - - b.HasIndex("Name") - .HasDatabaseName("IX_Product_Name"); - - b.HasIndex("CategoryId", "IsActive") - .HasDatabaseName("IX_Product_Category_Active"); - - b.HasIndex("IsActive", "IsCustomizable") - .HasDatabaseName("IX_Product_Active_Customizable"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("Color") - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("ImageUrl") - .HasMaxLength(500) - .HasColumnType("nvarchar(500)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.Property("ProductId") - .HasColumnType("uniqueidentifier"); - - b.Property("Size") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("Sku") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("StockQuantity") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasDefaultValue(0); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_ProductVariant_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_ProductVariant_CreatedBy"); - - b.HasIndex("IsActive") - .HasDatabaseName("IX_ProductVariant_IsActive"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_ProductVariant_ModifiedAt"); - - b.HasIndex("ProductId") - .HasDatabaseName("IX_ProductVariant_ProductId"); - - b.HasIndex("Sku") - .IsUnique() - .HasDatabaseName("IX_ProductVariant_SKU"); - - b.HasIndex("ProductId", "Size", "Color") - .IsUnique() - .HasDatabaseName("IX_ProductVariant_Product_Size_Color") - .HasFilter("[Color] IS NOT NULL"); - - b.ToTable("ProductVariants"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.Address", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasDefaultValueSql("NEWID()"); - - b.Property("AddressType") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("City") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("IsDefault") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(false); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("PostalCode") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); - - b.Property("State") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Street") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("UserId") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_Address_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_Address_CreatedBy"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_Address_ModifiedAt"); - - b.HasIndex("UserId") - .HasDatabaseName("IX_Address_UserId"); - - b.HasIndex("UserId", "AddressType") - .HasDatabaseName("IX_Address_User_Type"); - - b.HasIndex("UserId", "IsDefault") - .HasDatabaseName("IX_Address_User_Default"); - - b.ToTable("Addresses"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.Role", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("RoleName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("RoleName") - .IsUnique() - .HasDatabaseName("IX_Role_RoleName"); - - b.ToTable("Role"); - - b.HasData( - new - { - Id = new Guid("11111111-1111-1111-1111-111111111111"), - RoleName = "User" - }, - new - { - Id = new Guid("22222222-2222-2222-2222-222222222222"), - RoleName = "Merchant" - }, - new - { - Id = new Guid("33333333-3333-3333-3333-333333333333"), - RoleName = "Admin" - }); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => - { - b.Property("Id") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("DateOfBirth") - .HasColumnType("date"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("IsActive") - .ValueGeneratedOnAdd() - .HasColumnType("bit") - .HasDefaultValue(true); - - b.Property("LastLoginAt") - .HasColumnType("datetime2"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("PhoneNumber") - .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_User_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_User_CreatedBy"); - - b.HasIndex("Email") - .IsUnique() - .HasDatabaseName("IX_User_Email"); - - b.HasIndex("IsActive") - .HasDatabaseName("IX_User_IsActive"); - - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_User_ModifiedAt"); - - b.ToTable("User"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.UserRole", b => - { - b.Property("UserId") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - - b.Property("RoleId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId") - .HasDatabaseName("IX_UserRole_RoleId"); - - b.HasIndex("UserId") - .HasDatabaseName("IX_UserRole_UserId"); - - b.ToTable("UserRole"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => - { - b.HasOne("Imprink.Domain.Entities.Orders.OrderStatus", "OrderStatus") - .WithMany("Orders") - .HasForeignKey("OrderStatusId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Orders.ShippingStatus", "ShippingStatus") - .WithMany("Orders") - .HasForeignKey("ShippingStatusId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Users.User", "User") - .WithMany("Orders") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("OrderStatus"); - - b.Navigation("ShippingStatus"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderAddress", b => - { - b.HasOne("Imprink.Domain.Entities.Orders.Order", "Order") - .WithOne("OrderAddress") - .HasForeignKey("Imprink.Domain.Entities.Orders.OrderAddress", "OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Order"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderItem", b => - { - b.HasOne("Imprink.Domain.Entities.Orders.Order", "Order") - .WithMany("OrderItems") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Product.Product", "Product") - .WithMany("OrderItems") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Product.ProductVariant", "ProductVariant") - .WithMany("OrderItems") - .HasForeignKey("ProductVariantId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("Order"); - - b.Navigation("Product"); - - b.Navigation("ProductVariant"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Category", b => - { - b.HasOne("Imprink.Domain.Entities.Product.Category", "ParentCategory") - .WithMany("SubCategories") - .HasForeignKey("ParentCategoryId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("ParentCategory"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => - { - b.HasOne("Imprink.Domain.Entities.Product.Category", "Category") - .WithMany("Products") - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.SetNull); - - b.Navigation("Category"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => - { - b.HasOne("Imprink.Domain.Entities.Product.Product", "Product") - .WithMany("ProductVariants") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.Address", b => - { - b.HasOne("Imprink.Domain.Entities.Users.User", null) - .WithMany("Addresses") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.UserRole", b => - { - b.HasOne("Imprink.Domain.Entities.Users.Role", "Role") - .WithMany("UserRoles") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Imprink.Domain.Entities.Users.User", null) - .WithMany("UserRoles") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Role"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => - { - b.Navigation("OrderAddress") - .IsRequired(); - - b.Navigation("OrderItems"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderStatus", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Orders.ShippingStatus", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Category", b => - { - b.Navigation("Products"); - - b.Navigation("SubCategories"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => - { - b.Navigation("OrderItems"); - - b.Navigation("ProductVariants"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => - { - b.Navigation("OrderItems"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.Role", b => - { - b.Navigation("UserRoles"); - }); - - modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => - { - b.Navigation("Addresses"); - - b.Navigation("Orders"); - - b.Navigation("UserRoles"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.cs b/src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.cs deleted file mode 100644 index 5ebedd2..0000000 --- a/src/Imprink.Infrastructure/Migrations/20250606162608_RelateUsersAndOrders.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Imprink.Infrastructure.Migrations -{ - /// - public partial class RelateUsersAndOrders : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddForeignKey( - name: "FK_Orders_User_UserId", - table: "Orders", - column: "UserId", - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_User_UserId", - table: "Orders"); - } - } -} diff --git a/src/Imprink.Infrastructure/Migrations/20250606161235_AddUserRoles.Designer.cs b/src/Imprink.Infrastructure/Migrations/20250606173957_InitialSetup.Designer.cs similarity index 96% rename from src/Imprink.Infrastructure/Migrations/20250606161235_AddUserRoles.Designer.cs rename to src/Imprink.Infrastructure/Migrations/20250606173957_InitialSetup.Designer.cs index e1d71ca..4ce7e76 100644 --- a/src/Imprink.Infrastructure/Migrations/20250606161235_AddUserRoles.Designer.cs +++ b/src/Imprink.Infrastructure/Migrations/20250606173957_InitialSetup.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Imprink.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20250606161235_AddUserRoles")] - partial class AddUserRoles + [Migration("20250606173957_InitialSetup")] + partial class InitialSetup { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -740,7 +740,7 @@ namespace Imprink.Infrastructure.Migrations .IsUnique() .HasDatabaseName("IX_Role_RoleName"); - b.ToTable("Role"); + b.ToTable("Roles"); b.HasData( new @@ -763,15 +763,6 @@ namespace Imprink.Infrastructure.Migrations modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => { b.Property("Id") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() .HasMaxLength(450) .HasColumnType("nvarchar(450)"); @@ -801,28 +792,12 @@ namespace Imprink.Infrastructure.Migrations .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - b.Property("PhoneNumber") .HasMaxLength(20) .HasColumnType("nvarchar(20)"); b.HasKey("Id"); - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_User_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_User_CreatedBy"); - b.HasIndex("Email") .IsUnique() .HasDatabaseName("IX_User_Email"); @@ -830,10 +805,7 @@ namespace Imprink.Infrastructure.Migrations b.HasIndex("IsActive") .HasDatabaseName("IX_User_IsActive"); - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_User_ModifiedAt"); - - b.ToTable("User"); + b.ToTable("Users"); }); modelBuilder.Entity("Imprink.Domain.Entities.Users.UserRole", b => @@ -853,7 +825,7 @@ namespace Imprink.Infrastructure.Migrations b.HasIndex("UserId") .HasDatabaseName("IX_UserRole_UserId"); - b.ToTable("UserRole"); + b.ToTable("UserRoles"); }); modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => @@ -870,9 +842,17 @@ namespace Imprink.Infrastructure.Migrations .OnDelete(DeleteBehavior.Restrict) .IsRequired(); + b.HasOne("Imprink.Domain.Entities.Users.User", "User") + .WithMany("Orders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + b.Navigation("OrderStatus"); b.Navigation("ShippingStatus"); + + b.Navigation("User"); }); modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderAddress", b => @@ -960,13 +940,15 @@ namespace Imprink.Infrastructure.Migrations .OnDelete(DeleteBehavior.Restrict) .IsRequired(); - b.HasOne("Imprink.Domain.Entities.Users.User", null) + b.HasOne("Imprink.Domain.Entities.Users.User", "User") .WithMany("UserRoles") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Role"); + + b.Navigation("User"); }); modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => @@ -1015,6 +997,8 @@ namespace Imprink.Infrastructure.Migrations { b.Navigation("Addresses"); + b.Navigation("Orders"); + b.Navigation("UserRoles"); }); #pragma warning restore 612, 618 diff --git a/src/Imprink.Infrastructure/Migrations/20250603173128_InitialSetup.cs b/src/Imprink.Infrastructure/Migrations/20250606173957_InitialSetup.cs similarity index 85% rename from src/Imprink.Infrastructure/Migrations/20250603173128_InitialSetup.cs rename to src/Imprink.Infrastructure/Migrations/20250606173957_InitialSetup.cs index 3089515..770da5f 100644 --- a/src/Imprink.Infrastructure/Migrations/20250603173128_InitialSetup.cs +++ b/src/Imprink.Infrastructure/Migrations/20250606173957_InitialSetup.cs @@ -13,30 +13,6 @@ namespace Imprink.Infrastructure.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.CreateTable( - name: "Addresses", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), - UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), - AddressType = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), - Street = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), - City = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - State = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - PostalCode = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), - Country = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - IsDefault = table.Column(type: "bit", nullable: false, defaultValue: false), - IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), - CreatedAt = table.Column(type: "datetime2", nullable: false), - ModifiedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), - CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), - ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Addresses", x => x.Id); - }); - migrationBuilder.CreateTable( name: "Categories", columns: table => new @@ -76,6 +52,18 @@ namespace Imprink.Infrastructure.Migrations table.PrimaryKey("PK_OrderStatuses", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Roles", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + RoleName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.Id); + }); + migrationBuilder.CreateTable( name: "ShippingStatuses", columns: table => new @@ -88,6 +76,24 @@ namespace Imprink.Infrastructure.Migrations table.PrimaryKey("PK_ShippingStatuses", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), + Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), + FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PhoneNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + DateOfBirth = table.Column(type: "date", nullable: true), + IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), + LastLoginAt = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Products", columns: table => new @@ -116,6 +122,36 @@ namespace Imprink.Infrastructure.Migrations onDelete: ReferentialAction.SetNull); }); + migrationBuilder.CreateTable( + name: "Addresses", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), + UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), + AddressType = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Street = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + City = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + State = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PostalCode = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), + Country = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + IsDefault = table.Column(type: "bit", nullable: false, defaultValue: false), + IsActive = table.Column(type: "bit", nullable: false, defaultValue: true), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), + CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), + ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Addresses", x => x.Id); + table.ForeignKey( + name: "FK_Addresses_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -148,6 +184,36 @@ namespace Imprink.Infrastructure.Migrations principalTable: "ShippingStatuses", principalColumn: "Id", onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Orders_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "UserRoles", + columns: table => new + { + UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), + RoleId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_UserRoles_Roles_RoleId", + column: x => x.RoleId, + principalTable: "Roles", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_UserRoles_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -268,6 +334,16 @@ namespace Imprink.Infrastructure.Migrations { 3, "Cancelled" } }); + migrationBuilder.InsertData( + table: "Roles", + columns: new[] { "Id", "RoleName" }, + values: new object[,] + { + { new Guid("11111111-1111-1111-1111-111111111111"), "User" }, + { new Guid("22222222-2222-2222-2222-222222222222"), "Merchant" }, + { new Guid("33333333-3333-3333-3333-333333333333"), "Admin" } + }); + migrationBuilder.InsertData( table: "ShippingStatuses", columns: new[] { "Id", "Name" }, @@ -540,11 +616,38 @@ namespace Imprink.Infrastructure.Migrations column: "Sku", unique: true); + migrationBuilder.CreateIndex( + name: "IX_Role_RoleName", + table: "Roles", + column: "RoleName", + unique: true); + migrationBuilder.CreateIndex( name: "IX_ShippingStatus_Name", table: "ShippingStatuses", column: "Name", unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserRole_RoleId", + table: "UserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_UserRole_UserId", + table: "UserRoles", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_User_Email", + table: "Users", + column: "Email", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_User_IsActive", + table: "Users", + column: "IsActive"); } /// @@ -559,18 +662,27 @@ namespace Imprink.Infrastructure.Migrations migrationBuilder.DropTable( name: "OrderItems"); + migrationBuilder.DropTable( + name: "UserRoles"); + migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "ProductVariants"); + migrationBuilder.DropTable( + name: "Roles"); + migrationBuilder.DropTable( name: "OrderStatuses"); migrationBuilder.DropTable( name: "ShippingStatuses"); + migrationBuilder.DropTable( + name: "Users"); + migrationBuilder.DropTable( name: "Products"); diff --git a/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs index b88b787..060d38d 100644 --- a/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -737,7 +737,7 @@ namespace Imprink.Infrastructure.Migrations .IsUnique() .HasDatabaseName("IX_Role_RoleName"); - b.ToTable("Role"); + b.ToTable("Roles"); b.HasData( new @@ -760,15 +760,6 @@ namespace Imprink.Infrastructure.Migrations modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => { b.Property("Id") - .HasMaxLength(450) - .HasColumnType("nvarchar(450)") - .HasDefaultValueSql("NEWID()"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() .HasMaxLength(450) .HasColumnType("nvarchar(450)"); @@ -798,28 +789,12 @@ namespace Imprink.Infrastructure.Migrations .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); - - b.Property("ModifiedBy") - .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); - b.Property("PhoneNumber") .HasMaxLength(20) .HasColumnType("nvarchar(20)"); b.HasKey("Id"); - b.HasIndex("CreatedAt") - .HasDatabaseName("IX_User_CreatedAt"); - - b.HasIndex("CreatedBy") - .HasDatabaseName("IX_User_CreatedBy"); - b.HasIndex("Email") .IsUnique() .HasDatabaseName("IX_User_Email"); @@ -827,10 +802,7 @@ namespace Imprink.Infrastructure.Migrations b.HasIndex("IsActive") .HasDatabaseName("IX_User_IsActive"); - b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_User_ModifiedAt"); - - b.ToTable("User"); + b.ToTable("Users"); }); modelBuilder.Entity("Imprink.Domain.Entities.Users.UserRole", b => @@ -850,7 +822,7 @@ namespace Imprink.Infrastructure.Migrations b.HasIndex("UserId") .HasDatabaseName("IX_UserRole_UserId"); - b.ToTable("UserRole"); + b.ToTable("UserRoles"); }); modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => @@ -965,13 +937,15 @@ namespace Imprink.Infrastructure.Migrations .OnDelete(DeleteBehavior.Restrict) .IsRequired(); - b.HasOne("Imprink.Domain.Entities.Users.User", null) + b.HasOne("Imprink.Domain.Entities.Users.User", "User") .WithMany("UserRoles") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Role"); + + b.Navigation("User"); }); modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => diff --git a/src/Imprink.Infrastructure/Repositories/RoleRepository.cs b/src/Imprink.Infrastructure/Repositories/RoleRepository.cs new file mode 100644 index 0000000..e6c979c --- /dev/null +++ b/src/Imprink.Infrastructure/Repositories/RoleRepository.cs @@ -0,0 +1,36 @@ +using Imprink.Domain.Entities.Users; +using Imprink.Domain.Repositories; +using Imprink.Infrastructure.Database; +using Microsoft.EntityFrameworkCore; + +namespace Imprink.Infrastructure.Repositories; + +public class RoleRepository(ApplicationDbContext context) : IRoleRepository +{ + public async Task> GetAllRolesAsync(CancellationToken cancellationToken = default) + { + return await context.Roles + .AsNoTracking() + .ToListAsync(cancellationToken); + } + + public async Task GetRoleByIdAsync(Guid roleId, CancellationToken cancellationToken = default) + { + return await context.Roles + .AsNoTracking() + .FirstOrDefaultAsync(r => r.Id == roleId, cancellationToken); + } + + public async Task GetRoleByNameAsync(string roleName, CancellationToken cancellationToken = default) + { + return await context.Roles + .AsNoTracking() + .FirstOrDefaultAsync(r => r.RoleName == roleName, cancellationToken); + } + + public async Task RoleExistsAsync(Guid roleId, CancellationToken cancellationToken = default) + { + return await context.Roles + .AnyAsync(r => r.Id == roleId, cancellationToken); + } +} \ No newline at end of file diff --git a/src/Imprink.Infrastructure/Repositories/UserRepository.cs b/src/Imprink.Infrastructure/Repositories/UserRepository.cs new file mode 100644 index 0000000..7addee9 --- /dev/null +++ b/src/Imprink.Infrastructure/Repositories/UserRepository.cs @@ -0,0 +1,181 @@ +using Imprink.Domain.Entities.Users; +using Imprink.Domain.Repositories; +using Imprink.Infrastructure.Database; +using Microsoft.EntityFrameworkCore; + +namespace Imprink.Infrastructure.Repositories; + +public class UserRepository(ApplicationDbContext context) : IUserRepository +{ + public async Task GetUserByIdAsync(string userId, CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .FirstOrDefaultAsync(u => u.Id == userId, cancellationToken); + } + + public async Task GetUserByEmailAsync(string email, CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .FirstOrDefaultAsync(u => u.Email == email, cancellationToken); + } + + public async Task> GetAllUsersAsync(CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .ToListAsync(cancellationToken); + } + + public async Task> GetActiveUsersAsync(CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .Where(u => u.IsActive) + .ToListAsync(cancellationToken); + } + + public async Task CreateUserAsync(User user, CancellationToken cancellationToken = default) + { + context.Users.Add(user); + await context.SaveChangesAsync(cancellationToken); + return user; + } + + public async Task UpdateUserAsync(User user, CancellationToken cancellationToken = default) + { + context.Users.Update(user); + await context.SaveChangesAsync(cancellationToken); + return user; + } + + public async Task DeleteUserAsync(string userId, CancellationToken cancellationToken = default) + { + var user = await context.Users.FindAsync(new object[] { userId }, cancellationToken); + if (user != null) + { + context.Users.Remove(user); + await context.SaveChangesAsync(cancellationToken); + } + } + + public async Task UserExistsAsync(string userId, CancellationToken cancellationToken = default) + { + return await context.Users + .AnyAsync(u => u.Id == userId, cancellationToken); + } + + public async Task EmailExistsAsync(string email, CancellationToken cancellationToken = default) + { + return await context.Users + .AnyAsync(u => u.Email == email, cancellationToken); + } + + public async Task ActivateUserAsync(string userId, CancellationToken cancellationToken = default) + { + var user = await context.Users.FindAsync(new object[] { userId }, cancellationToken); + if (user == null) return false; + + user.IsActive = true; + await context.SaveChangesAsync(cancellationToken); + return true; + } + + public async Task DeactivateUserAsync(string userId, CancellationToken cancellationToken = default) + { + var user = await context.Users.FindAsync(new object[] { userId }, cancellationToken); + if (user == null) return false; + + user.IsActive = false; + await context.SaveChangesAsync(cancellationToken); + return true; + } + + public async Task UpdateLastLoginAsync(string userId, DateTime loginTime, CancellationToken cancellationToken = default) + { + var user = await context.Users.FindAsync(new object[] { userId }, cancellationToken); + if (user != null) + { + user.LastLoginAt = loginTime; + await context.SaveChangesAsync(cancellationToken); + } + } + + public async Task> SearchUsersAsync(string searchTerm, CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .Where(u => u.Email.Contains(searchTerm) || + u.FirstName.Contains(searchTerm) || + u.LastName.Contains(searchTerm)) + .ToListAsync(cancellationToken); + } + + public async Task> GetUsersByRoleAsync(Guid roleId, CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .Where(u => u.UserRoles.Any(ur => ur.RoleId == roleId)) + .ToListAsync(cancellationToken); + } + + public async Task<(IEnumerable Users, int TotalCount)> GetUsersPagedAsync( + int pageNumber, + int pageSize, + string? searchTerm = null, + bool? isActive = null, + CancellationToken cancellationToken = default) + { + var query = context.Users.AsNoTracking(); + + if (!string.IsNullOrEmpty(searchTerm)) + { + query = query.Where(u => u.Email.Contains(searchTerm) || + u.FirstName.Contains(searchTerm) || + u.LastName.Contains(searchTerm)); + } + + if (isActive.HasValue) + { + query = query.Where(u => u.IsActive == isActive.Value); + } + + var totalCount = await query.CountAsync(cancellationToken); + + var users = await query + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToListAsync(cancellationToken); + + return (users, totalCount); + } + + public async Task GetUserWithAddressesAsync(string userId, CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .Include(u => u.Addresses) + .FirstOrDefaultAsync(u => u.Id == userId, cancellationToken); + } + + public async Task GetUserWithRolesAsync(string userId, CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .Include(u => u.UserRoles) + .ThenInclude(ur => ur.Role) + .FirstOrDefaultAsync(u => u.Id == userId, cancellationToken); + } + + public async Task GetUserWithAllRelatedDataAsync(string userId, CancellationToken cancellationToken = default) + { + return await context.Users + .AsNoTracking() + .Include(u => u.Addresses) + .Include(u => u.UserRoles) + .ThenInclude(ur => ur.Role) + .Include(u => u.Orders) + .FirstOrDefaultAsync(u => u.Id == userId, cancellationToken); + } +} \ No newline at end of file diff --git a/src/Imprink.Infrastructure/Repositories/UserRoleRepository.cs b/src/Imprink.Infrastructure/Repositories/UserRoleRepository.cs new file mode 100644 index 0000000..1cb2a27 --- /dev/null +++ b/src/Imprink.Infrastructure/Repositories/UserRoleRepository.cs @@ -0,0 +1,60 @@ +using Imprink.Domain.Entities.Users; +using Imprink.Domain.Repositories; +using Imprink.Infrastructure.Database; +using Microsoft.EntityFrameworkCore; + +namespace Imprink.Infrastructure.Repositories; + +public class UserRoleRepository(ApplicationDbContext context) : IUserRoleRepository +{ + public async Task> GetUserRolesAsync(string userId, CancellationToken cancellationToken = default) + { + return await context.UserRoles + .AsNoTracking() + .Where(ur => ur.UserId == userId) + .Select(ur => ur.Role) + .ToListAsync(cancellationToken); + } + + public async Task> GetUsersInRoleAsync(Guid roleId, CancellationToken cancellationToken = default) + { + return await context.UserRoles + .AsNoTracking() + .Where(ur => ur.RoleId == roleId) + .Select(ur => ur.User) + .ToListAsync(cancellationToken); + } + + public async Task IsUserInRoleAsync(string userId, Guid roleId, CancellationToken cancellationToken = default) + { + return await context.UserRoles + .AnyAsync(ur => ur.UserId == userId && ur.RoleId == roleId, cancellationToken); + } + + public async Task GetUserRoleAsync(string userId, Guid roleId, CancellationToken cancellationToken = default) + { + return await context.UserRoles + .AsNoTracking() + .FirstOrDefaultAsync(ur => ur.UserId == userId && ur.RoleId == roleId, cancellationToken); + } + + public async Task AddUserRoleAsync(UserRole userRole, CancellationToken cancellationToken = default) + { + context.UserRoles.Add(userRole); + await context.SaveChangesAsync(cancellationToken); + } + + public async Task RemoveUserRoleAsync(UserRole userRole, CancellationToken cancellationToken = default) + { + context.UserRoles.Remove(userRole); + await context.SaveChangesAsync(cancellationToken); + } + + public async Task> GetUserRolesByUserIdAsync(string userId, CancellationToken cancellationToken = default) + { + return await context.UserRoles + .AsNoTracking() + .Where(ur => ur.UserId == userId) + .ToListAsync(cancellationToken); + } +} \ No newline at end of file diff --git a/src/Imprink.WebApi/Controllers/Users/UserController.cs b/src/Imprink.WebApi/Controllers/Users/UserController.cs new file mode 100644 index 0000000..4c9e1d6 --- /dev/null +++ b/src/Imprink.WebApi/Controllers/Users/UserController.cs @@ -0,0 +1,30 @@ +using System.Security.Claims; +using Imprink.Domain.Common.Models; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Imprink.WebApi.Controllers.Users; + +[ApiController] +[Route("/api/[controller]")] +public class UserController : ControllerBase +{ + [Authorize] + [HttpPost] + public IActionResult SyncUser() + { + var claims = User.Claims; + + var enumerable = claims as Claim[] ?? claims.ToArray(); + var user = new Auth0User + { + Sub = enumerable.FirstOrDefault(c => c.Type == "sub")?.Value ?? "", + Name = enumerable.FirstOrDefault(c => c.Type == "name")?.Value ?? "", + Nickname = enumerable.FirstOrDefault(c => c.Type == "nickname")?.Value ?? "", + Email = enumerable.FirstOrDefault(c => c.Type == "email")?.Value ?? "", + EmailVerified = enumerable.FirstOrDefault(c => c.Type == "email_verified")?.Value == "true" + }; + + return Ok(user); + } +} \ No newline at end of file diff --git a/src/Imprink.WebApi/Imprink.WebApi.csproj b/src/Imprink.WebApi/Imprink.WebApi.csproj index 74587f2..5ed647b 100644 --- a/src/Imprink.WebApi/Imprink.WebApi.csproj +++ b/src/Imprink.WebApi/Imprink.WebApi.csproj @@ -31,7 +31,6 @@ - diff --git a/src/Imprink.WebApi/Startup.cs b/src/Imprink.WebApi/Startup.cs index 18bcfa4..c0431db 100644 --- a/src/Imprink.WebApi/Startup.cs +++ b/src/Imprink.WebApi/Startup.cs @@ -18,6 +18,9 @@ public static class Startup services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddDbContext(options => diff --git a/webui/src/app/page.js b/webui/src/app/page.js index 5c582f4..40de756 100644 --- a/webui/src/app/page.js +++ b/webui/src/app/page.js @@ -5,27 +5,10 @@ import {useEffect, useState} from "react"; export default function Home() { const { user, error, isLoading } = useUser(); - const [accessToken, setAccessToken] = useState(null); - useEffect(() => { - const fetchAccessToken = async () => { - if (user) { - try { - const response = await fetch('/auth/access-token'); - if (response.ok) { - const tokenData = await response.text(); - setAccessToken(tokenData); - } else { - setAccessToken('Token not available'); - } - } catch (error) { - setAccessToken('Error fetching token'); - } - } - }; - - fetchAccessToken().then(r => console.log(r)); - }, [user]); + async function checkValidity() { + const check = await fetch('https://impr.ink/auth/sync', {method: 'POST'}); + } if (isLoading) { return ( @@ -131,15 +114,6 @@ export default function Home() { )} -
- -
- {accessToken} -
-
@@ -160,11 +134,22 @@ export default function Home() {