feat: Implement Discount Product and Shopping Cart functionalities

- Added UpdateDiscountProductCommandValidator for validating discount product updates.
- Created GetDiscountProductByIdQuery and its handler for retrieving discount product details by ID.
- Implemented GetDiscountProductsQuery and handler for fetching a list of discount products with filtering options.
- Developed AddToCartCommand and handler for adding products to the shopping cart.
- Implemented ClearCartCommand and handler for clearing the shopping cart.
- Created RemoveFromCartCommand and handler for removing items from the cart.
- Added UpdateCartItemCountCommand and handler for updating the quantity of items in the cart.
- Developed GetUserCartQuery and handler for retrieving the user's shopping cart details.
- Implemented Product Tag functionalities including assigning tags to products, creating, updating, and deleting tags.
- Added queries for fetching all tags and products by tag.
This commit is contained in:
masoodafar-web
2025-12-04 02:41:19 +03:30
parent c9dab944fa
commit 4f400eabc5
92 changed files with 2285 additions and 41 deletions

View File

@@ -0,0 +1,7 @@
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetOrderById;
public record GetOrderByIdQuery : IRequest<GetOrderByIdResponseDto>
{
/// <summary>شناسه سفارش</summary>
public long OrderId { get; init; }
}

View File

@@ -0,0 +1,58 @@
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetOrderById;
public class GetOrderByIdQueryHandler : IRequestHandler<GetOrderByIdQuery, GetOrderByIdResponseDto>
{
private readonly IApplicationContractContext _context;
public GetOrderByIdQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetOrderByIdResponseDto> Handle(GetOrderByIdQuery request, CancellationToken cancellationToken)
{
var response = await _context.DiscountOrders.GetOrderByIdAsync(
new GetOrderByIdRequest { OrderId = request.OrderId },
cancellationToken: cancellationToken);
return new GetOrderByIdResponseDto
{
Id = response.Id,
UserId = response.UserId,
TrackingCode = response.TrackingCode,
Status = response.Status,
StatusTitle = response.StatusTitle,
TotalPrice = response.TotalPrice,
DiscountBalanceUsed = response.DiscountBalanceUsed,
GatewayPayment = response.GatewayPayment,
FinalPrice = response.FinalPrice,
PaymentTransactionCode = response.PaymentTransactionCode,
AdminNote = response.AdminNote,
CreatedAt = response.CreatedAt.ToDateTime(),
PaidAt = response.HasPaidAt ? response.PaidAt.ToDateTime() : null,
ShippingAddress = new AddressInfoDto
{
Id = response.ShippingAddress.Id,
RecipientName = response.ShippingAddress.RecipientName,
RecipientPhone = response.ShippingAddress.RecipientPhone,
Province = response.ShippingAddress.Province,
City = response.ShippingAddress.City,
PostalCode = response.ShippingAddress.PostalCode,
FullAddress = response.ShippingAddress.FullAddress
},
Items = response.Items.Select(item => new OrderItemDto
{
Id = item.Id,
ProductId = item.ProductId,
ProductTitle = item.ProductTitle,
UnitPrice = item.UnitPrice,
DiscountPercent = item.DiscountPercent,
Quantity = item.Quantity,
TotalPrice = item.TotalPrice,
DiscountedPrice = item.DiscountedPrice
}).ToList()
};
}
}

View File

@@ -0,0 +1,10 @@
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetOrderById;
public class GetOrderByIdQueryValidator : AbstractValidator<GetOrderByIdQuery>
{
public GetOrderByIdQueryValidator()
{
RuleFor(x => x.OrderId)
.GreaterThan(0).WithMessage("شناسه سفارش نامعتبر است");
}
}

View File

@@ -0,0 +1,44 @@
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetOrderById;
public class GetOrderByIdResponseDto
{
public long Id { get; set; }
public long UserId { get; set; }
public string TrackingCode { get; set; }
public int Status { get; set; }
public string StatusTitle { get; set; }
public long TotalPrice { get; set; }
public long DiscountBalanceUsed { get; set; }
public long GatewayPayment { get; set; }
public long FinalPrice { get; set; }
public string PaymentTransactionCode { get; set; }
public string AdminNote { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? PaidAt { get; set; }
public AddressInfoDto ShippingAddress { get; set; }
public List<OrderItemDto> Items { get; set; } = new();
}
public class AddressInfoDto
{
public long Id { get; set; }
public string RecipientName { get; set; }
public string RecipientPhone { get; set; }
public string Province { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public string FullAddress { get; set; }
}
public class OrderItemDto
{
public long Id { get; set; }
public long ProductId { get; set; }
public string ProductTitle { get; set; }
public long UnitPrice { get; set; }
public int DiscountPercent { get; set; }
public int Quantity { get; set; }
public long TotalPrice { get; set; }
public long DiscountedPrice { get; set; }
}