From 50a2a05cf84cb2b972bd4111d094c8743e919a6f Mon Sep 17 00:00:00 2001 From: kodoku-x Date: Sat, 20 Apr 2024 19:30:25 +0700 Subject: [PATCH] fixbug: checkout basket --- src/API/CleanArchitecture.Api/API.xml | 33 +- .../V1/{ => Baskets}/BasketController.cs | 8 +- .../V1/{ => Categories}/CategoryController.cs | 6 +- .../V1/{ => Orders}/OrderController.cs | 2 +- .../V1/{ => Products}/ProductController.cs | 4 +- .../CleanArchitecture.Application.csproj | 4 - .../CheckoutBasket/CheckoutCommandHandler.cs | 2 +- .../CheckoutBasket/CheckoutValidator.cs | 3 +- .../Models/Requests/UserInformationRequest.cs | 2 +- .../OrderCreatedDomainEventHandler.cs | 31 ++ .../Events/ProductUpdateDomainEventHandler.cs | 24 -- .../Orders/Events/OrderCreatedDomainEvent.cs | 5 + .../AggregatesModels/Orders/Order.cs | 8 +- .../Events/ProductUpdatedDomainEvent.cs | 5 - .../AggregatesModels/Products/Product.cs | 3 - .../Shared/UserInformation.cs | 6 +- .../Configurations/OrderConfiguration.cs | 2 +- ...l-UserInformation-171320042024.Designer.cs | 392 +++++++++++++++++ ...date-Model-UserInformation-171320042024.cs | 28 ++ ...l-UserInformation-182820042024.Designer.cs | 397 ++++++++++++++++++ ...date-Model-UserInformation-182820042024.cs | 30 ++ ...l-UserInformation-184720042024.Designer.cs | 392 +++++++++++++++++ ...date-Model-UserInformation-184720042024.cs | 30 ++ .../ApplicationDbContextModelSnapshot.cs | 8 +- 24 files changed, 1350 insertions(+), 75 deletions(-) rename src/API/CleanArchitecture.Api/Controllers/V1/{ => Baskets}/BasketController.cs (94%) rename src/API/CleanArchitecture.Api/Controllers/V1/{ => Categories}/CategoryController.cs (96%) rename src/API/CleanArchitecture.Api/Controllers/V1/{ => Orders}/OrderController.cs (94%) rename src/API/CleanArchitecture.Api/Controllers/V1/{ => Products}/ProductController.cs (97%) create mode 100644 src/Core/CleanArchitecture.Application/Features/V1/Orders/EventHandlers/OrderCreatedDomainEventHandler.cs delete mode 100644 src/Core/CleanArchitecture.Application/Features/V1/Products/Events/ProductUpdateDomainEventHandler.cs create mode 100644 src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Events/OrderCreatedDomainEvent.cs delete mode 100644 src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Events/ProductUpdatedDomainEvent.cs create mode 100644 src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.Designer.cs create mode 100644 src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.cs create mode 100644 src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.Designer.cs create mode 100644 src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.cs create mode 100644 src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.Designer.cs create mode 100644 src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.cs diff --git a/src/API/CleanArchitecture.Api/API.xml b/src/API/CleanArchitecture.Api/API.xml index fbe4c11..fed26c4 100644 --- a/src/API/CleanArchitecture.Api/API.xml +++ b/src/API/CleanArchitecture.Api/API.xml @@ -19,62 +19,61 @@ - + Get basket by user id - + Add product into basket - + Remove product item in basket - + Clear basket - - + Check out - + Get the paginated category list - + Get category by id - + Create category - + Update category @@ -82,49 +81,49 @@ - + Delete category - + Get orders by user id - + Get the paginated product list - + Get product by id - + Create product - + Update product - + Delete product diff --git a/src/API/CleanArchitecture.Api/Controllers/V1/BasketController.cs b/src/API/CleanArchitecture.Api/Controllers/V1/Baskets/BasketController.cs similarity index 94% rename from src/API/CleanArchitecture.Api/Controllers/V1/BasketController.cs rename to src/API/CleanArchitecture.Api/Controllers/V1/Baskets/BasketController.cs index f61e11b..eec628f 100644 --- a/src/API/CleanArchitecture.Api/Controllers/V1/BasketController.cs +++ b/src/API/CleanArchitecture.Api/Controllers/V1/Baskets/BasketController.cs @@ -10,7 +10,7 @@ using MediatR; using Microsoft.AspNetCore.Mvc; -namespace CleanArchitecture.Api.Controllers.V1 +namespace CleanArchitecture.Api.Controllers.V1.Baskets { [ApiVersion(1)] public class BasketController : BaseApiController @@ -86,6 +86,12 @@ public async Task ClearBasket() public async Task Checkout([FromBody] CheckoutCommand request) { var result = await Sender.Send(request); + + if (result.IsFailure) + { + throw new BadRequestException(new List { result.Error }); + } + return Ok(result); } } diff --git a/src/API/CleanArchitecture.Api/Controllers/V1/CategoryController.cs b/src/API/CleanArchitecture.Api/Controllers/V1/Categories/CategoryController.cs similarity index 96% rename from src/API/CleanArchitecture.Api/Controllers/V1/CategoryController.cs rename to src/API/CleanArchitecture.Api/Controllers/V1/Categories/CategoryController.cs index 08e3537..74e238e 100644 --- a/src/API/CleanArchitecture.Api/Controllers/V1/CategoryController.cs +++ b/src/API/CleanArchitecture.Api/Controllers/V1/Categories/CategoryController.cs @@ -12,7 +12,7 @@ using MediatR; using Microsoft.AspNetCore.Mvc; -namespace CleanArchitecture.Api.Controllers.V1; +namespace CleanArchitecture.Api.Controllers.V1.Categories; [ApiVersion(1)] public class CategoryController : BaseApiController @@ -46,7 +46,7 @@ public async Task GetCategoryById(Guid id) { Result result = await Sender.Send(new GetCategoryByIdQuery(id)); - if(result.IsFailure) + if (result.IsFailure) { throw new BadRequestException(new List { result.Error }); } @@ -79,7 +79,7 @@ public async Task CreateCategory([FromBody] CreateCategoryCommand [MustHavePermission(Action.Update, Resource.Categories)] public async Task UpdateCategory(Guid id, [FromBody] UpdateCategoryCommand request) { - if(request.Id != id) + if (request.Id != id) return BadRequest(); var result = await Sender.Send(request); diff --git a/src/API/CleanArchitecture.Api/Controllers/V1/OrderController.cs b/src/API/CleanArchitecture.Api/Controllers/V1/Orders/OrderController.cs similarity index 94% rename from src/API/CleanArchitecture.Api/Controllers/V1/OrderController.cs rename to src/API/CleanArchitecture.Api/Controllers/V1/Orders/OrderController.cs index 74457fc..20c7ff8 100644 --- a/src/API/CleanArchitecture.Api/Controllers/V1/OrderController.cs +++ b/src/API/CleanArchitecture.Api/Controllers/V1/Orders/OrderController.cs @@ -6,7 +6,7 @@ using MediatR; using Microsoft.AspNetCore.Mvc; -namespace CleanArchitecture.Api.Controllers.V1 +namespace CleanArchitecture.Api.Controllers.V1.Orders { [ApiVersion(1)] public class OrderController : BaseApiController diff --git a/src/API/CleanArchitecture.Api/Controllers/V1/ProductController.cs b/src/API/CleanArchitecture.Api/Controllers/V1/Products/ProductController.cs similarity index 97% rename from src/API/CleanArchitecture.Api/Controllers/V1/ProductController.cs rename to src/API/CleanArchitecture.Api/Controllers/V1/Products/ProductController.cs index cb93cc3..8e2f0f9 100644 --- a/src/API/CleanArchitecture.Api/Controllers/V1/ProductController.cs +++ b/src/API/CleanArchitecture.Api/Controllers/V1/Products/ProductController.cs @@ -12,7 +12,7 @@ using MediatR; using Microsoft.AspNetCore.Mvc; -namespace CleanArchitecture.Api.Controllers.V1; +namespace CleanArchitecture.Api.Controllers.V1.Products; [ApiVersion(1)] public class ProductController : BaseApiController @@ -85,7 +85,7 @@ public async Task UpdateProduct([FromBody] UpdateProductCommand r if (result.IsFailure) throw new BadRequestException(new List { result.Error }); - return CreatedAtAction(nameof(GetProductById), new { Id = result.Value}, result.Value); + return CreatedAtAction(nameof(GetProductById), new { Id = result.Value }, result.Value); } /// diff --git a/src/Core/CleanArchitecture.Application/CleanArchitecture.Application.csproj b/src/Core/CleanArchitecture.Application/CleanArchitecture.Application.csproj index aaee327..313fb82 100644 --- a/src/Core/CleanArchitecture.Application/CleanArchitecture.Application.csproj +++ b/src/Core/CleanArchitecture.Application/CleanArchitecture.Application.csproj @@ -17,10 +17,6 @@ - - - - diff --git a/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutCommandHandler.cs b/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutCommandHandler.cs index 4e41450..7ce0529 100644 --- a/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutCommandHandler.cs +++ b/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutCommandHandler.cs @@ -27,7 +27,7 @@ public async Task> Handle(CheckoutCommand request, CancellationToke Guid userId = _currentUser.GetUserId(); UserInformation userInfomation = new UserInformation( - request.UserInformation.UserName, + request.UserInformation.Name, new Phone(request.UserInformation.Phone), new Address(request.UserInformation.Address.Street, request.UserInformation.Address.City)); diff --git a/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutValidator.cs b/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutValidator.cs index 085dbf7..aa0b5db 100644 --- a/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutValidator.cs +++ b/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Commands/CheckoutBasket/CheckoutValidator.cs @@ -14,8 +14,7 @@ public CheckoutValidator() .NotEmpty() .NotNull().WithMessage("Phone number is required.") .MinimumLength(10).WithMessage("Phone number must not be less than 10 characters.") - .MaximumLength(20).WithMessage("Phone number must not exceed 50 characters.") - .Matches(new Regex(@"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}")).WithMessage("Phone number not valid"); + .MaximumLength(20).WithMessage("Phone number must not exceed 50 characters."); RuleFor(c => c.UserInformation.Address) .NotEmpty() diff --git a/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Models/Requests/UserInformationRequest.cs b/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Models/Requests/UserInformationRequest.cs index 9deda30..3e63731 100644 --- a/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Models/Requests/UserInformationRequest.cs +++ b/src/Core/CleanArchitecture.Application/Features/V1/Baskets/Models/Requests/UserInformationRequest.cs @@ -1,6 +1,6 @@ namespace CleanArchitecture.Application.Features.V1.Baskets.Models.Requests; public sealed record UserInformationRequest( - string UserName, + string Name, string Phone, AddressRequest Address); diff --git a/src/Core/CleanArchitecture.Application/Features/V1/Orders/EventHandlers/OrderCreatedDomainEventHandler.cs b/src/Core/CleanArchitecture.Application/Features/V1/Orders/EventHandlers/OrderCreatedDomainEventHandler.cs new file mode 100644 index 0000000..b288d36 --- /dev/null +++ b/src/Core/CleanArchitecture.Application/Features/V1/Orders/EventHandlers/OrderCreatedDomainEventHandler.cs @@ -0,0 +1,31 @@ +using CleanArchitecture.Application.Common.Email; +using CleanArchitecture.Application.Common.Messaging; +using CleanArchitecture.Application.Features.Identities.Users; +using CleanArchitecture.Domain.AggregatesModels.Orders.Events; + +namespace CleanArchitecture.Application.Features.V1.Orders.EventHandlers; + +public sealed class OrderCreatedDomainEventHandler : IDomainEventHandler +{ + private readonly IMailService _mailService; + private readonly IUserService _userService; + public OrderCreatedDomainEventHandler(IMailService mailService, IUserService userService) + { + _mailService = mailService ?? throw new ArgumentNullException(nameof(mailService)); + _userService = userService ?? throw new ArgumentNullException(nameof(userService)); + } + + public async Task Handle(OrderCreatedDomainEvent notification, CancellationToken cancellationToken) + { + var user = await _userService.GetAsync(notification.UserId, cancellationToken); + if (user is null) + return; + + var mail = new MailRequest(new List { + user.Email! }, + "Thank you for your purchase", + "Thank you for ordering. We received your order and will begin processing it soon!"); + + await _mailService.SendAsync(mail, cancellationToken); + } +} diff --git a/src/Core/CleanArchitecture.Application/Features/V1/Products/Events/ProductUpdateDomainEventHandler.cs b/src/Core/CleanArchitecture.Application/Features/V1/Products/Events/ProductUpdateDomainEventHandler.cs deleted file mode 100644 index 11bb008..0000000 --- a/src/Core/CleanArchitecture.Application/Features/V1/Products/Events/ProductUpdateDomainEventHandler.cs +++ /dev/null @@ -1,24 +0,0 @@ -using CleanArchitecture.Application.Common.Email; -using CleanArchitecture.Application.Common.Messaging; -using CleanArchitecture.Domain.AggregatesModels.Products.Events; - -namespace CleanArchitecture.Application.Features.V1.Products.Events; - -public sealed class ProductUpdateDomainEventHandler : IDomainEventHandler -{ - private readonly IMailService _mailService; - public ProductUpdateDomainEventHandler(IMailService mailService) - { - _mailService = mailService ?? throw new ArgumentNullException(nameof(mailService)); - } - - public async Task Handle(ProductUpdatedDomainEvent notification, CancellationToken cancellationToken) - { - var mail = new MailRequest(new List { - "nguyenminhdat0802@gmail.com" }, - "Update Product", - $"Product with id = {notification.productId} updated!"); - - await _mailService.SendAsync(mail, cancellationToken); - } -} diff --git a/src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Events/OrderCreatedDomainEvent.cs b/src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Events/OrderCreatedDomainEvent.cs new file mode 100644 index 0000000..515692b --- /dev/null +++ b/src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Events/OrderCreatedDomainEvent.cs @@ -0,0 +1,5 @@ +using CleanArchitecture.Domain.Common; + +namespace CleanArchitecture.Domain.AggregatesModels.Orders.Events; + +public sealed record OrderCreatedDomainEvent(Guid UserId) : IDomainEvent; diff --git a/src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Order.cs b/src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Order.cs index 218ca28..3215c9c 100644 --- a/src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Order.cs +++ b/src/Core/CleanArchitecture.Domain/AggregatesModels/Orders/Order.cs @@ -1,5 +1,6 @@ using CleanArchitecture.Domain.AggregatesModels.Baskets; using CleanArchitecture.Domain.AggregatesModels.Orders.Enums; +using CleanArchitecture.Domain.AggregatesModels.Orders.Events; using CleanArchitecture.Domain.AggregatesModels.Shared; using CleanArchitecture.Domain.Common; @@ -8,6 +9,7 @@ namespace CleanArchitecture.Domain.AggregatesModels.Orders; public sealed class Order : BaseEntityRoot { private readonly List _orderItems = new(); + private Order(Guid userId) { UserId = userId; @@ -33,13 +35,13 @@ public static Order Create(Basket basket, UserInformation userInfomation) order.AddOrderItem(item.ProductId, item.Quantity, item.Product.Price); } + order.RaiseDomainEvent(new OrderCreatedDomainEvent(order.UserId)); + return order; } private void AddOrderItem(Guid productId, int quantity, decimal price) { - OrderItem orderItem = _orderItems.FirstOrDefault(o => o.ProductId == productId); - if (orderItem is not null) - _orderItems.Add(OrderItem.Create(Id, productId, quantity, price)); + _orderItems.Add(OrderItem.Create(Id, productId, quantity, price)); } } diff --git a/src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Events/ProductUpdatedDomainEvent.cs b/src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Events/ProductUpdatedDomainEvent.cs deleted file mode 100644 index 5be9bbf..0000000 --- a/src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Events/ProductUpdatedDomainEvent.cs +++ /dev/null @@ -1,5 +0,0 @@ -using CleanArchitecture.Domain.Common; - -namespace CleanArchitecture.Domain.AggregatesModels.Products.Events; - -public sealed record ProductUpdatedDomainEvent(Guid productId) : IDomainEvent; diff --git a/src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Product.cs b/src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Product.cs index 7314c68..03fce9f 100644 --- a/src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Product.cs +++ b/src/Core/CleanArchitecture.Domain/AggregatesModels/Products/Product.cs @@ -1,5 +1,4 @@ using CleanArchitecture.Domain.AggregatesModels.Categories; -using CleanArchitecture.Domain.AggregatesModels.Products.Events; using CleanArchitecture.Domain.Common; namespace CleanArchitecture.Domain.AggregatesModels.Products; @@ -71,8 +70,6 @@ public Product Update( if (categoryId.HasValue && CategoryId.Equals(categoryId.Value) is not true && categoryId.Value != Guid.Empty) CategoryId = categoryId.Value; - RaiseDomainEvent(new ProductUpdatedDomainEvent(Id)); - return this; } diff --git a/src/Core/CleanArchitecture.Domain/AggregatesModels/Shared/UserInformation.cs b/src/Core/CleanArchitecture.Domain/AggregatesModels/Shared/UserInformation.cs index 3ee7ae1..fc678dc 100644 --- a/src/Core/CleanArchitecture.Domain/AggregatesModels/Shared/UserInformation.cs +++ b/src/Core/CleanArchitecture.Domain/AggregatesModels/Shared/UserInformation.cs @@ -2,15 +2,15 @@ public record UserInformation { - public string UserName { get; private set; } + public string Name { get; private set; } public Phone Phone { get; private set; } public Address Address { get; private set; } protected UserInformation() { } - public UserInformation(string userName, Phone phone, Address address) + public UserInformation(string name, Phone phone, Address address) { - UserName = userName; + Name = name; Phone = phone; Address = address; } diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Configurations/OrderConfiguration.cs b/src/Infrastructure/CleanArchitecture.Persistence/Configurations/OrderConfiguration.cs index 8603b73..b728965 100644 --- a/src/Infrastructure/CleanArchitecture.Persistence/Configurations/OrderConfiguration.cs +++ b/src/Infrastructure/CleanArchitecture.Persistence/Configurations/OrderConfiguration.cs @@ -38,7 +38,7 @@ public void Configure(EntityTypeBuilder builder) .IsRequired(); }); - userInformationBuider.Property(u => u.UserName) + userInformationBuider.Property(u => u.Name) .IsRequired(); }); } diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.Designer.cs b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.Designer.cs new file mode 100644 index 0000000..d6cb2be --- /dev/null +++ b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.Designer.cs @@ -0,0 +1,392 @@ +// +using System; +using CleanArchitecture.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CleanArchitecture.Persistence.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240420101420_Update-Model-UserInformation-171320042024")] + partial class UpdateModelUserInformation171320042024 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.BasketProductItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("BasketId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.HasIndex("ProductId"); + + b.ToTable("BasketProductItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Categories.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Products.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CategoryId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("ImagePath") + .HasColumnType("nvarchar(max)"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("CleanArchitecture.Persistence.Outbox.OutboxMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Error") + .HasColumnType("nvarchar(max)"); + + b.Property("OccurredOnUtc") + .HasColumnType("datetime2"); + + b.Property("ProcessedOnUtc") + .HasColumnType("datetime2"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("OutboxMessages"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.BasketProductItem", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", null) + .WithMany("BasketProductItems") + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Products.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.OwnsOne("CleanArchitecture.Domain.AggregatesModels.Shared.UserInformation", "UserInformation", b1 => + { + b1.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b1.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b1.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + + b1.OwnsOne("CleanArchitecture.Domain.AggregatesModels.Shared.Address", "Address", b2 => + { + b2.Property("UserInformationOrderId") + .HasColumnType("uniqueidentifier"); + + b2.Property("City") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b2.Property("Street") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b2.HasKey("UserInformationOrderId"); + + b2.ToTable("Orders"); + + b2.WithOwner() + .HasForeignKey("UserInformationOrderId"); + }); + + b1.Navigation("Address") + .IsRequired(); + }); + + b.Navigation("UserInformation") + .IsRequired(); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.OrderItem", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Orders.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Products.Product", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Categories.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", b => + { + b.Navigation("BasketProductItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.cs b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.cs new file mode 100644 index 0000000..08c1793 --- /dev/null +++ b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420101420_Update-Model-UserInformation-171320042024.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CleanArchitecture.Persistence.Migrations +{ + /// + public partial class UpdateModelUserInformation171320042024 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "UserInformation_UserName", + table: "Orders", + newName: "UserInformation_Name"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "UserInformation_Name", + table: "Orders", + newName: "UserInformation_UserName"); + } + } +} diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.Designer.cs b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.Designer.cs new file mode 100644 index 0000000..c384718 --- /dev/null +++ b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.Designer.cs @@ -0,0 +1,397 @@ +// +using System; +using CleanArchitecture.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CleanArchitecture.Persistence.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240420112841_Update-Model-UserInformation-182820042024")] + partial class UpdateModelUserInformation182820042024 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.BasketProductItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("BasketId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.HasIndex("ProductId"); + + b.ToTable("BasketProductItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Categories.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Products.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CategoryId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("ImagePath") + .HasColumnType("nvarchar(max)"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("CleanArchitecture.Persistence.Outbox.OutboxMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Error") + .HasColumnType("nvarchar(max)"); + + b.Property("OccurredOnUtc") + .HasColumnType("datetime2"); + + b.Property("ProcessedOnUtc") + .HasColumnType("datetime2"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("OutboxMessages"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.BasketProductItem", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", null) + .WithMany("BasketProductItems") + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Products.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.OwnsOne("CleanArchitecture.Domain.AggregatesModels.Shared.UserInformation", "UserInformation", b1 => + { + b1.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b1.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b1.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b1.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + + b1.OwnsOne("CleanArchitecture.Domain.AggregatesModels.Shared.Address", "Address", b2 => + { + b2.Property("UserInformationOrderId") + .HasColumnType("uniqueidentifier"); + + b2.Property("City") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b2.Property("Street") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b2.HasKey("UserInformationOrderId"); + + b2.ToTable("Orders"); + + b2.WithOwner() + .HasForeignKey("UserInformationOrderId"); + }); + + b1.Navigation("Address") + .IsRequired(); + }); + + b.Navigation("UserInformation") + .IsRequired(); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.OrderItem", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Orders.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Products.Product", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Categories.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", b => + { + b.Navigation("BasketProductItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.cs b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.cs new file mode 100644 index 0000000..24a0ca2 --- /dev/null +++ b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420112841_Update-Model-UserInformation-182820042024.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CleanArchitecture.Persistence.Migrations +{ + /// + public partial class UpdateModelUserInformation182820042024 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "UserInformation_Email", + table: "Orders", + type: "nvarchar(100)", + maxLength: 100, + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "UserInformation_Email", + table: "Orders"); + } + } +} diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.Designer.cs b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.Designer.cs new file mode 100644 index 0000000..2eee425 --- /dev/null +++ b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.Designer.cs @@ -0,0 +1,392 @@ +// +using System; +using CleanArchitecture.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CleanArchitecture.Persistence.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240420114848_Update-Model-UserInformation-184720042024")] + partial class UpdateModelUserInformation184720042024 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.BasketProductItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("BasketId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.HasIndex("ProductId"); + + b.ToTable("BasketProductItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Categories.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("ProductId") + .HasColumnType("uniqueidentifier"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Products.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CategoryId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("DeletedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("DeletedOn") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("ImagePath") + .HasColumnType("nvarchar(max)"); + + b.Property("LastModifiedBy") + .HasColumnType("uniqueidentifier"); + + b.Property("LastModifiedOn") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("CleanArchitecture.Persistence.Outbox.OutboxMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Error") + .HasColumnType("nvarchar(max)"); + + b.Property("OccurredOnUtc") + .HasColumnType("datetime2"); + + b.Property("ProcessedOnUtc") + .HasColumnType("datetime2"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("OutboxMessages"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.BasketProductItem", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", null) + .WithMany("BasketProductItems") + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Products.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.OwnsOne("CleanArchitecture.Domain.AggregatesModels.Shared.UserInformation", "UserInformation", b1 => + { + b1.Property("OrderId") + .HasColumnType("uniqueidentifier"); + + b1.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b1.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + + b1.OwnsOne("CleanArchitecture.Domain.AggregatesModels.Shared.Address", "Address", b2 => + { + b2.Property("UserInformationOrderId") + .HasColumnType("uniqueidentifier"); + + b2.Property("City") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b2.Property("Street") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b2.HasKey("UserInformationOrderId"); + + b2.ToTable("Orders"); + + b2.WithOwner() + .HasForeignKey("UserInformationOrderId"); + }); + + b1.Navigation("Address") + .IsRequired(); + }); + + b.Navigation("UserInformation") + .IsRequired(); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.OrderItem", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Orders.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Products.Product", b => + { + b.HasOne("CleanArchitecture.Domain.AggregatesModels.Categories.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Baskets.Basket", b => + { + b.Navigation("BasketProductItems"); + }); + + modelBuilder.Entity("CleanArchitecture.Domain.AggregatesModels.Orders.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.cs b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.cs new file mode 100644 index 0000000..292a401 --- /dev/null +++ b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/20240420114848_Update-Model-UserInformation-184720042024.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CleanArchitecture.Persistence.Migrations +{ + /// + public partial class UpdateModelUserInformation184720042024 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "UserInformation_Email", + table: "Orders"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "UserInformation_Email", + table: "Orders", + type: "nvarchar(100)", + maxLength: 100, + nullable: false, + defaultValue: ""); + } + } +} diff --git a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs index 23620b1..77aa024 100644 --- a/src/Infrastructure/CleanArchitecture.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/Infrastructure/CleanArchitecture.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs @@ -307,15 +307,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b1.Property("OrderId") .HasColumnType("uniqueidentifier"); + b1.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + b1.Property("Phone") .IsRequired() .HasMaxLength(20) .HasColumnType("nvarchar(20)"); - b1.Property("UserName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b1.HasKey("OrderId"); b1.ToTable("Orders");