diff --git a/src/Imprink.Application/Commands/Addresses/CreateAddressHandler.cs b/src/Imprink.Application/Commands/Addresses/CreateAddressHandler.cs index 5d8da24..83de43c 100644 --- a/src/Imprink.Application/Commands/Addresses/CreateAddressHandler.cs +++ b/src/Imprink.Application/Commands/Addresses/CreateAddressHandler.cs @@ -1,13 +1,14 @@ using AutoMapper; using Imprink.Application.Dtos; +using Imprink.Application.Services; using Imprink.Domain.Entities; using MediatR; +using Microsoft.Extensions.Logging; namespace Imprink.Application.Commands.Addresses; public class CreateAddressCommand : IRequest { - public string UserId { get; set; } = null!; public string AddressType { get; set; } = null!; public string? FirstName { get; set; } public string? LastName { get; set; } @@ -27,7 +28,12 @@ public class CreateAddressCommand : IRequest public bool IsActive { get; set; } = true; } -public class CreateAddressHandler(IUnitOfWork uw, IMapper mapper) : IRequestHandler +public class CreateAddressHandler( + IUnitOfWork uw, + IMapper mapper, + ICurrentUserService userService, + ILogger logger) + : IRequestHandler { public async Task Handle(CreateAddressCommand request, CancellationToken cancellationToken) { @@ -35,6 +41,10 @@ public class CreateAddressHandler(IUnitOfWork uw, IMapper mapper) : IRequestHand { var address = mapper.Map
(request); + address.UserId = userService.GetCurrentUserId()!; + address.CreatedAt = DateTime.UtcNow; + address.ModifiedAt = DateTime.UtcNow; + if (address.IsDefault) { var currentDefault = await uw.AddressRepository.GetDefaultByUserIdAsync(address.UserId, cancellationToken); @@ -46,6 +56,8 @@ public class CreateAddressHandler(IUnitOfWork uw, IMapper mapper) : IRequestHand } var createdAddress = await uw.AddressRepository.AddAsync(address, cancellationToken); + + await uw.SaveAsync(cancellationToken); return mapper.Map(createdAddress); }, cancellationToken); } diff --git a/src/Imprink.Application/Commands/Orders/CreateOrderHandler.cs b/src/Imprink.Application/Commands/Orders/CreateOrderHandler.cs index ac9a59c..55b09f6 100644 --- a/src/Imprink.Application/Commands/Orders/CreateOrderHandler.cs +++ b/src/Imprink.Application/Commands/Orders/CreateOrderHandler.cs @@ -1,5 +1,7 @@ using AutoMapper; using Imprink.Application.Dtos; +using Imprink.Application.Exceptions; +using Imprink.Application.Services; using Imprink.Domain.Entities; using MediatR; @@ -7,7 +9,6 @@ namespace Imprink.Application.Commands.Orders; public class CreateOrderCommand : IRequest { - public string UserId { get; set; } = null!; public decimal Amount { get; set; } public int Quantity { get; set; } public Guid ProductId { get; set; } @@ -15,29 +16,30 @@ public class CreateOrderCommand : IRequest public string? Notes { get; set; } public string? MerchantId { get; set; } public string? ComposingImageUrl { get; set; } - public string[] OriginalImageUrls { get; set; } = []; - public string CustomizationImageUrl { get; set; } = null!; - public string CustomizationDescription { get; set; } = null!; + public string[]? OriginalImageUrls { get; set; } = []; + public string? CustomizationImageUrl { get; set; } = null!; + public string? CustomizationDescription { get; set; } = null!; public Guid AddressId { get; set; } } -public class CreateOrderHandler(IUnitOfWork uw, IMapper mapper) : IRequestHandler +public class CreateOrderHandler(IUnitOfWork uw, IMapper mapper, ICurrentUserService userService) : IRequestHandler { public async Task Handle(CreateOrderCommand request, CancellationToken cancellationToken) { return await uw.TransactAsync(async () => { - var sourceAddress = await uw.AddressRepository.GetByIdAndUserIdAsync(request.AddressId, request.UserId, cancellationToken); + var sourceAddress = await uw.AddressRepository.GetByIdAndUserIdAsync(request.AddressId, userService.GetCurrentUserId()!, cancellationToken); if (sourceAddress == null) { - throw new ArgumentException($"Address with ID {request.AddressId} not found for user {request.UserId}"); + throw new NotFoundException($"Address with ID {request.AddressId} not found for user {userService.GetCurrentUserId()!}"); } var order = mapper.Map(request); + order.UserId = userService.GetCurrentUserId()!; order.OrderDate = DateTime.UtcNow; - order.OrderStatusId = 1; - order.ShippingStatusId = 1; + order.OrderStatusId = 0; + order.ShippingStatusId = 0; var createdOrder = await uw.OrderRepository.AddAsync(order, cancellationToken); @@ -70,6 +72,8 @@ public class CreateOrderHandler(IUnitOfWork uw, IMapper mapper) : IRequestHandle { createdOrder.ProductVariant = await uw.ProductVariantRepository.GetByIdAsync(createdOrder.ProductVariantId.Value, cancellationToken); } + + await uw.SaveAsync(cancellationToken); return mapper.Map(createdOrder); }, cancellationToken); diff --git a/src/Imprink.Application/Dtos/AddressDto.cs b/src/Imprink.Application/Dtos/AddressDto.cs index 6887b18..29512f5 100644 --- a/src/Imprink.Application/Dtos/AddressDto.cs +++ b/src/Imprink.Application/Dtos/AddressDto.cs @@ -21,6 +21,4 @@ public class AddressDto public string? Instructions { get; set; } public bool IsDefault { get; set; } public bool IsActive { get; set; } - public DateTime CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } } \ No newline at end of file diff --git a/src/Imprink.Application/Dtos/OrderDto.cs b/src/Imprink.Application/Dtos/OrderDto.cs index 9c1cb3f..947aea7 100644 --- a/src/Imprink.Application/Dtos/OrderDto.cs +++ b/src/Imprink.Application/Dtos/OrderDto.cs @@ -11,13 +11,11 @@ public class OrderDto public Guid? ProductVariantId { get; set; } public int OrderStatusId { get; set; } public int ShippingStatusId { get; set; } - public string OrderNumber { get; set; } = null!; public string? Notes { get; set; } public string? MerchantId { get; set; } - public string? ComposingImageUrl { get; set; } - public string[] OriginalImageUrls { get; set; } = []; - public string CustomizationImageUrl { get; set; } = null!; - public string CustomizationDescription { get; set; } = null!; + public string? CustomizationImageUrl { get; set; } + public string[]? OriginalImageUrls { get; set; } = []; + public string? CustomizationDescription { get; set; } = null!; public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } diff --git a/src/Imprink.Application/Mappings/AddressMappingProfile.cs b/src/Imprink.Application/Mappings/AddressMappingProfile.cs new file mode 100644 index 0000000..13236f4 --- /dev/null +++ b/src/Imprink.Application/Mappings/AddressMappingProfile.cs @@ -0,0 +1,23 @@ +using AutoMapper; +using Imprink.Application.Commands.Addresses; +using Imprink.Application.Dtos; +using Imprink.Domain.Entities; + +namespace Imprink.Application.Mappings; + +public class AddressMappingProfile : Profile +{ + public AddressMappingProfile() + { + CreateMap() + .ForMember(dest => dest.Id, opt => opt.Ignore()) + .ForMember(dest => dest.CreatedAt, opt => opt.Ignore()) + .ForMember(dest => dest.ModifiedAt, opt => opt.Ignore()) + .ForMember(dest => dest.User, opt => opt.Ignore()); + + CreateMap(); + + CreateMap() + .ForMember(dest => dest.User, opt => opt.Ignore()); + } +} \ No newline at end of file diff --git a/src/Imprink.Application/Mappings/OrderAddressMappingProfile.cs b/src/Imprink.Application/Mappings/OrderAddressMappingProfile.cs new file mode 100644 index 0000000..6524393 --- /dev/null +++ b/src/Imprink.Application/Mappings/OrderAddressMappingProfile.cs @@ -0,0 +1,38 @@ +using AutoMapper; +using Imprink.Application.Dtos; +using Imprink.Domain.Entities; + +namespace Imprink.Application.Mappings; + +public class OrderAddressMappingProfile : Profile +{ + public OrderAddressMappingProfile() + { + CreateMap(); + + CreateMap() + .ForMember(dest => dest.Order, opt => opt.Ignore()); + + CreateMap() + .ForMember(dest => dest.Id, opt => opt.Ignore()) + .ForMember(dest => dest.OrderId, opt => opt.Ignore()) + .ForMember(dest => dest.Order, opt => opt.Ignore()) + .ForMember(dest => dest.CreatedAt, opt => opt.Ignore()) + .ForMember(dest => dest.ModifiedAt, opt => opt.Ignore()) + .ForMember(dest => dest.AddressType, opt => opt.MapFrom(src => src.AddressType)) + .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.FirstName)) + .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.LastName)) + .ForMember(dest => dest.Company, opt => opt.MapFrom(src => src.Company)) + .ForMember(dest => dest.AddressLine1, opt => opt.MapFrom(src => src.AddressLine1)) + .ForMember(dest => dest.AddressLine2, opt => opt.MapFrom(src => src.AddressLine2)) + .ForMember(dest => dest.ApartmentNumber, opt => opt.MapFrom(src => src.ApartmentNumber)) + .ForMember(dest => dest.BuildingNumber, opt => opt.MapFrom(src => src.BuildingNumber)) + .ForMember(dest => dest.Floor, opt => opt.MapFrom(src => src.Floor)) + .ForMember(dest => dest.City, opt => opt.MapFrom(src => src.City)) + .ForMember(dest => dest.State, opt => opt.MapFrom(src => src.State)) + .ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.PostalCode)) + .ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.Country)) + .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.PhoneNumber)) + .ForMember(dest => dest.Instructions, opt => opt.MapFrom(src => src.Instructions)); + } +} \ No newline at end of file diff --git a/src/Imprink.Application/Mappings/OrderMappingProfile.cs b/src/Imprink.Application/Mappings/OrderMappingProfile.cs new file mode 100644 index 0000000..82a83ad --- /dev/null +++ b/src/Imprink.Application/Mappings/OrderMappingProfile.cs @@ -0,0 +1,36 @@ +using AutoMapper; +using Imprink.Application.Commands.Orders; +using Imprink.Application.Dtos; +using Imprink.Domain.Entities; + +namespace Imprink.Application.Mappings; + +public class OrderMappingProfile : Profile +{ + public OrderMappingProfile() + { + CreateMap() + .ForMember(dest => dest.Id, opt => opt.Ignore()) + .ForMember(dest => dest.OrderDate, opt => opt.Ignore()) + .ForMember(dest => dest.OrderStatusId, opt => opt.Ignore()) + .ForMember(dest => dest.ShippingStatusId, opt => opt.Ignore()) + .ForMember(dest => dest.CreatedAt, opt => opt.Ignore()) + .ForMember(dest => dest.ModifiedAt, opt => opt.Ignore()) + .ForMember(dest => dest.OrderStatus, opt => opt.Ignore()) + .ForMember(dest => dest.User, opt => opt.Ignore()) + .ForMember(dest => dest.ShippingStatus, opt => opt.Ignore()) + .ForMember(dest => dest.OrderAddress, opt => opt.Ignore()) + .ForMember(dest => dest.Product, opt => opt.Ignore()) + .ForMember(dest => dest.ProductVariant, opt => opt.Ignore()); + + CreateMap(); + + CreateMap() + .ForMember(dest => dest.OrderStatus, opt => opt.Ignore()) + .ForMember(dest => dest.User, opt => opt.Ignore()) + .ForMember(dest => dest.ShippingStatus, opt => opt.Ignore()) + .ForMember(dest => dest.OrderAddress, opt => opt.Ignore()) + .ForMember(dest => dest.Product, opt => opt.Ignore()) + .ForMember(dest => dest.ProductVariant, opt => opt.Ignore()); + } +} \ No newline at end of file diff --git a/src/Imprink.Application/Mappings/OrderStatusMappingProfile.cs b/src/Imprink.Application/Mappings/OrderStatusMappingProfile.cs new file mode 100644 index 0000000..c61c7fe --- /dev/null +++ b/src/Imprink.Application/Mappings/OrderStatusMappingProfile.cs @@ -0,0 +1,15 @@ +using AutoMapper; +using Imprink.Application.Dtos; +using Imprink.Domain.Entities; + +namespace Imprink.Application.Mappings; + +public class OrderStatusMappingProfile : Profile +{ + public OrderStatusMappingProfile() + { + CreateMap(); + + CreateMap(); + } +} \ No newline at end of file diff --git a/src/Imprink.Application/Mappings/ShippingStatusMappingProfile.cs b/src/Imprink.Application/Mappings/ShippingStatusMappingProfile.cs new file mode 100644 index 0000000..16a60a5 --- /dev/null +++ b/src/Imprink.Application/Mappings/ShippingStatusMappingProfile.cs @@ -0,0 +1,15 @@ +using AutoMapper; +using Imprink.Application.Dtos; +using Imprink.Domain.Entities; + +namespace Imprink.Application.Mappings; + +public class ShippingStatusMappingProfile : Profile +{ + public ShippingStatusMappingProfile() + { + CreateMap(); + + CreateMap(); + } +} \ No newline at end of file diff --git a/src/Imprink.Domain/Entities/Order.cs b/src/Imprink.Domain/Entities/Order.cs index 144d8b3..e67ff02 100644 --- a/src/Imprink.Domain/Entities/Order.cs +++ b/src/Imprink.Domain/Entities/Order.cs @@ -2,7 +2,7 @@ namespace Imprink.Domain.Entities; public class Order : EntityBase { - public string UserId { get; set; } = null!; + public required string UserId { get; set; } public DateTime OrderDate { get; set; } public decimal Amount { get; set; } public int Quantity { get; set; } @@ -10,18 +10,17 @@ public class Order : EntityBase public Guid? ProductVariantId { get; set; } public int OrderStatusId { get; set; } public int ShippingStatusId { get; set; } - public string OrderNumber { get; set; } = null!; public string? Notes { get; set; } public string? MerchantId { get; set; } - public string? ComposingImageUrl { get; set; } + public string? CustomizationImageUrl { get; set; } public string[] OriginalImageUrls { get; set; } = []; - public string CustomizationImageUrl { get; set; } = null!; - public string CustomizationDescription { get; set; } = null!; + public string? CustomizationDescription { get; set; } - public OrderStatus OrderStatus { get; set; } = null!; - public User User { get; set; } = null!; - public ShippingStatus ShippingStatus { get; set; } = null!; - public OrderAddress OrderAddress { get; set; } = null!; - public Product Product { get; set; } = null!; - public ProductVariant? ProductVariant { get; set; } + public virtual OrderStatus OrderStatus { get; set; } = null!; + public virtual User User { get; set; } = null!; + public virtual User? Merchant { get; set; } + public virtual ShippingStatus ShippingStatus { get; set; } = null!; + public virtual OrderAddress OrderAddress { get; set; } = null!; + public virtual Product Product { get; set; } = null!; + public virtual ProductVariant? ProductVariant { get; set; } } \ No newline at end of file diff --git a/src/Imprink.Domain/Entities/OrderAddress.cs b/src/Imprink.Domain/Entities/OrderAddress.cs index 944fe37..49fb270 100644 --- a/src/Imprink.Domain/Entities/OrderAddress.cs +++ b/src/Imprink.Domain/Entities/OrderAddress.cs @@ -18,6 +18,6 @@ public class OrderAddress : EntityBase public required string Country { get; set; } public string? PhoneNumber { get; set; } public string? Instructions { get; set; } - - public virtual required Order Order { get; set; } + + public virtual Order Order { get; set; } = null!; } \ No newline at end of file diff --git a/src/Imprink.Domain/Repositories/IAddressRepository.cs b/src/Imprink.Domain/Repositories/IAddressRepository.cs index 911061d..61267ce 100644 --- a/src/Imprink.Domain/Repositories/IAddressRepository.cs +++ b/src/Imprink.Domain/Repositories/IAddressRepository.cs @@ -6,7 +6,7 @@ public interface IAddressRepository { Task> GetByUserIdAsync(string userId, CancellationToken cancellationToken = default); Task> GetActiveByUserIdAsync(string userId, CancellationToken cancellationToken = default); - Task GetDefaultByUserIdAsync(string userId, CancellationToken cancellationToken = default); + Task GetDefaultByUserIdAsync(string? userId, CancellationToken cancellationToken = default); Task> GetByUserIdAndTypeAsync(string userId, string addressType, CancellationToken cancellationToken = default); Task GetByIdAsync(Guid id, CancellationToken cancellationToken = default); Task GetByIdAndUserIdAsync(Guid id, string userId, CancellationToken cancellationToken = default); @@ -14,7 +14,7 @@ public interface IAddressRepository Task
UpdateAsync(Address address, CancellationToken cancellationToken = default); Task DeleteAsync(Guid id, CancellationToken cancellationToken = default); Task DeleteByUserIdAsync(Guid id, string userId, CancellationToken cancellationToken = default); - Task SetDefaultAddressAsync(string userId, Guid addressId, CancellationToken cancellationToken = default); + Task SetDefaultAddressAsync(string? userId, Guid addressId, CancellationToken cancellationToken = default); Task DeactivateAddressAsync(Guid addressId, CancellationToken cancellationToken = default); Task ActivateAddressAsync(Guid addressId, CancellationToken cancellationToken = default); Task ExistsAsync(Guid id, CancellationToken cancellationToken = default); diff --git a/src/Imprink.Domain/Repositories/IOrderRepository.cs b/src/Imprink.Domain/Repositories/IOrderRepository.cs index d5a95fb..01e7276 100644 --- a/src/Imprink.Domain/Repositories/IOrderRepository.cs +++ b/src/Imprink.Domain/Repositories/IOrderRepository.cs @@ -7,7 +7,6 @@ public interface IOrderRepository { Task GetByIdAsync(Guid id, CancellationToken cancellationToken = default); Task GetByIdWithDetailsAsync(Guid id, CancellationToken cancellationToken = default); - Task GetByOrderNumberAsync(string orderNumber, CancellationToken cancellationToken = default); Task> GetByUserIdAsync(string userId, CancellationToken cancellationToken = default); Task> GetByUserIdWithDetailsAsync(string userId, CancellationToken cancellationToken = default); Task> GetByMerchantIdAsync(string merchantId, CancellationToken cancellationToken = default); @@ -19,9 +18,6 @@ public interface IOrderRepository Task UpdateAsync(Order order, CancellationToken cancellationToken = default); Task DeleteAsync(Guid id, CancellationToken cancellationToken = default); Task ExistsAsync(Guid id, CancellationToken cancellationToken = default); - Task IsOrderNumberUniqueAsync(string orderNumber, CancellationToken cancellationToken = default); - Task IsOrderNumberUniqueAsync(string orderNumber, Guid excludeOrderId, CancellationToken cancellationToken = default); - Task GenerateOrderNumberAsync(CancellationToken cancellationToken = default); Task UpdateStatusAsync(Guid orderId, int statusId, CancellationToken cancellationToken = default); Task UpdateShippingStatusAsync(Guid orderId, int shippingStatusId, CancellationToken cancellationToken = default); Task AssignMerchantAsync(Guid orderId, string merchantId, CancellationToken cancellationToken = default); diff --git a/src/Imprink.Infrastructure/Configuration/AddressConfiguration.cs b/src/Imprink.Infrastructure/Configuration/AddressConfiguration.cs index 6a1bcce..be115a3 100644 --- a/src/Imprink.Infrastructure/Configuration/AddressConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/AddressConfiguration.cs @@ -75,7 +75,6 @@ public class AddressConfiguration : EntityBaseConfiguration
builder.HasOne(a => a.User) .WithMany(u => u.Addresses) .HasForeignKey(a => a.UserId) - .HasPrincipalKey(u => u.Id) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(a => a.UserId) @@ -87,4 +86,4 @@ public class AddressConfiguration : EntityBaseConfiguration
builder.HasIndex(a => new { a.UserId, a.IsDefault }) .HasDatabaseName("IX_Address_User_Default"); } -} +} \ No newline at end of file diff --git a/src/Imprink.Infrastructure/EntityBaseConfiguration.cs b/src/Imprink.Infrastructure/Configuration/EntityBaseConfiguration.cs similarity index 84% rename from src/Imprink.Infrastructure/EntityBaseConfiguration.cs rename to src/Imprink.Infrastructure/Configuration/EntityBaseConfiguration.cs index 4e4f717..30f376e 100644 --- a/src/Imprink.Infrastructure/EntityBaseConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/EntityBaseConfiguration.cs @@ -2,7 +2,7 @@ using Imprink.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Imprink.Infrastructure; +namespace Imprink.Infrastructure.Configuration; public class EntityBaseConfiguration : IEntityTypeConfiguration where T : EntityBase { @@ -12,20 +12,16 @@ public class EntityBaseConfiguration : IEntityTypeConfiguration where T : builder.Property(e => e.Id) .HasDefaultValueSql("NEWID()"); - - builder.Property(e => e.CreatedAt) - .IsRequired(); + + builder.Property(e => e.CreatedAt); builder.Property(e => e.ModifiedAt) - .IsRequired() .HasDefaultValueSql("GETUTCDATE()"); builder.Property(e => e.CreatedBy) - .IsRequired() .HasMaxLength(450); builder.Property(e => e.ModifiedBy) - .IsRequired() .HasMaxLength(450); builder.HasIndex(e => e.CreatedAt) diff --git a/src/Imprink.Infrastructure/Configuration/OrderConfiguration.cs b/src/Imprink.Infrastructure/Configuration/OrderConfiguration.cs index 0aebad5..1683554 100644 --- a/src/Imprink.Infrastructure/Configuration/OrderConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/OrderConfiguration.cs @@ -35,19 +35,12 @@ public class OrderConfiguration : EntityBaseConfiguration builder.Property(o => o.ShippingStatusId) .IsRequired(); - builder.Property(o => o.OrderNumber) - .IsRequired() - .HasMaxLength(50); - builder.Property(o => o.Notes) .HasMaxLength(1000); builder.Property(o => o.MerchantId) .HasMaxLength(450); - builder.Property(o => o.ComposingImageUrl) - .HasMaxLength(1000); - builder.Property(o => o.OriginalImageUrls) .HasConversion( v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null), @@ -55,11 +48,9 @@ public class OrderConfiguration : EntityBaseConfiguration .HasColumnType("nvarchar(max)"); builder.Property(o => o.CustomizationImageUrl) - .IsRequired() .HasMaxLength(1000); builder.Property(o => o.CustomizationDescription) - .IsRequired() .HasMaxLength(2000); builder.HasOne(o => o.OrderStatus) @@ -80,13 +71,11 @@ public class OrderConfiguration : EntityBaseConfiguration builder.HasOne(o => o.User) .WithMany(u => u.Orders) .HasForeignKey(o => o.UserId) - .HasPrincipalKey(u => u.Id) .OnDelete(DeleteBehavior.Restrict); - builder.HasOne() + builder.HasOne(o => o.Merchant) .WithMany(u => u.MerchantOrders) .HasForeignKey(o => o.MerchantId) - .HasPrincipalKey(u => u.Id) .OnDelete(DeleteBehavior.SetNull); builder.HasOne(o => o.Product) @@ -102,10 +91,6 @@ public class OrderConfiguration : EntityBaseConfiguration builder.HasIndex(o => o.UserId) .HasDatabaseName("IX_Order_UserId"); - builder.HasIndex(o => o.OrderNumber) - .IsUnique() - .HasDatabaseName("IX_Order_OrderNumber"); - builder.HasIndex(o => o.OrderDate) .HasDatabaseName("IX_Order_OrderDate"); @@ -133,4 +118,4 @@ public class OrderConfiguration : EntityBaseConfiguration builder.HasIndex(o => new { o.ProductId, o.OrderDate }) .HasDatabaseName("IX_Order_Product_Date"); } -} +} \ No newline at end of file diff --git a/src/Imprink.Infrastructure/Configuration/ProductConfiguration.cs b/src/Imprink.Infrastructure/Configuration/ProductConfiguration.cs index c0ef17f..31db7d8 100644 --- a/src/Imprink.Infrastructure/Configuration/ProductConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/ProductConfiguration.cs @@ -34,18 +34,6 @@ public class ProductConfiguration : EntityBaseConfiguration builder.Property(p => p.CategoryId) .IsRequired(false); - - builder.Property(c => c.CreatedAt) - .IsRequired(false); - - builder.Property(c => c.CreatedBy) - .IsRequired(false); - - builder.Property(c => c.ModifiedAt) - .IsRequired(false); - - builder.Property(c => c.ModifiedBy) - .IsRequired(false); builder.HasOne(p => p.Category) .WithMany(c => c.Products) diff --git a/src/Imprink.Infrastructure/Configuration/ProductVariantConfiguration.cs b/src/Imprink.Infrastructure/Configuration/ProductVariantConfiguration.cs index 2d323a1..89de1e3 100644 --- a/src/Imprink.Infrastructure/Configuration/ProductVariantConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/ProductVariantConfiguration.cs @@ -37,18 +37,6 @@ public class ProductVariantConfiguration : EntityBaseConfiguration pv.IsActive) .IsRequired() .HasDefaultValue(true); - - builder.Property(c => c.CreatedAt) - .IsRequired(false); - - builder.Property(c => c.CreatedBy) - .IsRequired(false); - - builder.Property(c => c.ModifiedAt) - .IsRequired(false); - - builder.Property(c => c.ModifiedBy) - .IsRequired(false); builder.HasOne(pv => pv.Product) .WithMany(p => p.ProductVariants) diff --git a/src/Imprink.Infrastructure/Configuration/UserConfiguration.cs b/src/Imprink.Infrastructure/Configuration/UserConfiguration.cs index 3725f6c..42f4a54 100644 --- a/src/Imprink.Infrastructure/Configuration/UserConfiguration.cs +++ b/src/Imprink.Infrastructure/Configuration/UserConfiguration.cs @@ -8,6 +8,8 @@ public class UserConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { + builder.HasKey(u => u.Id); + builder.Property(u => u.Id) .HasMaxLength(450) .ValueGeneratedNever(); @@ -47,12 +49,6 @@ public class UserConfiguration : IEntityTypeConfiguration builder.HasIndex(u => u.IsActive) .HasDatabaseName("IX_User_IsActive"); - builder.HasMany(u => u.Addresses) - .WithOne() - .HasForeignKey(a => a.UserId) - .HasPrincipalKey(u => u.Id) - .OnDelete(DeleteBehavior.Cascade); - builder.Ignore(u => u.DefaultAddress); builder.Ignore(u => u.Roles); } diff --git a/src/Imprink.Infrastructure/Migrations/20250617163555_InitialSetup.Designer.cs b/src/Imprink.Infrastructure/Migrations/20250625211612_InitialSetup.Designer.cs similarity index 81% rename from src/Imprink.Infrastructure/Migrations/20250617163555_InitialSetup.Designer.cs rename to src/Imprink.Infrastructure/Migrations/20250625211612_InitialSetup.Designer.cs index 18e4c1b..65b0a44 100644 --- a/src/Imprink.Infrastructure/Migrations/20250617163555_InitialSetup.Designer.cs +++ b/src/Imprink.Infrastructure/Migrations/20250625211612_InitialSetup.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Imprink.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20250617163555_InitialSetup")] + [Migration("20250625211612_InitialSetup")] partial class InitialSetup { /// @@ -25,128 +25,94 @@ namespace Imprink.Infrastructure.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => + modelBuilder.Entity("Imprink.Domain.Entities.Address", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier") .HasDefaultValueSql("NEWID()"); - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") + b.Property("AddressLine1") .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); + b.Property("AddressLine2") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); - 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") + b.Property("AddressType") .IsRequired() .HasMaxLength(50) .HasColumnType("nvarchar(50)"); - b.Property("OrderStatusId") - .HasColumnType("int"); + b.Property("ApartmentNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); - 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("BuildingNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); b.Property("City") .IsRequired() .HasMaxLength(100) .HasColumnType("nvarchar(100)"); + b.Property("Company") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + b.Property("Country") .IsRequired() .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("CreatedAt") + b.Property("CreatedAt") .HasColumnType("datetime2"); b.Property("CreatedBy") - .IsRequired() .HasMaxLength(450) .HasColumnType("nvarchar(450)"); - b.Property("ModifiedAt") + b.Property("FirstName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Floor") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("Instructions") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(true); + + b.Property("IsDefault") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(false); + + b.Property("LastName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ModifiedAt") .ValueGeneratedOnAdd() .HasColumnType("datetime2") .HasDefaultValueSql("GETUTCDATE()"); b.Property("ModifiedBy") - .IsRequired() .HasMaxLength(450) .HasColumnType("nvarchar(450)"); - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); + b.Property("PhoneNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); b.Property("PostalCode") .IsRequired() @@ -158,193 +124,35 @@ namespace Imprink.Infrastructure.Migrations .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") + b.Property("UserId") .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"); + .HasDatabaseName("IX_Address_CreatedAt"); b.HasIndex("CreatedBy") - .HasDatabaseName("IX_OrderItem_CreatedBy"); + .HasDatabaseName("IX_Address_CreatedBy"); b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_OrderItem_ModifiedAt"); + .HasDatabaseName("IX_Address_ModifiedAt"); - b.HasIndex("OrderId") - .HasDatabaseName("IX_OrderItem_OrderId"); + b.HasIndex("UserId") + .HasDatabaseName("IX_Address_UserId"); - b.HasIndex("ProductId") - .HasDatabaseName("IX_OrderItem_ProductId"); + b.HasIndex("UserId", "AddressType") + .HasDatabaseName("IX_Address_User_Type"); - b.HasIndex("ProductVariantId") - .HasDatabaseName("IX_OrderItem_ProductVariantId"); + b.HasIndex("UserId", "IsDefault") + .HasDatabaseName("IX_Address_User_Default"); - b.HasIndex("OrderId", "ProductId") - .HasDatabaseName("IX_OrderItem_Order_Product"); - - b.ToTable("OrderItems"); + b.ToTable("Addresses"); }); - 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 => + modelBuilder.Entity("Imprink.Domain.Entities.Category", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -461,7 +269,273 @@ namespace Imprink.Infrastructure.Migrations }); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => + modelBuilder.Entity("Imprink.Domain.Entities.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWID()"); + + b.Property("Amount") + .HasColumnType("decimal(18,2)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("CustomizationDescription") + .HasMaxLength(2000) + .HasColumnType("nvarchar(2000)"); + + b.Property("CustomizationImageUrl") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("MerchantId") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("ModifiedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("Notes") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderStatusId") + .HasColumnType("int"); + + b.Property("OriginalImageUrls") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("ProductVariantId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(1); + + b.Property("ShippingStatusId") + .HasColumnType("int"); + + 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("MerchantId") + .HasDatabaseName("IX_Order_MerchantId"); + + b.HasIndex("ModifiedAt") + .HasDatabaseName("IX_Order_ModifiedAt"); + + b.HasIndex("OrderDate") + .HasDatabaseName("IX_Order_OrderDate"); + + b.HasIndex("OrderStatusId") + .HasDatabaseName("IX_Order_OrderStatusId"); + + b.HasIndex("ProductId") + .HasDatabaseName("IX_Order_ProductId"); + + b.HasIndex("ProductVariantId") + .HasDatabaseName("IX_Order_ProductVariantId"); + + b.HasIndex("ShippingStatusId") + .HasDatabaseName("IX_Order_ShippingStatusId"); + + b.HasIndex("UserId") + .HasDatabaseName("IX_Order_UserId"); + + b.HasIndex("MerchantId", "OrderDate") + .HasDatabaseName("IX_Order_Merchant_Date"); + + b.HasIndex("ProductId", "OrderDate") + .HasDatabaseName("IX_Order_Product_Date"); + + b.HasIndex("UserId", "OrderDate") + .HasDatabaseName("IX_Order_User_Date"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.OrderAddress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWID()"); + + b.Property("AddressLine1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("AddressLine2") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("AddressType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("ApartmentNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("BuildingNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("City") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Company") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Country") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("FirstName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Floor") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("Instructions") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("LastName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("ModifiedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b.Property("PhoneNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("PostalCode") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("State") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + 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.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.Product", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -545,7 +619,7 @@ namespace Imprink.Infrastructure.Migrations b.ToTable("Products"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => + modelBuilder.Entity("Imprink.Domain.Entities.ProductVariant", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -631,100 +705,7 @@ namespace Imprink.Infrastructure.Migrations 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 => + modelBuilder.Entity("Imprink.Domain.Entities.Role", b => { b.Property("Id") .HasColumnType("uniqueidentifier"); @@ -755,7 +736,48 @@ namespace Imprink.Infrastructure.Migrations }); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => + modelBuilder.Entity("Imprink.Domain.Entities.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.User", b => { b.Property("Id") .HasMaxLength(450) @@ -767,7 +789,6 @@ namespace Imprink.Infrastructure.Migrations .HasColumnType("nvarchar(256)"); b.Property("EmailVerified") - .HasMaxLength(100) .HasColumnType("bit"); b.Property("FirstName") @@ -809,7 +830,7 @@ namespace Imprink.Infrastructure.Migrations b.ToTable("Users"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.UserRole", b => + modelBuilder.Entity("Imprink.Domain.Entities.UserRole", b => { b.Property("UserId") .HasMaxLength(450) @@ -829,73 +850,20 @@ namespace Imprink.Infrastructure.Migrations b.ToTable("UserRole"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => + modelBuilder.Entity("Imprink.Domain.Entities.Address", 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") + b.HasOne("Imprink.Domain.Entities.User", "User") + .WithMany("Addresses") .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("OrderStatus"); - - b.Navigation("ShippingStatus"); - b.Navigation("User"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderAddress", b => + modelBuilder.Entity("Imprink.Domain.Entities.Category", 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") + b.HasOne("Imprink.Domain.Entities.Category", "ParentCategory") .WithMany("SubCategories") .HasForeignKey("ParentCategoryId") .OnDelete(DeleteBehavior.Restrict); @@ -903,9 +871,69 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("ParentCategory"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => + modelBuilder.Entity("Imprink.Domain.Entities.Order", b => { - b.HasOne("Imprink.Domain.Entities.Product.Category", "Category") + b.HasOne("Imprink.Domain.Entities.User", "Merchant") + .WithMany("MerchantOrders") + .HasForeignKey("MerchantId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Imprink.Domain.Entities.OrderStatus", "OrderStatus") + .WithMany("Orders") + .HasForeignKey("OrderStatusId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Imprink.Domain.Entities.Product", "Product") + .WithMany("Orders") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Imprink.Domain.Entities.ProductVariant", "ProductVariant") + .WithMany("Orders") + .HasForeignKey("ProductVariantId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Imprink.Domain.Entities.ShippingStatus", "ShippingStatus") + .WithMany("Orders") + .HasForeignKey("ShippingStatusId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Imprink.Domain.Entities.User", "User") + .WithMany("Orders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Merchant"); + + b.Navigation("OrderStatus"); + + b.Navigation("Product"); + + b.Navigation("ProductVariant"); + + b.Navigation("ShippingStatus"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.OrderAddress", b => + { + b.HasOne("Imprink.Domain.Entities.Order", "Order") + .WithOne("OrderAddress") + .HasForeignKey("Imprink.Domain.Entities.OrderAddress", "OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.Product", b => + { + b.HasOne("Imprink.Domain.Entities.Category", "Category") .WithMany("Products") .HasForeignKey("CategoryId") .OnDelete(DeleteBehavior.SetNull); @@ -913,9 +941,9 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("Category"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => + modelBuilder.Entity("Imprink.Domain.Entities.ProductVariant", b => { - b.HasOne("Imprink.Domain.Entities.Product.Product", "Product") + b.HasOne("Imprink.Domain.Entities.Product", "Product") .WithMany("ProductVariants") .HasForeignKey("ProductId") .OnDelete(DeleteBehavior.Cascade) @@ -924,24 +952,15 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("Product"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.Address", b => + modelBuilder.Entity("Imprink.Domain.Entities.UserRole", 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") + b.HasOne("Imprink.Domain.Entities.Role", "Role") .WithMany("UserRoles") .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Restrict) .IsRequired(); - b.HasOne("Imprink.Domain.Entities.Users.User", "User") + b.HasOne("Imprink.Domain.Entities.User", "User") .WithMany("UserRoles") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) @@ -952,52 +971,52 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("User"); }); - 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 => + modelBuilder.Entity("Imprink.Domain.Entities.Category", b => { b.Navigation("Products"); b.Navigation("SubCategories"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => + modelBuilder.Entity("Imprink.Domain.Entities.Order", b => { - b.Navigation("OrderItems"); + b.Navigation("OrderAddress") + .IsRequired(); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.OrderStatus", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.Product", b => + { + b.Navigation("Orders"); b.Navigation("ProductVariants"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => + modelBuilder.Entity("Imprink.Domain.Entities.ProductVariant", b => { - b.Navigation("OrderItems"); + b.Navigation("Orders"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.Role", b => + modelBuilder.Entity("Imprink.Domain.Entities.Role", b => { b.Navigation("UserRoles"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => + modelBuilder.Entity("Imprink.Domain.Entities.ShippingStatus", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.User", b => { b.Navigation("Addresses"); + b.Navigation("MerchantOrders"); + b.Navigation("Orders"); b.Navigation("UserRoles"); diff --git a/src/Imprink.Infrastructure/Migrations/20250617163555_InitialSetup.cs b/src/Imprink.Infrastructure/Migrations/20250625211612_InitialSetup.cs similarity index 87% rename from src/Imprink.Infrastructure/Migrations/20250617163555_InitialSetup.cs rename to src/Imprink.Infrastructure/Migrations/20250625211612_InitialSetup.cs index 30c801b..9606a5c 100644 --- a/src/Imprink.Infrastructure/Migrations/20250617163555_InitialSetup.cs +++ b/src/Imprink.Infrastructure/Migrations/20250625211612_InitialSetup.cs @@ -84,7 +84,7 @@ namespace Imprink.Infrastructure.Migrations Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Nickname = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), - EmailVerified = table.Column(type: "bit", maxLength: 100, nullable: false), + EmailVerified = table.Column(type: "bit", nullable: false), FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), PhoneNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), @@ -130,17 +130,26 @@ namespace Imprink.Infrastructure.Migrations 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), + FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), + LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), + Company = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + AddressLine1 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + AddressLine2 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + ApartmentNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + BuildingNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Floor = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), 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), + PhoneNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Instructions = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), 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) + CreatedAt = table.Column(type: "datetime2", nullable: true), + ModifiedAt = table.Column(type: "datetime2", nullable: true, defaultValueSql: "GETUTCDATE()"), + CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true) }, constraints: table => { @@ -153,46 +162,6 @@ namespace Imprink.Infrastructure.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), - UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), - OrderDate = table.Column(type: "datetime2", nullable: false), - TotalPrice = table.Column(type: "decimal(18,2)", nullable: false), - OrderStatusId = table.Column(type: "int", nullable: false), - ShippingStatusId = table.Column(type: "int", nullable: false), - OrderNumber = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), - Notes = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: false), - 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_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_OrderStatuses_OrderStatusId", - column: x => x.OrderStatusId, - principalTable: "OrderStatuses", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Orders_ShippingStatuses_ShippingStatusId", - column: x => x.ShippingStatusId, - 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: "UserRole", columns: table => new @@ -246,21 +215,95 @@ namespace Imprink.Infrastructure.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), + UserId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), + OrderDate = table.Column(type: "datetime2", nullable: false), + Amount = table.Column(type: "decimal(18,2)", nullable: false), + Quantity = table.Column(type: "int", nullable: false, defaultValue: 1), + ProductId = table.Column(type: "uniqueidentifier", nullable: false), + ProductVariantId = table.Column(type: "uniqueidentifier", nullable: true), + OrderStatusId = table.Column(type: "int", nullable: false), + ShippingStatusId = table.Column(type: "int", nullable: false), + Notes = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: true), + MerchantId = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + CustomizationImageUrl = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: true), + OriginalImageUrls = table.Column(type: "nvarchar(max)", nullable: false), + CustomizationDescription = table.Column(type: "nvarchar(2000)", maxLength: 2000, nullable: true), + CreatedAt = table.Column(type: "datetime2", nullable: true), + ModifiedAt = table.Column(type: "datetime2", nullable: true, defaultValueSql: "GETUTCDATE()"), + CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_OrderStatuses_OrderStatusId", + column: x => x.OrderStatusId, + principalTable: "OrderStatuses", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Orders_ProductVariants_ProductVariantId", + column: x => x.ProductVariantId, + principalTable: "ProductVariants", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Orders_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Orders_ShippingStatuses_ShippingStatusId", + column: x => x.ShippingStatusId, + principalTable: "ShippingStatuses", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Orders_Users_MerchantId", + column: x => x.MerchantId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + table.ForeignKey( + name: "FK_Orders_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "OrderAddresses", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), OrderId = table.Column(type: "uniqueidentifier", nullable: false), - Street = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + AddressType = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + FirstName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), + LastName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), + Company = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + AddressLine1 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + AddressLine2 = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + ApartmentNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + BuildingNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Floor = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), 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), - 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) + PhoneNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Instructions = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), + CreatedAt = table.Column(type: "datetime2", nullable: true), + ModifiedAt = table.Column(type: "datetime2", nullable: true, defaultValueSql: "GETUTCDATE()"), + CreatedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true), + ModifiedBy = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: true) }, constraints: table => { @@ -273,47 +316,6 @@ namespace Imprink.Infrastructure.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "OrderItems", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"), - OrderId = table.Column(type: "uniqueidentifier", nullable: false), - ProductId = table.Column(type: "uniqueidentifier", nullable: false), - ProductVariantId = table.Column(type: "uniqueidentifier", nullable: true), - Quantity = table.Column(type: "int", nullable: false, defaultValue: 1), - UnitPrice = table.Column(type: "decimal(18,2)", nullable: false), - TotalPrice = table.Column(type: "decimal(18,2)", nullable: false), - CustomizationImageUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), - CustomizationDescription = table.Column(type: "nvarchar(2000)", maxLength: 2000, nullable: false), - 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_OrderItems", x => x.Id); - table.ForeignKey( - name: "FK_OrderItems_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_OrderItems_ProductVariants_ProductVariantId", - column: x => x.ProductVariantId, - principalTable: "ProductVariants", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_OrderItems_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - migrationBuilder.InsertData( table: "Categories", columns: new[] { "Id", "CreatedAt", "CreatedBy", "Description", "ImageUrl", "IsActive", "ModifiedAt", "ModifiedBy", "Name", "ParentCategoryId", "SortOrder" }, @@ -446,41 +448,6 @@ namespace Imprink.Infrastructure.Migrations column: "OrderId", unique: true); - migrationBuilder.CreateIndex( - name: "IX_OrderItem_CreatedAt", - table: "OrderItems", - column: "CreatedAt"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItem_CreatedBy", - table: "OrderItems", - column: "CreatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItem_ModifiedAt", - table: "OrderItems", - column: "ModifiedAt"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItem_Order_Product", - table: "OrderItems", - columns: new[] { "OrderId", "ProductId" }); - - migrationBuilder.CreateIndex( - name: "IX_OrderItem_OrderId", - table: "OrderItems", - column: "OrderId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItem_ProductId", - table: "OrderItems", - column: "ProductId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItem_ProductVariantId", - table: "OrderItems", - column: "ProductVariantId"); - migrationBuilder.CreateIndex( name: "IX_Order_CreatedAt", table: "Orders", @@ -491,6 +458,16 @@ namespace Imprink.Infrastructure.Migrations table: "Orders", column: "CreatedBy"); + migrationBuilder.CreateIndex( + name: "IX_Order_Merchant_Date", + table: "Orders", + columns: new[] { "MerchantId", "OrderDate" }); + + migrationBuilder.CreateIndex( + name: "IX_Order_MerchantId", + table: "Orders", + column: "MerchantId"); + migrationBuilder.CreateIndex( name: "IX_Order_ModifiedAt", table: "Orders", @@ -501,17 +478,26 @@ namespace Imprink.Infrastructure.Migrations table: "Orders", column: "OrderDate"); - migrationBuilder.CreateIndex( - name: "IX_Order_OrderNumber", - table: "Orders", - column: "OrderNumber", - unique: true); - migrationBuilder.CreateIndex( name: "IX_Order_OrderStatusId", table: "Orders", column: "OrderStatusId"); + migrationBuilder.CreateIndex( + name: "IX_Order_Product_Date", + table: "Orders", + columns: new[] { "ProductId", "OrderDate" }); + + migrationBuilder.CreateIndex( + name: "IX_Order_ProductId", + table: "Orders", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_Order_ProductVariantId", + table: "Orders", + column: "ProductVariantId"); + migrationBuilder.CreateIndex( name: "IX_Order_ShippingStatusId", table: "Orders", @@ -659,24 +645,21 @@ namespace Imprink.Infrastructure.Migrations migrationBuilder.DropTable( name: "OrderAddresses"); - migrationBuilder.DropTable( - name: "OrderItems"); - migrationBuilder.DropTable( name: "UserRole"); migrationBuilder.DropTable( name: "Orders"); - migrationBuilder.DropTable( - name: "ProductVariants"); - migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "OrderStatuses"); + migrationBuilder.DropTable( + name: "ProductVariants"); + migrationBuilder.DropTable( name: "ShippingStatuses"); diff --git a/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs index 1195e8b..9d264b9 100644 --- a/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/Imprink.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -22,128 +22,94 @@ namespace Imprink.Infrastructure.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => + modelBuilder.Entity("Imprink.Domain.Entities.Address", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier") .HasDefaultValueSql("NEWID()"); - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") + b.Property("AddressLine1") .IsRequired() - .HasMaxLength(450) - .HasColumnType("nvarchar(450)"); + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); - b.Property("ModifiedAt") - .ValueGeneratedOnAdd() - .HasColumnType("datetime2") - .HasDefaultValueSql("GETUTCDATE()"); + b.Property("AddressLine2") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); - 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") + b.Property("AddressType") .IsRequired() .HasMaxLength(50) .HasColumnType("nvarchar(50)"); - b.Property("OrderStatusId") - .HasColumnType("int"); + b.Property("ApartmentNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); - 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("BuildingNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); b.Property("City") .IsRequired() .HasMaxLength(100) .HasColumnType("nvarchar(100)"); + b.Property("Company") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + b.Property("Country") .IsRequired() .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("CreatedAt") + b.Property("CreatedAt") .HasColumnType("datetime2"); b.Property("CreatedBy") - .IsRequired() .HasMaxLength(450) .HasColumnType("nvarchar(450)"); - b.Property("ModifiedAt") + b.Property("FirstName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Floor") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("Instructions") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(true); + + b.Property("IsDefault") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(false); + + b.Property("LastName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ModifiedAt") .ValueGeneratedOnAdd() .HasColumnType("datetime2") .HasDefaultValueSql("GETUTCDATE()"); b.Property("ModifiedBy") - .IsRequired() .HasMaxLength(450) .HasColumnType("nvarchar(450)"); - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); + b.Property("PhoneNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); b.Property("PostalCode") .IsRequired() @@ -155,193 +121,35 @@ namespace Imprink.Infrastructure.Migrations .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") + b.Property("UserId") .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"); + .HasDatabaseName("IX_Address_CreatedAt"); b.HasIndex("CreatedBy") - .HasDatabaseName("IX_OrderItem_CreatedBy"); + .HasDatabaseName("IX_Address_CreatedBy"); b.HasIndex("ModifiedAt") - .HasDatabaseName("IX_OrderItem_ModifiedAt"); + .HasDatabaseName("IX_Address_ModifiedAt"); - b.HasIndex("OrderId") - .HasDatabaseName("IX_OrderItem_OrderId"); + b.HasIndex("UserId") + .HasDatabaseName("IX_Address_UserId"); - b.HasIndex("ProductId") - .HasDatabaseName("IX_OrderItem_ProductId"); + b.HasIndex("UserId", "AddressType") + .HasDatabaseName("IX_Address_User_Type"); - b.HasIndex("ProductVariantId") - .HasDatabaseName("IX_OrderItem_ProductVariantId"); + b.HasIndex("UserId", "IsDefault") + .HasDatabaseName("IX_Address_User_Default"); - b.HasIndex("OrderId", "ProductId") - .HasDatabaseName("IX_OrderItem_Order_Product"); - - b.ToTable("OrderItems"); + b.ToTable("Addresses"); }); - 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 => + modelBuilder.Entity("Imprink.Domain.Entities.Category", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -458,7 +266,273 @@ namespace Imprink.Infrastructure.Migrations }); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => + modelBuilder.Entity("Imprink.Domain.Entities.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWID()"); + + b.Property("Amount") + .HasColumnType("decimal(18,2)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("CustomizationDescription") + .HasMaxLength(2000) + .HasColumnType("nvarchar(2000)"); + + b.Property("CustomizationImageUrl") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("MerchantId") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("ModifiedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("Notes") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("OrderDate") + .HasColumnType("datetime2"); + + b.Property("OrderStatusId") + .HasColumnType("int"); + + b.Property("OriginalImageUrls") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("ProductVariantId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(1); + + b.Property("ShippingStatusId") + .HasColumnType("int"); + + 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("MerchantId") + .HasDatabaseName("IX_Order_MerchantId"); + + b.HasIndex("ModifiedAt") + .HasDatabaseName("IX_Order_ModifiedAt"); + + b.HasIndex("OrderDate") + .HasDatabaseName("IX_Order_OrderDate"); + + b.HasIndex("OrderStatusId") + .HasDatabaseName("IX_Order_OrderStatusId"); + + b.HasIndex("ProductId") + .HasDatabaseName("IX_Order_ProductId"); + + b.HasIndex("ProductVariantId") + .HasDatabaseName("IX_Order_ProductVariantId"); + + b.HasIndex("ShippingStatusId") + .HasDatabaseName("IX_Order_ShippingStatusId"); + + b.HasIndex("UserId") + .HasDatabaseName("IX_Order_UserId"); + + b.HasIndex("MerchantId", "OrderDate") + .HasDatabaseName("IX_Order_Merchant_Date"); + + b.HasIndex("ProductId", "OrderDate") + .HasDatabaseName("IX_Order_Product_Date"); + + b.HasIndex("UserId", "OrderDate") + .HasDatabaseName("IX_Order_User_Date"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.OrderAddress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWID()"); + + b.Property("AddressLine1") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("AddressLine2") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("AddressType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("ApartmentNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("BuildingNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("City") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Company") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Country") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("FirstName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Floor") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("Instructions") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("LastName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ModifiedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("ModifiedBy") + .HasMaxLength(450) + .HasColumnType("nvarchar(450)"); + + b.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b.Property("PhoneNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("PostalCode") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("State") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + 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.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.Product", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -542,7 +616,7 @@ namespace Imprink.Infrastructure.Migrations b.ToTable("Products"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => + modelBuilder.Entity("Imprink.Domain.Entities.ProductVariant", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -628,100 +702,7 @@ namespace Imprink.Infrastructure.Migrations 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 => + modelBuilder.Entity("Imprink.Domain.Entities.Role", b => { b.Property("Id") .HasColumnType("uniqueidentifier"); @@ -752,7 +733,48 @@ namespace Imprink.Infrastructure.Migrations }); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => + modelBuilder.Entity("Imprink.Domain.Entities.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.User", b => { b.Property("Id") .HasMaxLength(450) @@ -764,7 +786,6 @@ namespace Imprink.Infrastructure.Migrations .HasColumnType("nvarchar(256)"); b.Property("EmailVerified") - .HasMaxLength(100) .HasColumnType("bit"); b.Property("FirstName") @@ -806,7 +827,7 @@ namespace Imprink.Infrastructure.Migrations b.ToTable("Users"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.UserRole", b => + modelBuilder.Entity("Imprink.Domain.Entities.UserRole", b => { b.Property("UserId") .HasMaxLength(450) @@ -826,73 +847,20 @@ namespace Imprink.Infrastructure.Migrations b.ToTable("UserRole"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Orders.Order", b => + modelBuilder.Entity("Imprink.Domain.Entities.Address", 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") + b.HasOne("Imprink.Domain.Entities.User", "User") + .WithMany("Addresses") .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("OrderStatus"); - - b.Navigation("ShippingStatus"); - b.Navigation("User"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Orders.OrderAddress", b => + modelBuilder.Entity("Imprink.Domain.Entities.Category", 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") + b.HasOne("Imprink.Domain.Entities.Category", "ParentCategory") .WithMany("SubCategories") .HasForeignKey("ParentCategoryId") .OnDelete(DeleteBehavior.Restrict); @@ -900,9 +868,69 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("ParentCategory"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => + modelBuilder.Entity("Imprink.Domain.Entities.Order", b => { - b.HasOne("Imprink.Domain.Entities.Product.Category", "Category") + b.HasOne("Imprink.Domain.Entities.User", "Merchant") + .WithMany("MerchantOrders") + .HasForeignKey("MerchantId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Imprink.Domain.Entities.OrderStatus", "OrderStatus") + .WithMany("Orders") + .HasForeignKey("OrderStatusId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Imprink.Domain.Entities.Product", "Product") + .WithMany("Orders") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Imprink.Domain.Entities.ProductVariant", "ProductVariant") + .WithMany("Orders") + .HasForeignKey("ProductVariantId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("Imprink.Domain.Entities.ShippingStatus", "ShippingStatus") + .WithMany("Orders") + .HasForeignKey("ShippingStatusId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Imprink.Domain.Entities.User", "User") + .WithMany("Orders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Merchant"); + + b.Navigation("OrderStatus"); + + b.Navigation("Product"); + + b.Navigation("ProductVariant"); + + b.Navigation("ShippingStatus"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.OrderAddress", b => + { + b.HasOne("Imprink.Domain.Entities.Order", "Order") + .WithOne("OrderAddress") + .HasForeignKey("Imprink.Domain.Entities.OrderAddress", "OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.Product", b => + { + b.HasOne("Imprink.Domain.Entities.Category", "Category") .WithMany("Products") .HasForeignKey("CategoryId") .OnDelete(DeleteBehavior.SetNull); @@ -910,9 +938,9 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("Category"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => + modelBuilder.Entity("Imprink.Domain.Entities.ProductVariant", b => { - b.HasOne("Imprink.Domain.Entities.Product.Product", "Product") + b.HasOne("Imprink.Domain.Entities.Product", "Product") .WithMany("ProductVariants") .HasForeignKey("ProductId") .OnDelete(DeleteBehavior.Cascade) @@ -921,24 +949,15 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("Product"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.Address", b => + modelBuilder.Entity("Imprink.Domain.Entities.UserRole", 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") + b.HasOne("Imprink.Domain.Entities.Role", "Role") .WithMany("UserRoles") .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Restrict) .IsRequired(); - b.HasOne("Imprink.Domain.Entities.Users.User", "User") + b.HasOne("Imprink.Domain.Entities.User", "User") .WithMany("UserRoles") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) @@ -949,52 +968,52 @@ namespace Imprink.Infrastructure.Migrations b.Navigation("User"); }); - 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 => + modelBuilder.Entity("Imprink.Domain.Entities.Category", b => { b.Navigation("Products"); b.Navigation("SubCategories"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.Product", b => + modelBuilder.Entity("Imprink.Domain.Entities.Order", b => { - b.Navigation("OrderItems"); + b.Navigation("OrderAddress") + .IsRequired(); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.OrderStatus", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.Product", b => + { + b.Navigation("Orders"); b.Navigation("ProductVariants"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Product.ProductVariant", b => + modelBuilder.Entity("Imprink.Domain.Entities.ProductVariant", b => { - b.Navigation("OrderItems"); + b.Navigation("Orders"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.Role", b => + modelBuilder.Entity("Imprink.Domain.Entities.Role", b => { b.Navigation("UserRoles"); }); - modelBuilder.Entity("Imprink.Domain.Entities.Users.User", b => + modelBuilder.Entity("Imprink.Domain.Entities.ShippingStatus", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("Imprink.Domain.Entities.User", b => { b.Navigation("Addresses"); + b.Navigation("MerchantOrders"); + b.Navigation("Orders"); b.Navigation("UserRoles"); diff --git a/src/Imprink.Infrastructure/Repositories/AddressRepository.cs b/src/Imprink.Infrastructure/Repositories/AddressRepository.cs index e30e420..10fb3e0 100644 --- a/src/Imprink.Infrastructure/Repositories/AddressRepository.cs +++ b/src/Imprink.Infrastructure/Repositories/AddressRepository.cs @@ -25,7 +25,7 @@ public class AddressRepository(ApplicationDbContext context) : IAddressRepositor .ToListAsync(cancellationToken); } - public async Task GetDefaultByUserIdAsync(string userId, CancellationToken cancellationToken = default) + public async Task GetDefaultByUserIdAsync(string? userId, CancellationToken cancellationToken = default) { return await context.Addresses .FirstOrDefaultAsync(a => a.UserId == userId && a.IsDefault && a.IsActive, cancellationToken); @@ -103,7 +103,7 @@ public class AddressRepository(ApplicationDbContext context) : IAddressRepositor return true; } - public async Task SetDefaultAddressAsync(string userId, Guid addressId, CancellationToken cancellationToken = default) + public async Task SetDefaultAddressAsync(string? userId, Guid addressId, CancellationToken cancellationToken = default) { await UnsetDefaultAddressesAsync(userId, cancellationToken); @@ -154,7 +154,7 @@ public class AddressRepository(ApplicationDbContext context) : IAddressRepositor .AnyAsync(a => a.Id == id && a.UserId == userId, cancellationToken); } - private async Task UnsetDefaultAddressesAsync(string userId, CancellationToken cancellationToken = default) + private async Task UnsetDefaultAddressesAsync(string? userId, CancellationToken cancellationToken = default) { var defaultAddresses = await context.Addresses .Where(a => a.UserId == userId && a.IsDefault) diff --git a/src/Imprink.Infrastructure/Repositories/OrderRepository.cs b/src/Imprink.Infrastructure/Repositories/OrderRepository.cs index 1a11f67..d8e00b7 100644 --- a/src/Imprink.Infrastructure/Repositories/OrderRepository.cs +++ b/src/Imprink.Infrastructure/Repositories/OrderRepository.cs @@ -25,12 +25,6 @@ public class OrderRepository(ApplicationDbContext context) : IOrderRepository .FirstOrDefaultAsync(o => o.Id == id, cancellationToken); } - public async Task GetByOrderNumberAsync(string orderNumber, CancellationToken cancellationToken = default) - { - return await context.Orders - .FirstOrDefaultAsync(o => o.OrderNumber == orderNumber, cancellationToken); - } - public async Task> GetByUserIdAsync(string userId, CancellationToken cancellationToken = default) { return await context.Orders @@ -134,37 +128,6 @@ public class OrderRepository(ApplicationDbContext context) : IOrderRepository .AnyAsync(o => o.Id == id, cancellationToken); } - public async Task IsOrderNumberUniqueAsync(string orderNumber, CancellationToken cancellationToken = default) - { - return !await context.Orders - .AnyAsync(o => o.OrderNumber == orderNumber, cancellationToken); - } - - public async Task IsOrderNumberUniqueAsync(string orderNumber, Guid excludeOrderId, CancellationToken cancellationToken = default) - { - return !await context.Orders - .AnyAsync(o => o.OrderNumber == orderNumber && o.Id != excludeOrderId, cancellationToken); - } - - public async Task GenerateOrderNumberAsync(CancellationToken cancellationToken = default) - { - string orderNumber; - bool isUnique; - - do - { - // Generate order number format: ORD-YYYYMMDD-XXXXXX (where X is random) - var datePart = DateTime.UtcNow.ToString("yyyyMMdd"); - var randomPart = Random.Shared.Next(100000, 999999).ToString(); - orderNumber = $"ORD-{datePart}-{randomPart}"; - - isUnique = await IsOrderNumberUniqueAsync(orderNumber, cancellationToken); - } - while (!isUnique); - - return orderNumber; - } - public async Task UpdateStatusAsync(Guid orderId, int statusId, CancellationToken cancellationToken = default) { var order = await context.Orders diff --git a/src/Imprink.Infrastructure/UnitOfWork.cs b/src/Imprink.Infrastructure/UnitOfWork.cs index 80e3472..3025afd 100644 --- a/src/Imprink.Infrastructure/UnitOfWork.cs +++ b/src/Imprink.Infrastructure/UnitOfWork.cs @@ -52,7 +52,6 @@ public class UnitOfWork( try { var result = await operation(); - await SaveAsync(cancellationToken); await CommitTransactionAsync(cancellationToken); return result; } @@ -69,7 +68,6 @@ public class UnitOfWork( try { await operation(); - await SaveAsync(cancellationToken); await CommitTransactionAsync(cancellationToken); } catch diff --git a/src/Imprink.WebApi/Controllers/AddressesController.cs b/src/Imprink.WebApi/Controllers/AddressesController.cs new file mode 100644 index 0000000..bac0cfb --- /dev/null +++ b/src/Imprink.WebApi/Controllers/AddressesController.cs @@ -0,0 +1,60 @@ +using Imprink.Application.Commands.Addresses; +using Imprink.Application.Dtos; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Imprink.WebApi.Controllers; + +[ApiController] +[Route("/api/addresses")] +public class AddressesController(IMediator mediator) : ControllerBase +{ + + [HttpGet("{id:guid}")] + [Authorize] + public async Task> GetAddressById( + Guid id, + [FromQuery] string? userId = null, + CancellationToken cancellationToken = default) + { + var result = await mediator.Send(new GetAddressByIdQuery + { + Id = id, + UserId = userId + }, cancellationToken); + + if (result == null) + return NotFound(); + + return Ok(result); + } + + [HttpGet("user/{userId}")] + [Authorize] + public async Task>> GetAddressesByUserId( + string userId, + [FromQuery] bool activeOnly = false, + [FromQuery] string? addressType = null, + CancellationToken cancellationToken = default) + { + var result = await mediator.Send(new GetAddressesByUserIdQuery + { + UserId = userId, + ActiveOnly = activeOnly, + AddressType = addressType + }, cancellationToken); + + return Ok(result); + } + + [HttpPost] + [Authorize] + public async Task> CreateAddress( + [FromBody] CreateAddressCommand command, + CancellationToken cancellationToken = default) + { + var result = await mediator.Send(command, cancellationToken); + return CreatedAtAction(nameof(GetAddressById), new { id = result.Id }, result); + } +} \ No newline at end of file diff --git a/src/Imprink.WebApi/Controllers/OrdersController.cs b/src/Imprink.WebApi/Controllers/OrdersController.cs new file mode 100644 index 0000000..da9366b --- /dev/null +++ b/src/Imprink.WebApi/Controllers/OrdersController.cs @@ -0,0 +1,74 @@ +using Imprink.Application.Commands.Orders; +using Imprink.Application.Dtos; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Imprink.WebApi.Controllers; + +[ApiController] +[Route("/api/orders")] +public class OrdersController(IMediator mediator) : ControllerBase +{ + + [HttpGet("{id:guid}")] + [Authorize] + public async Task> GetOrderById( + Guid id, + [FromQuery] bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var result = await mediator.Send(new GetOrderByIdQuery + { + Id = id, + IncludeDetails = includeDetails + }, cancellationToken); + + if (result == null) + return NotFound(); + + return Ok(result); + } + + [HttpGet("user/{userId}")] + [Authorize] + public async Task>> GetOrdersByUserId( + string userId, + [FromQuery] bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var result = await mediator.Send(new GetOrdersByUserIdQuery + { + UserId = userId, + IncludeDetails = includeDetails + }, cancellationToken); + + return Ok(result); + } + + [HttpGet("merchant/{merchantId}")] + [Authorize(Roles = "Admin,Merchant")] + public async Task>> GetOrdersByMerchantId( + string merchantId, + [FromQuery] bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var result = await mediator.Send(new GetOrdersByMerchantIdQuery + { + MerchantId = merchantId, + IncludeDetails = includeDetails + }, cancellationToken); + + return Ok(result); + } + + [HttpPost] + [Authorize] + public async Task> CreateOrder( + [FromBody] CreateOrderCommand command, + CancellationToken cancellationToken = default) + { + var result = await mediator.Send(command, cancellationToken); + return CreatedAtAction(nameof(GetOrderById), new { id = result.Id }, result); + } +} \ No newline at end of file