feat: Implement Discount Sales Report Query and Handler
Build and Deploy / build (push) Successful in 2m33s

- Added GetDiscountSalesReportQuery and GetDiscountSalesReportQueryHandler to fetch discount sales reports.
- Introduced DiscountSalesReportDto, SalesSummaryDto, and PeriodSalesDto for structured report data.

feat: Add Discount Product Image Management

- Created AddDiscountProductImageCommand and AddDiscountProductImageCommandHandler for image uploads.
- Implemented DeleteDiscountProductImageCommand and DeleteDiscountProductImageCommandHandler for image deletion.
- Added ReorderDiscountProductImagesCommand and ReorderDiscountProductImagesCommandHandler for image reordering.
- Developed UpdateDiscountProductImageCommand and UpdateDiscountProductImageCommandHandler for image updates.

feat: Enhance Product Tag Management

- Introduced DeleteProductTagCommand and DeleteProductTagCommandHandler for tag deletion.
- Added UpdateProductTagCommand and UpdateProductTagCommandHandler for updating product tags.
- Implemented GetAllProductTagsQuery and GetAllProductTagsQueryHandler for fetching all product tags.
- Created GetProductTagQuery and GetProductTagQueryHandler for retrieving specific product tags.

feat: Develop Web API Services for Discount and Product Management

- Implemented DiscountCategoryService for managing discount categories.
- Created DiscountOrderService for handling discount orders and related queries.
- Developed DiscountProductService for managing discount products and their images.
- Added DiscountShoppingCartService for managing shopping cart operations.
- Implemented ProductTagService for managing product tags and their associations.
- Created TagService for managing tags and their related operations.
This commit is contained in:
masoodafar-web
2026-01-01 02:26:51 +03:30
parent 721207f6a0
commit d0224d41b2
48 changed files with 1368 additions and 51 deletions
+56 -7
View File
@@ -1,22 +1,71 @@
# Plan: فعال‌سازی مرحله‌ای Handler های کامنت‌شده
**تاریخ:** 8 دسامبر 2025
**وضعیت:** در انتظار اجرا
**تعداد کل فایل‌های کامنت‌شده:** 37 فایل در 3 دسته
**وضعیت:** ✅ کامل شده
**آخرین به‌روزرسانی:** 1 ژانویه 2026
---
## خلاصه اجرایی
در `BackOffice.BFF.Application.csproj` سه دسته handler کامنت شدهاند:
در `BackOffice.BFF.Application.csproj` سه دسته handler کامنت شده بودند که همه فعال شدند:
1. **DiscountOrderCQ/** (18 فایل) - عدم تطابق Proto با CMS
2. **DiscountShoppingCartCQ/** (16 فایل) - عدم تطابق Proto
3. **CommissionCQ/Commands/ProcessWithdrawal/** (3 فایل) - مشکل تبدیل StringValue
1. **DiscountOrderCQ/** (18 فایل) - ✅ فعال شد
2. **DiscountShoppingCartCQ/** (16 فایل) - ✅ فعال شد و با CMS proto هماهنگ شد
3. **CommissionCQ/Commands/ProcessWithdrawal/** (3 فایل) - ✅ قبلاً فعال شده بود
**همچنین در BackOffice UI (1 ژانویه 2026):**
- فعال‌سازی همه سرویس‌ها در `ConfigureService.cs`
- ثبت gRPC Clients برای DiscountProduct, DiscountCategory, DiscountOrder, Tag, ProductTag, PublicMessage
- ثبت Application Services
---
## مرحله 1: ProcessWithdrawal (30 دقیقه - ساده ✅)
## تغییرات انجام‌شده (1 ژانویه 2026)
### BackOffice UI - فعال‌سازی فرانت‌اند
#### ConfigureService.cs
- فعال‌سازی using statements برای همه proto clients
- ثبت gRPC Clients در DI container
- ثبت Application Services (IDiscountProductService, IDiscountCategoryService, etc.)
#### صفحات فعال شده:
| Route | صفحه |
|-------|------|
| `/discount-products` | مدیریت محصولات تخفیفی |
| `/discount-categories` | مدیریت دسته‌بندی‌ها |
| `/discount-orders` | مدیریت سفارشات |
| `/tags` | مدیریت تگ‌ها |
| `/public-messages` | پیام‌های عمومی |
---
## تغییرات انجام‌شده (13 ژانویه 2025)
### DiscountShoppingCartCQ - اصلاحات Proto
#### RemoveFromCart
- `CartItemId``ProductId` (مطابق با proto)
#### UpdateCartItemCount
- `CartItemId``ProductId` (مطابق با proto)
#### GetUserCart Response
- حذف `UserId` از response
- `TotalDiscountedPrice``TotalDiscountAmount`
- `TotalSavings` → حذف شد
- اضافه شدن `FinalPrice`
#### CartItemDto
- حذف `Id`
- `DiscountedPrice``DiscountAmount`
- `AddedAt``Created`
- اضافه شدن `FinalPrice`, `ProductRemainingCount`
---
## مرحله 1: ProcessWithdrawal ✅ (قبلاً انجام شده)
### ویژگی بیزینسی
مدیریت درخواست‌های برداشت کمیسیون توسط ادمین (تایید/رد)
@@ -5,14 +5,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- Exclude handlers that need proto fixes -->
<!-- All handlers now ENABLED with BFF Protobuf and Mapster profiles -->
<!-- ProcessWithdrawal, DiscountOrder, DiscountShoppingCart fixed and enabled -->
<ItemGroup>
<!-- DiscountShoppingCart - FrontOffice-only feature, not needed in BackOffice -->
<!-- این feature فقط برای مشتریان FrontOffice است. مدیریت سبد خرید توسط ادمین در آینده اضافه خواهد شد -->
<Compile Remove="DiscountShoppingCartCQ/**/*.cs" />
<!-- All handlers now ENABLED with BFF Protobuf and Mapster profiles -->
<!-- ProcessWithdrawal, DiscountOrder fixed and enabled -->
<!-- All excluded handlers have been enabled -->
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,50 @@
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetAllDiscountOrders;
/// <summary>
/// کوئری دریافت همه سفارشات فروشگاه تخفیفی برای ادمین
/// </summary>
public class GetAllDiscountOrdersQuery : IRequest<GetAllDiscountOrdersResponseDto>
{
public int PageNumber { get; set; } = 1;
public int PageSize { get; set; } = 20;
public long? UserId { get; set; }
public int? PaymentStatus { get; set; }
public int? DeliveryStatus { get; set; }
public string? UserMobile { get; set; }
public string? TrackingCode { get; set; }
public DateTime? FromDate { get; set; }
public DateTime? ToDate { get; set; }
public long? MinAmount { get; set; }
public long? MaxAmount { get; set; }
}
public class GetAllDiscountOrdersResponseDto
{
public MetaData MetaData { get; set; } = new();
public List<AdminOrderDto> Orders { get; set; } = new();
}
public class AdminOrderDto
{
public long Id { get; set; }
public long UserId { get; set; }
public string UserFullName { get; set; } = string.Empty;
public string UserMobile { get; set; } = string.Empty;
public long TotalAmount { get; set; }
public long DiscountBalanceUsed { get; set; }
public long GatewayAmountPaid { get; set; }
public long VatAmount { get; set; }
public int PaymentStatus { get; set; }
public DateTime? PaymentDate { get; set; }
public int DeliveryStatus { get; set; }
public DateTime? DeliveryDate { get; set; }
public string? ShippingAddress { get; set; }
public string? ReceiverName { get; set; }
public string? ReceiverMobile { get; set; }
public string? TrackingCode { get; set; }
public string? AdminNote { get; set; }
public DateTime Created { get; set; }
public DateTime? LastModified { get; set; }
public int ItemsCount { get; set; }
}
@@ -0,0 +1,88 @@
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
using Google.Protobuf.WellKnownTypes;
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetAllDiscountOrders;
public class GetAllDiscountOrdersQueryHandler : IRequestHandler<GetAllDiscountOrdersQuery, GetAllDiscountOrdersResponseDto>
{
private readonly IApplicationContractContext _context;
public GetAllDiscountOrdersQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetAllDiscountOrdersResponseDto> Handle(GetAllDiscountOrdersQuery request, CancellationToken cancellationToken)
{
var grpcRequest = new GetAllDiscountOrdersRequest
{
PageNumber = request.PageNumber,
PageSize = request.PageSize
};
if (request.UserId.HasValue)
grpcRequest.UserId = request.UserId.Value;
if (request.PaymentStatus.HasValue)
grpcRequest.PaymentStatus = request.PaymentStatus.Value;
if (request.DeliveryStatus.HasValue)
grpcRequest.DeliveryStatus = request.DeliveryStatus.Value;
if (!string.IsNullOrWhiteSpace(request.UserMobile))
grpcRequest.UserMobile = request.UserMobile;
if (!string.IsNullOrWhiteSpace(request.TrackingCode))
grpcRequest.TrackingCode = request.TrackingCode;
if (request.FromDate.HasValue)
grpcRequest.FromDate = Timestamp.FromDateTime(DateTime.SpecifyKind(request.FromDate.Value, DateTimeKind.Utc));
if (request.ToDate.HasValue)
grpcRequest.ToDate = Timestamp.FromDateTime(DateTime.SpecifyKind(request.ToDate.Value, DateTimeKind.Utc));
if (request.MinAmount.HasValue)
grpcRequest.MinAmount = request.MinAmount.Value;
if (request.MaxAmount.HasValue)
grpcRequest.MaxAmount = request.MaxAmount.Value;
var response = await _context.DiscountOrders.GetAllDiscountOrdersAsync(grpcRequest, cancellationToken: cancellationToken);
return new GetAllDiscountOrdersResponseDto
{
MetaData = new MetaData
{
CurrentPage = response.MetaData.CurrentPage,
TotalPage = response.MetaData.TotalPage,
PageSize = response.MetaData.PageSize,
TotalCount = response.MetaData.TotalCount,
HasPrevious = response.MetaData.HasPrevious,
HasNext = response.MetaData.HasNext
},
Orders = response.Models.Select(o => new AdminOrderDto
{
Id = o.Id,
UserId = o.UserId,
UserFullName = o.UserFullName,
UserMobile = o.UserMobile,
TotalAmount = o.TotalAmount,
DiscountBalanceUsed = o.DiscountBalanceUsed,
GatewayAmountPaid = o.GatewayAmountPaid,
VatAmount = o.VatAmount,
PaymentStatus = (int)o.PaymentStatus,
PaymentDate = o.PaymentDate?.ToDateTime(),
DeliveryStatus = (int)o.DeliveryStatus,
DeliveryDate = o.DeliveryDate?.ToDateTime(),
ShippingAddress = o.ShippingAddress,
ReceiverName = o.ReceiverName,
ReceiverMobile = o.ReceiverMobile,
TrackingCode = o.TrackingCode,
AdminNote = o.AdminNote,
Created = o.Created.ToDateTime(),
LastModified = o.LastModified?.ToDateTime(),
ItemsCount = o.ItemsCount
}).ToList()
};
}
}
@@ -0,0 +1,53 @@
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetDiscountSalesReport;
public class GetDiscountSalesReportQuery : IRequest<DiscountSalesReportDto>
{
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
public ReportPeriodType PeriodType { get; set; } = ReportPeriodType.Daily;
}
public enum ReportPeriodType
{
Summary = 0,
Daily = 1,
Weekly = 2,
Monthly = 3
}
public class DiscountSalesReportDto
{
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
public ReportPeriodType PeriodType { get; set; }
public SalesSummaryDto Summary { get; set; } = new();
public List<PeriodSalesDto> Periods { get; set; } = new();
}
public class SalesSummaryDto
{
public int TotalOrders { get; set; }
public int SuccessfulOrders { get; set; }
public int PendingOrders { get; set; }
public int RejectedOrders { get; set; }
public decimal TotalRevenue { get; set; }
public decimal TotalDiscountUsed { get; set; }
public decimal TotalGatewayPayments { get; set; }
public decimal TotalVat { get; set; }
public int TotalItemsSold { get; set; }
public int UniqueCustomers { get; set; }
public decimal AverageOrderValue { get; set; }
}
public class PeriodSalesDto
{
public string PeriodLabel { get; set; } = string.Empty;
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
public int OrderCount { get; set; }
public decimal Revenue { get; set; }
public decimal DiscountUsed { get; set; }
public decimal GatewayPayments { get; set; }
public decimal VatAmount { get; set; }
public int ItemsSold { get; set; }
}
@@ -0,0 +1,59 @@
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
using Google.Protobuf.WellKnownTypes;
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetDiscountSalesReport;
public class GetDiscountSalesReportQueryHandler : IRequestHandler<GetDiscountSalesReportQuery, DiscountSalesReportDto>
{
private readonly IApplicationContractContext _context;
public GetDiscountSalesReportQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<DiscountSalesReportDto> Handle(GetDiscountSalesReportQuery request, CancellationToken cancellationToken)
{
var grpcRequest = new GetDiscountSalesReportRequest
{
FromDate = Timestamp.FromDateTime(DateTime.SpecifyKind(request.FromDate, DateTimeKind.Utc)),
ToDate = Timestamp.FromDateTime(DateTime.SpecifyKind(request.ToDate, DateTimeKind.Utc)),
ReportType = (SalesReportType)request.PeriodType
};
var response = await _context.DiscountOrders.GetDiscountSalesReportAsync(grpcRequest, cancellationToken: cancellationToken);
return new DiscountSalesReportDto
{
FromDate = request.FromDate,
ToDate = request.ToDate,
PeriodType = request.PeriodType,
Summary = new SalesSummaryDto
{
TotalOrders = response.Summary.TotalOrders,
SuccessfulOrders = response.Summary.CompletedOrders,
PendingOrders = response.Summary.PendingOrders,
RejectedOrders = response.Summary.CancelledOrders,
TotalRevenue = response.Summary.TotalSalesAmount,
TotalDiscountUsed = response.Summary.TotalDiscountUsed,
TotalGatewayPayments = response.Summary.TotalGatewayPaid,
TotalVat = response.Summary.TotalVatAmount,
TotalItemsSold = response.Summary.TotalProductsSold,
UniqueCustomers = response.Summary.UniqueCustomers,
AverageOrderValue = response.Summary.AverageOrderValue
},
Periods = response.Periods.Select(p => new PeriodSalesDto
{
PeriodLabel = p.PeriodLabel,
PeriodStart = p.PeriodStart.ToDateTime(),
PeriodEnd = p.PeriodEnd.ToDateTime(),
OrderCount = p.OrdersCount,
Revenue = p.TotalAmount,
DiscountUsed = p.DiscountUsed,
GatewayPayments = p.GatewayPaid,
VatAmount = 0, // Not in proto response
ItemsSold = 0 // Not in proto response
}).ToList()
};
}
}
@@ -0,0 +1,22 @@
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.AddDiscountProductImage;
public class AddDiscountProductImageCommand : IRequest<AddDiscountProductImageResponseDto>
{
public long DiscountProductId { get; set; }
public ImageFileInput? ImageFile { get; set; }
public ImageFileInput? ThumbnailFile { get; set; }
public string? Title { get; set; }
public string? AltText { get; set; }
}
public class ImageFileInput
{
public byte[] Data { get; set; } = [];
public string FileName { get; set; } = string.Empty;
public string MimeType { get; set; } = string.Empty;
}
public class AddDiscountProductImageResponseDto
{
public long ImageId { get; set; }
}
@@ -0,0 +1,67 @@
using CMSMicroservice.Protobuf.Protos.DiscountProduct;
using Google.Protobuf;
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.AddDiscountProductImage;
public class AddDiscountProductImageCommandHandler : IRequestHandler<AddDiscountProductImageCommand, AddDiscountProductImageResponseDto>
{
private readonly IApplicationContractContext _context;
public AddDiscountProductImageCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<AddDiscountProductImageResponseDto> Handle(AddDiscountProductImageCommand request, CancellationToken cancellationToken)
{
var addRequest = new AddDiscountProductImageRequest
{
DiscountProductId = request.DiscountProductId
};
if (!string.IsNullOrWhiteSpace(request.Title))
addRequest.Title = request.Title;
if (!string.IsNullOrWhiteSpace(request.AltText))
addRequest.AltText = request.AltText;
// Upload Image
if (request.ImageFile != null && request.ImageFile.Data != null && request.ImageFile.Data.Length > 0)
{
var imageFileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
{
Directory = "Images/DiscountShop/Products/Gallery",
IsBase64 = false,
MIME = request.ImageFile.MimeType,
FileName = request.ImageFile.FileName,
File = ByteString.CopyFrom(request.ImageFile.Data)
}, cancellationToken: cancellationToken);
if (imageFileInfo != null && !string.IsNullOrWhiteSpace(imageFileInfo.File))
addRequest.ImagePath = imageFileInfo.File;
}
// Upload Thumbnail
if (request.ThumbnailFile != null && request.ThumbnailFile.Data != null && request.ThumbnailFile.Data.Length > 0)
{
var thumbnailFileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
{
Directory = "Images/DiscountShop/Products/Gallery/Thumbnails",
IsBase64 = false,
MIME = request.ThumbnailFile.MimeType,
FileName = request.ThumbnailFile.FileName,
File = ByteString.CopyFrom(request.ThumbnailFile.Data)
}, cancellationToken: cancellationToken);
if (thumbnailFileInfo != null && !string.IsNullOrWhiteSpace(thumbnailFileInfo.File))
addRequest.ThumbnailPath = thumbnailFileInfo.File;
}
var response = await _context.DiscountProducts.AddDiscountProductImageAsync(addRequest, cancellationToken: cancellationToken);
return new AddDiscountProductImageResponseDto
{
ImageId = response.ImageId
};
}
}
@@ -0,0 +1,6 @@
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.DeleteDiscountProductImage;
public class DeleteDiscountProductImageCommand : IRequest
{
public long Id { get; set; }
}
@@ -0,0 +1,23 @@
using CMSMicroservice.Protobuf.Protos.DiscountProduct;
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.DeleteDiscountProductImage;
public class DeleteDiscountProductImageCommandHandler : IRequestHandler<DeleteDiscountProductImageCommand>
{
private readonly IApplicationContractContext _context;
public DeleteDiscountProductImageCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteDiscountProductImageCommand request, CancellationToken cancellationToken)
{
await _context.DiscountProducts.DeleteDiscountProductImageAsync(new DeleteDiscountProductImageRequest
{
Id = request.Id
}, cancellationToken: cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,7 @@
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.ReorderDiscountProductImages;
public class ReorderDiscountProductImagesCommand : IRequest
{
public long DiscountProductId { get; set; }
public List<long> ImageIds { get; set; } = new();
}
@@ -0,0 +1,26 @@
using CMSMicroservice.Protobuf.Protos.DiscountProduct;
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.ReorderDiscountProductImages;
public class ReorderDiscountProductImagesCommandHandler : IRequestHandler<ReorderDiscountProductImagesCommand>
{
private readonly IApplicationContractContext _context;
public ReorderDiscountProductImagesCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(ReorderDiscountProductImagesCommand request, CancellationToken cancellationToken)
{
var reorderRequest = new ReorderDiscountProductImagesRequest
{
DiscountProductId = request.DiscountProductId
};
reorderRequest.ImageIds.AddRange(request.ImageIds);
await _context.DiscountProducts.ReorderDiscountProductImagesAsync(reorderRequest, cancellationToken: cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,13 @@
using BackOffice.BFF.Application.DiscountProductCQ.Commands.AddDiscountProductImage;
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.UpdateDiscountProductImage;
public class UpdateDiscountProductImageCommand : IRequest
{
public long Id { get; set; }
public ImageFileInput? ImageFile { get; set; }
public ImageFileInput? ThumbnailFile { get; set; }
public string? Title { get; set; }
public string? AltText { get; set; }
public bool IsActive { get; set; }
}
@@ -0,0 +1,65 @@
using CMSMicroservice.Protobuf.Protos.DiscountProduct;
using Google.Protobuf;
namespace BackOffice.BFF.Application.DiscountProductCQ.Commands.UpdateDiscountProductImage;
public class UpdateDiscountProductImageCommandHandler : IRequestHandler<UpdateDiscountProductImageCommand>
{
private readonly IApplicationContractContext _context;
public UpdateDiscountProductImageCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateDiscountProductImageCommand request, CancellationToken cancellationToken)
{
var updateRequest = new UpdateDiscountProductImageRequest
{
Id = request.Id,
IsActive = request.IsActive
};
if (!string.IsNullOrWhiteSpace(request.Title))
updateRequest.Title = request.Title;
if (!string.IsNullOrWhiteSpace(request.AltText))
updateRequest.AltText = request.AltText;
// Upload new Image if provided
if (request.ImageFile != null && request.ImageFile.Data != null && request.ImageFile.Data.Length > 0)
{
var imageFileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
{
Directory = "Images/DiscountShop/Products/Gallery",
IsBase64 = false,
MIME = request.ImageFile.MimeType,
FileName = request.ImageFile.FileName,
File = ByteString.CopyFrom(request.ImageFile.Data)
}, cancellationToken: cancellationToken);
if (imageFileInfo != null && !string.IsNullOrWhiteSpace(imageFileInfo.File))
updateRequest.ImagePath = imageFileInfo.File;
}
// Upload new Thumbnail if provided
if (request.ThumbnailFile != null && request.ThumbnailFile.Data != null && request.ThumbnailFile.Data.Length > 0)
{
var thumbnailFileInfo = await _context.FileInfos.CreateNewFileInfoAsync(new()
{
Directory = "Images/DiscountShop/Products/Gallery/Thumbnails",
IsBase64 = false,
MIME = request.ThumbnailFile.MimeType,
FileName = request.ThumbnailFile.FileName,
File = ByteString.CopyFrom(request.ThumbnailFile.Data)
}, cancellationToken: cancellationToken);
if (thumbnailFileInfo != null && !string.IsNullOrWhiteSpace(thumbnailFileInfo.File))
updateRequest.ThumbnailPath = thumbnailFileInfo.File;
}
await _context.DiscountProducts.UpdateDiscountProductImageAsync(updateRequest, cancellationToken: cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,24 @@
namespace BackOffice.BFF.Application.DiscountProductCQ.Queries.GetDiscountProductImages;
public class GetDiscountProductImagesQuery : IRequest<GetDiscountProductImagesResponseDto>
{
public long DiscountProductId { get; set; }
public bool OnlyActive { get; set; } = false; // Admin can see all
}
public class GetDiscountProductImagesResponseDto
{
public List<DiscountProductImageDto> Images { get; set; } = new();
}
public class DiscountProductImageDto
{
public long Id { get; set; }
public long DiscountProductId { get; set; }
public string ImagePath { get; set; } = string.Empty;
public string? ThumbnailPath { get; set; }
public string? Title { get; set; }
public string? AltText { get; set; }
public int SortOrder { get; set; }
public bool IsActive { get; set; }
}
@@ -0,0 +1,39 @@
using CMSMicroservice.Protobuf.Protos.DiscountProduct;
namespace BackOffice.BFF.Application.DiscountProductCQ.Queries.GetDiscountProductImages;
public class GetDiscountProductImagesQueryHandler : IRequestHandler<GetDiscountProductImagesQuery, GetDiscountProductImagesResponseDto>
{
private readonly IApplicationContractContext _context;
public GetDiscountProductImagesQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetDiscountProductImagesResponseDto> Handle(GetDiscountProductImagesQuery request, CancellationToken cancellationToken)
{
var grpcRequest = new GetDiscountProductImagesRequest
{
DiscountProductId = request.DiscountProductId,
OnlyActive = request.OnlyActive
};
var response = await _context.DiscountProducts.GetDiscountProductImagesAsync(grpcRequest, cancellationToken: cancellationToken);
return new GetDiscountProductImagesResponseDto
{
Images = response.Images.Select(i => new DiscountProductImageDto
{
Id = i.Id,
DiscountProductId = i.DiscountProductId,
ImagePath = i.ImagePath,
ThumbnailPath = i.ThumbnailPath,
Title = i.Title,
AltText = i.AltText,
SortOrder = i.SortOrder,
IsActive = i.IsActive
}).ToList()
};
}
}
@@ -5,6 +5,6 @@ public record RemoveFromCartCommand : IRequest
/// <summary>شناسه کاربر</summary>
public long UserId { get; init; }
/// <summary>شناسه آیتم سبد خرید</summary>
public long CartItemId { get; init; }
/// <summary>شناسه محصول</summary>
public long ProductId { get; init; }
}
@@ -17,7 +17,7 @@ public class RemoveFromCartCommandHandler : IRequestHandler<RemoveFromCartComman
new RemoveFromCartRequest
{
UserId = request.UserId,
CartItemId = request.CartItemId
ProductId = request.ProductId
},
cancellationToken: cancellationToken);
@@ -7,7 +7,7 @@ public class RemoveFromCartCommandValidator : AbstractValidator<RemoveFromCartCo
RuleFor(x => x.UserId)
.GreaterThan(0).WithMessage("شناسه کاربر نامعتبر است");
RuleFor(x => x.CartItemId)
.GreaterThan(0).WithMessage("شناسه آیتم سبد خرید نامعتبر است");
RuleFor(x => x.ProductId)
.GreaterThan(0).WithMessage("شناسه محصول نامعتبر است");
}
}
@@ -5,8 +5,8 @@ public record UpdateCartItemCountCommand : IRequest
/// <summary>شناسه کاربر</summary>
public long UserId { get; init; }
/// <summary>شناسه آیتم سبد خرید</summary>
public long CartItemId { get; init; }
/// <summary>شناسه محصول</summary>
public long ProductId { get; init; }
/// <summary>تعداد جدید</summary>
public int NewCount { get; init; }
@@ -17,7 +17,7 @@ public class UpdateCartItemCountCommandHandler : IRequestHandler<UpdateCartItemC
new UpdateCartItemCountRequest
{
UserId = request.UserId,
CartItemId = request.CartItemId,
ProductId = request.ProductId,
NewCount = request.NewCount
},
cancellationToken: cancellationToken);
@@ -7,8 +7,8 @@ public class UpdateCartItemCountCommandValidator : AbstractValidator<UpdateCartI
RuleFor(x => x.UserId)
.GreaterThan(0).WithMessage("شناسه کاربر نامعتبر است");
RuleFor(x => x.CartItemId)
.GreaterThan(0).WithMessage("شناسه آیتم سبد خرید نامعتبر است");
RuleFor(x => x.ProductId)
.GreaterThan(0).WithMessage("شناسه محصول نامعتبر است");
RuleFor(x => x.NewCount)
.GreaterThan(0).WithMessage("تعداد جدید باید بیشتر از صفر باشد");
@@ -19,13 +19,11 @@ public class GetUserCartQueryHandler : IRequestHandler<GetUserCartQuery, GetUser
return new GetUserCartResponseDto
{
UserId = response.UserId,
TotalPrice = response.TotalPrice,
TotalDiscountedPrice = response.TotalDiscountedPrice,
TotalSavings = response.TotalSavings,
TotalDiscountAmount = response.TotalDiscountAmount,
FinalPrice = response.FinalPrice,
Items = response.Items.Select(item => new CartItemDto
{
Id = item.Id,
ProductId = item.ProductId,
ProductTitle = item.ProductTitle,
ProductImagePath = item.ProductImagePath,
@@ -33,8 +31,10 @@ public class GetUserCartQueryHandler : IRequestHandler<GetUserCartQuery, GetUser
MaxDiscountPercent = item.MaxDiscountPercent,
Count = item.Count,
TotalPrice = item.TotalPrice,
DiscountedPrice = item.DiscountedPrice,
AddedAt = item.AddedAt.ToDateTime()
DiscountAmount = item.DiscountAmount,
FinalPrice = item.FinalPrice,
ProductRemainingCount = item.ProductRemainingCount,
Created = item.Created.ToDateTime()
}).ToList()
};
}
@@ -2,23 +2,28 @@ namespace BackOffice.BFF.Application.DiscountShoppingCartCQ.Queries.GetUserCart;
public class GetUserCartResponseDto
{
public long UserId { get; set; }
public List<CartItemDto> Items { get; set; } = new();
/// <summary>جمع کل قیمت (بدون تخفیف)</summary>
public long TotalPrice { get; set; }
public long TotalDiscountedPrice { get; set; }
public long TotalSavings { get; set; }
/// <summary>جمع تخفیف‌ها</summary>
public long TotalDiscountAmount { get; set; }
/// <summary>قیمت نهایی (با تخفیف)</summary>
public long FinalPrice { get; set; }
}
public class CartItemDto
{
public long Id { get; set; }
public long ProductId { get; set; }
public string ProductTitle { get; set; }
public string ProductImagePath { get; set; }
public string ProductTitle { get; set; } = string.Empty;
public string ProductImagePath { get; set; } = string.Empty;
public long UnitPrice { get; set; }
public int MaxDiscountPercent { get; set; }
public int Count { get; set; }
public long TotalPrice { get; set; }
public long DiscountedPrice { get; set; }
public DateTime AddedAt { get; set; }
/// <summary>مبلغ تخفیف</summary>
public long DiscountAmount { get; set; }
/// <summary>قیمت نهایی آیتم</summary>
public long FinalPrice { get; set; }
public int ProductRemainingCount { get; set; }
public DateTime Created { get; set; }
}
@@ -0,0 +1,6 @@
namespace BackOffice.BFF.Application.ProductTagCQ.Commands.DeleteProductTag;
public record DeleteProductTagCommand : IRequest<Unit>
{
public long Id { get; init; }
}
@@ -0,0 +1,25 @@
using CMSMicroservice.Protobuf.Protos.ProductTag;
namespace BackOffice.BFF.Application.ProductTagCQ.Commands.DeleteProductTag;
public class DeleteProductTagCommandHandler : IRequestHandler<DeleteProductTagCommand, Unit>
{
private readonly IApplicationContractContext _context;
public DeleteProductTagCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteProductTagCommand request, CancellationToken cancellationToken)
{
await _context.ProductTags.DeleteProductTagAsync(
new DeleteProductTagRequest
{
Id = request.Id
},
cancellationToken: cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,8 @@
namespace BackOffice.BFF.Application.ProductTagCQ.Commands.UpdateProductTag;
public record UpdateProductTagCommand : IRequest<Unit>
{
public long Id { get; init; }
public long ProductId { get; init; }
public long TagId { get; init; }
}
@@ -0,0 +1,27 @@
using CMSMicroservice.Protobuf.Protos.ProductTag;
namespace BackOffice.BFF.Application.ProductTagCQ.Commands.UpdateProductTag;
public class UpdateProductTagCommandHandler : IRequestHandler<UpdateProductTagCommand, Unit>
{
private readonly IApplicationContractContext _context;
public UpdateProductTagCommandHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateProductTagCommand request, CancellationToken cancellationToken)
{
await _context.ProductTags.UpdateProductTagAsync(
new UpdateProductTagRequest
{
Id = request.Id,
ProductId = request.ProductId,
TagId = request.TagId
},
cancellationToken: cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,23 @@
namespace BackOffice.BFF.Application.ProductTagCQ.Queries.GetAllProductTags;
public record GetAllProductTagsQuery : IRequest<GetAllProductTagsResponseDto>
{
public int PageNumber { get; init; } = 1;
public int PageSize { get; init; } = 10;
public string? SortBy { get; init; }
public long? ProductId { get; init; }
public long? TagId { get; init; }
}
public record GetAllProductTagsResponseDto
{
public MetaData MetaData { get; init; } = default!;
public List<ProductTagItemDto> Items { get; init; } = new();
}
public record ProductTagItemDto
{
public long Id { get; init; }
public long ProductId { get; init; }
public long TagId { get; init; }
}
@@ -0,0 +1,51 @@
using CMSMicroservice.Protobuf.Protos.ProductTag;
using CmsPaginationState = CMSMicroservice.Protobuf.Protos.PaginationState;
namespace BackOffice.BFF.Application.ProductTagCQ.Queries.GetAllProductTags;
public class GetAllProductTagsQueryHandler : IRequestHandler<GetAllProductTagsQuery, GetAllProductTagsResponseDto>
{
private readonly IApplicationContractContext _context;
public GetAllProductTagsQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetAllProductTagsResponseDto> Handle(GetAllProductTagsQuery request, CancellationToken cancellationToken)
{
var response = await _context.ProductTags.GetAllProductTagByFilterAsync(
new GetAllProductTagByFilterRequest
{
PaginationState = new CmsPaginationState
{
PageNumber = request.PageNumber,
PageSize = request.PageSize
},
SortBy = request.SortBy ?? "",
Filter = new GetAllProductTagByFilterFilter
{
ProductId = request.ProductId ?? 0,
TagId = request.TagId ?? 0
}
},
cancellationToken: cancellationToken);
return new GetAllProductTagsResponseDto
{
MetaData = new MetaData
{
CurrentPage = response.MetaData.CurrentPage,
PageSize = response.MetaData.PageSize,
TotalCount = response.MetaData.TotalCount,
TotalPage = response.MetaData.TotalPage
},
Items = response.Models.Select(pt => new ProductTagItemDto
{
Id = pt.Id,
ProductId = pt.ProductId,
TagId = pt.TagId
}).ToList()
};
}
}
@@ -0,0 +1,13 @@
namespace BackOffice.BFF.Application.ProductTagCQ.Queries.GetProductTag;
public record GetProductTagQuery : IRequest<GetProductTagResponseDto>
{
public long Id { get; init; }
}
public record GetProductTagResponseDto
{
public long Id { get; init; }
public long ProductId { get; init; }
public long TagId { get; init; }
}
@@ -0,0 +1,30 @@
using CMSMicroservice.Protobuf.Protos.ProductTag;
namespace BackOffice.BFF.Application.ProductTagCQ.Queries.GetProductTag;
public class GetProductTagQueryHandler : IRequestHandler<GetProductTagQuery, GetProductTagResponseDto>
{
private readonly IApplicationContractContext _context;
public GetProductTagQueryHandler(IApplicationContractContext context)
{
_context = context;
}
public async Task<GetProductTagResponseDto> Handle(GetProductTagQuery request, CancellationToken cancellationToken)
{
var response = await _context.ProductTags.GetProductTagAsync(
new GetProductTagRequest
{
Id = request.Id
},
cancellationToken: cancellationToken);
return new GetProductTagResponseDto
{
Id = response.Id,
ProductId = response.ProductId,
TagId = response.TagId
};
}
}
@@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Afrino.FMSMicroservice.Protobuf" Version="0.0.122" />
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.162" />
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.164" />
<PackageReference Include="Google.Protobuf" Version="3.23.3" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.54.0" />
@@ -42,6 +42,12 @@
<ProjectReference Include="..\Protobufs\BackOffice.BFF.Configuration.Protobuf\BackOffice.BFF.Configuration.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.NetworkMembership.Protobuf\BackOffice.BFF.NetworkMembership.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.PublicMessage.Protobuf\BackOffice.BFF.PublicMessage.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.DiscountProduct.Protobuf\BackOffice.BFF.DiscountProduct.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.DiscountOrder.Protobuf\BackOffice.BFF.DiscountOrder.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.DiscountCategory.Protobuf\BackOffice.BFF.DiscountCategory.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.DiscountShoppingCart.Protobuf\BackOffice.BFF.DiscountShoppingCart.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.Tag.Protobuf\BackOffice.BFF.Tag.Protobuf.csproj" />
<ProjectReference Include="..\Protobufs\BackOffice.BFF.ProductTag.Protobuf\BackOffice.BFF.ProductTag.Protobuf.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
@@ -0,0 +1,38 @@
using BackOffice.BFF.DiscountCategory.Protobuf.Protos.DiscountCategory;
using BackOffice.BFF.WebApi.Common.Services;
using BackOffice.BFF.Application.DiscountCategoryCQ.Commands.CreateDiscountCategory;
using BackOffice.BFF.Application.DiscountCategoryCQ.Commands.UpdateDiscountCategory;
using BackOffice.BFF.Application.DiscountCategoryCQ.Commands.DeleteDiscountCategory;
using BackOffice.BFF.Application.DiscountCategoryCQ.Queries.GetDiscountCategories;
namespace BackOffice.BFF.WebApi.Services;
public class DiscountCategoryService : DiscountCategoryContract.DiscountCategoryContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public DiscountCategoryService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
public override async Task<CreateDiscountCategoryResponse> CreateDiscountCategory(CreateDiscountCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateDiscountCategoryRequest, CreateDiscountCategoryCommand, CreateDiscountCategoryResponse>(request, context);
}
public override async Task<Empty> UpdateDiscountCategory(UpdateDiscountCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateDiscountCategoryRequest, UpdateDiscountCategoryCommand>(request, context);
}
public override async Task<Empty> DeleteDiscountCategory(DeleteDiscountCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeleteDiscountCategoryRequest, DeleteDiscountCategoryCommand>(request, context);
}
public override async Task<GetDiscountCategoriesResponse> GetDiscountCategories(GetDiscountCategoriesRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetDiscountCategoriesRequest, GetDiscountCategoriesQuery, GetDiscountCategoriesResponse>(request, context);
}
}
@@ -0,0 +1,59 @@
using BackOffice.BFF.DiscountOrder.Protobuf.Protos.DiscountOrder;
using BackOffice.BFF.WebApi.Common.Services;
using BackOffice.BFF.Application.DiscountOrderCQ.Commands.PlaceOrder;
using BackOffice.BFF.Application.DiscountOrderCQ.Commands.CompleteOrderPayment;
using BackOffice.BFF.Application.DiscountOrderCQ.Commands.UpdateOrderStatus;
using BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetOrderById;
using BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetUserOrders;
using BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetAllDiscountOrders;
using BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetDiscountSalesReport;
namespace BackOffice.BFF.WebApi.Services;
public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public DiscountOrderService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
// Order Management
public override async Task<PlaceOrderResponse> PlaceOrder(PlaceOrderRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<PlaceOrderRequest, PlaceOrderCommand, PlaceOrderResponse>(request, context);
}
public override async Task<CompleteOrderPaymentResponse> CompleteOrderPayment(CompleteOrderPaymentRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CompleteOrderPaymentRequest, CompleteOrderPaymentCommand, CompleteOrderPaymentResponse>(request, context);
}
public override async Task<UpdateOrderStatusResponse> UpdateOrderStatus(UpdateOrderStatusRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateOrderStatusRequest, UpdateOrderStatusCommand, UpdateOrderStatusResponse>(request, context);
}
// Order Queries
public override async Task<GetOrderByIdResponse> GetOrderById(GetOrderByIdRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetOrderByIdRequest, GetOrderByIdQuery, GetOrderByIdResponse>(request, context);
}
public override async Task<GetUserOrdersResponse> GetUserOrders(GetUserOrdersRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetUserOrdersRequest, GetUserOrdersQuery, GetUserOrdersResponse>(request, context);
}
// Admin APIs
public override async Task<GetAllDiscountOrdersResponse> GetAllDiscountOrders(GetAllDiscountOrdersRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllDiscountOrdersRequest, GetAllDiscountOrdersQuery, GetAllDiscountOrdersResponse>(request, context);
}
public override async Task<GetDiscountSalesReportResponse> GetDiscountSalesReport(GetDiscountSalesReportRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetDiscountSalesReportRequest, GetDiscountSalesReportQuery, GetDiscountSalesReportResponse>(request, context);
}
}
@@ -0,0 +1,76 @@
using BackOffice.BFF.DiscountProduct.Protobuf.Protos.DiscountProduct;
using BackOffice.BFF.WebApi.Common.Services;
using BackOffice.BFF.Application.DiscountProductCQ.Commands.CreateDiscountProduct;
using BackOffice.BFF.Application.DiscountProductCQ.Commands.UpdateDiscountProduct;
using BackOffice.BFF.Application.DiscountProductCQ.Commands.DeleteDiscountProduct;
using BackOffice.BFF.Application.DiscountProductCQ.Commands.AddDiscountProductImage;
using BackOffice.BFF.Application.DiscountProductCQ.Commands.UpdateDiscountProductImage;
using BackOffice.BFF.Application.DiscountProductCQ.Commands.DeleteDiscountProductImage;
using BackOffice.BFF.Application.DiscountProductCQ.Commands.ReorderDiscountProductImages;
using BackOffice.BFF.Application.DiscountProductCQ.Queries.GetDiscountProductById;
using BackOffice.BFF.Application.DiscountProductCQ.Queries.GetDiscountProducts;
using BackOffice.BFF.Application.DiscountProductCQ.Queries.GetDiscountProductImages;
namespace BackOffice.BFF.WebApi.Services;
public class DiscountProductService : DiscountProductContract.DiscountProductContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public DiscountProductService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
// Product CRUD
public override async Task<CreateDiscountProductResponse> CreateDiscountProduct(CreateDiscountProductRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateDiscountProductRequest, CreateDiscountProductCommand, CreateDiscountProductResponse>(request, context);
}
public override async Task<Empty> UpdateDiscountProduct(UpdateDiscountProductRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateDiscountProductRequest, UpdateDiscountProductCommand>(request, context);
}
public override async Task<Empty> DeleteDiscountProduct(DeleteDiscountProductRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeleteDiscountProductRequest, DeleteDiscountProductCommand>(request, context);
}
public override async Task<GetDiscountProductByIdResponse> GetDiscountProductById(GetDiscountProductByIdRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetDiscountProductByIdRequest, GetDiscountProductByIdQuery, GetDiscountProductByIdResponse>(request, context);
}
public override async Task<GetDiscountProductsResponse> GetDiscountProducts(GetDiscountProductsRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetDiscountProductsRequest, GetDiscountProductsQuery, GetDiscountProductsResponse>(request, context);
}
// Product Image Gallery
public override async Task<AddDiscountProductImageResponse> AddDiscountProductImage(AddDiscountProductImageRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<AddDiscountProductImageRequest, AddDiscountProductImageCommand, AddDiscountProductImageResponse>(request, context);
}
public override async Task<Empty> UpdateDiscountProductImage(UpdateDiscountProductImageRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateDiscountProductImageRequest, UpdateDiscountProductImageCommand>(request, context);
}
public override async Task<Empty> DeleteDiscountProductImage(DeleteDiscountProductImageRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeleteDiscountProductImageRequest, DeleteDiscountProductImageCommand>(request, context);
}
public override async Task<Empty> ReorderDiscountProductImages(ReorderDiscountProductImagesRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<ReorderDiscountProductImagesRequest, ReorderDiscountProductImagesCommand>(request, context);
}
public override async Task<GetDiscountProductImagesResponse> GetDiscountProductImages(GetDiscountProductImagesRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetDiscountProductImagesRequest, GetDiscountProductImagesQuery, GetDiscountProductImagesResponse>(request, context);
}
}
@@ -0,0 +1,44 @@
using BackOffice.BFF.DiscountShoppingCart.Protobuf.Protos.DiscountShoppingCart;
using BackOffice.BFF.WebApi.Common.Services;
using BackOffice.BFF.Application.DiscountShoppingCartCQ.Commands.AddToCart;
using BackOffice.BFF.Application.DiscountShoppingCartCQ.Commands.RemoveFromCart;
using BackOffice.BFF.Application.DiscountShoppingCartCQ.Commands.UpdateCartItemCount;
using BackOffice.BFF.Application.DiscountShoppingCartCQ.Commands.ClearCart;
using BackOffice.BFF.Application.DiscountShoppingCartCQ.Queries.GetUserCart;
namespace BackOffice.BFF.WebApi.Services;
public class DiscountShoppingCartService : DiscountShoppingCartContract.DiscountShoppingCartContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public DiscountShoppingCartService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
public override async Task<AddToCartResponse> AddToCart(AddToCartRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<AddToCartRequest, AddToCartCommand, AddToCartResponse>(request, context);
}
public override async Task<RemoveFromCartResponse> RemoveFromCart(RemoveFromCartRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<RemoveFromCartRequest, RemoveFromCartCommand, RemoveFromCartResponse>(request, context);
}
public override async Task<UpdateCartItemCountResponse> UpdateCartItemCount(UpdateCartItemCountRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateCartItemCountRequest, UpdateCartItemCountCommand, UpdateCartItemCountResponse>(request, context);
}
public override async Task<GetUserCartResponse> GetUserCart(GetUserCartRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetUserCartRequest, GetUserCartQuery, GetUserCartResponse>(request, context);
}
public override async Task<Empty> ClearCart(ClearCartRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<ClearCartRequest, ClearCartCommand>(request, context);
}
}
@@ -0,0 +1,44 @@
using BackOffice.BFF.ProductTag.Protobuf.Protos.ProductTag;
using BackOffice.BFF.WebApi.Common.Services;
using BackOffice.BFF.Application.ProductTagCQ.Commands.AssignTagToProduct;
using BackOffice.BFF.Application.ProductTagCQ.Commands.UpdateProductTag;
using BackOffice.BFF.Application.ProductTagCQ.Commands.DeleteProductTag;
using BackOffice.BFF.Application.ProductTagCQ.Queries.GetProductTag;
using BackOffice.BFF.Application.ProductTagCQ.Queries.GetAllProductTags;
namespace BackOffice.BFF.WebApi.Services;
public class ProductTagService : ProductTagContract.ProductTagContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public ProductTagService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
public override async Task<CreateNewProductTagResponse> CreateNewProductTag(CreateNewProductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateNewProductTagRequest, AssignTagToProductCommand, CreateNewProductTagResponse>(request, context);
}
public override async Task<Empty> UpdateProductTag(UpdateProductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateProductTagRequest, UpdateProductTagCommand>(request, context);
}
public override async Task<Empty> DeleteProductTag(DeleteProductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeleteProductTagRequest, DeleteProductTagCommand>(request, context);
}
public override async Task<GetProductTagResponse> GetProductTag(GetProductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetProductTagRequest, GetProductTagQuery, GetProductTagResponse>(request, context);
}
public override async Task<GetAllProductTagByFilterResponse> GetAllProductTagByFilter(GetAllProductTagByFilterRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllProductTagByFilterRequest, GetAllProductTagsQuery, GetAllProductTagByFilterResponse>(request, context);
}
}
@@ -0,0 +1,50 @@
using BackOffice.BFF.Tag.Protobuf.Protos.Tag;
using BackOffice.BFF.WebApi.Common.Services;
using BackOffice.BFF.Application.TagCQ.Commands.CreateTag;
using BackOffice.BFF.Application.TagCQ.Commands.UpdateTag;
using BackOffice.BFF.Application.TagCQ.Commands.DeleteTag;
using BackOffice.BFF.Application.TagCQ.Queries.GetTag;
using BackOffice.BFF.Application.TagCQ.Queries.GetAllTags;
using BackOffice.BFF.Application.TagCQ.Queries.GetProductsByTag;
namespace BackOffice.BFF.WebApi.Services;
public class TagService : TagContract.TagContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public TagService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
public override async Task<CreateNewTagResponse> CreateNewTag(CreateNewTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateNewTagRequest, CreateTagCommand, CreateNewTagResponse>(request, context);
}
public override async Task<Empty> UpdateTag(UpdateTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateTagRequest, UpdateTagCommand>(request, context);
}
public override async Task<Empty> DeleteTag(DeleteTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeleteTagRequest, DeleteTagCommand>(request, context);
}
public override async Task<GetTagResponse> GetTag(GetTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetTagRequest, GetTagQuery, GetTagResponse>(request, context);
}
public override async Task<GetAllTagByFilterResponse> GetAllTagByFilter(GetAllTagByFilterRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllTagByFilterRequest, GetAllTagsQuery, GetAllTagByFilterResponse>(request, context);
}
public override async Task<GetProductsByTagResponse> GetProductsByTag(GetProductsByTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetProductsByTagRequest, GetProductsByTagQuery, GetProductsByTagResponse>(request, context);
}
}
@@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\discountcategory.proto" ProtoRoot="Protos\" GrpcServices="Client" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
<Protobuf Include="Protos\discountcategory.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
</ItemGroup>
<ItemGroup>
@@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\discountorder.proto" ProtoRoot="Protos\" GrpcServices="Client" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
<Protobuf Include="Protos\discountorder.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
</ItemGroup>
<ItemGroup>
@@ -40,6 +40,20 @@ service DiscountOrderContract
get: "/GetUserOrders"
};
};
// Admin: Get All Discount Orders with filters
rpc GetAllDiscountOrders(GetAllDiscountOrdersRequest) returns (GetAllDiscountOrdersResponse){
option (google.api.http) = {
get: "/GetAllDiscountOrders"
};
};
// Admin: Get Sales Report
rpc GetDiscountSalesReport(GetDiscountSalesReportRequest) returns (GetDiscountSalesReportResponse){
option (google.api.http) = {
get: "/GetDiscountSalesReport"
};
};
}
// Place Order (Initial Step - Create Order)
@@ -175,3 +189,118 @@ message OrderSummaryDto
int32 items_count = 9;
google.protobuf.Timestamp created = 10;
}
// ===== Admin: Get All Discount Orders =====
message GetAllDiscountOrdersRequest
{
google.protobuf.Int64Value user_id = 1;
google.protobuf.Int32Value payment_status = 2;
google.protobuf.Int32Value delivery_status = 3;
google.protobuf.StringValue user_mobile = 4;
google.protobuf.StringValue tracking_code = 5;
google.protobuf.Timestamp from_date = 6;
google.protobuf.Timestamp to_date = 7;
google.protobuf.Int64Value min_amount = 8;
google.protobuf.Int64Value max_amount = 9;
int32 page_number = 10;
int32 page_size = 11;
}
message GetAllDiscountOrdersResponse
{
messages.MetaData meta_data = 1;
repeated AdminOrderDto models = 2;
}
message AdminOrderDto
{
int64 id = 1;
int64 user_id = 2;
string user_full_name = 3;
string user_mobile = 4;
int64 total_amount = 5;
int64 discount_balance_used = 6;
int64 gateway_amount_paid = 7;
int64 vat_amount = 8;
PaymentStatus payment_status = 9;
google.protobuf.Timestamp payment_date = 10;
DeliveryStatus delivery_status = 11;
google.protobuf.Timestamp delivery_date = 12;
google.protobuf.StringValue shipping_address = 13;
google.protobuf.StringValue receiver_name = 14;
google.protobuf.StringValue receiver_mobile = 15;
google.protobuf.StringValue tracking_code = 16;
google.protobuf.StringValue admin_note = 17;
google.protobuf.Timestamp created = 18;
google.protobuf.Timestamp last_modified = 19;
int32 items_count = 20;
}
enum PaymentStatus
{
PAYMENT_PENDING = 0;
PAYMENT_COMPLETED = 1;
PAYMENT_FAILED = 2;
PAYMENT_REFUNDED = 3;
}
// ===== Sales Report Messages =====
enum SalesReportType
{
REPORT_SUMMARY = 0;
REPORT_DAILY = 1;
REPORT_WEEKLY = 2;
REPORT_MONTHLY = 3;
}
message GetDiscountSalesReportRequest
{
google.protobuf.Timestamp from_date = 1;
google.protobuf.Timestamp to_date = 2;
SalesReportType report_type = 3;
}
message GetDiscountSalesReportResponse
{
SalesSummary summary = 1;
repeated SalesPeriodDto periods = 2;
repeated TopSellingProductDto top_products = 3;
}
message SalesSummary
{
int32 total_orders = 1;
int32 completed_orders = 2;
int32 pending_orders = 3;
int32 cancelled_orders = 4;
int64 total_sales_amount = 5;
int64 total_discount_used = 6;
int64 total_gateway_paid = 7;
int64 total_vat_amount = 8;
int64 average_order_value = 9;
int32 unique_customers = 10;
int32 total_products_sold = 11;
}
message SalesPeriodDto
{
string period_label = 1;
google.protobuf.Timestamp period_start = 2;
google.protobuf.Timestamp period_end = 3;
int32 orders_count = 4;
int64 total_amount = 5;
int64 discount_used = 6;
int64 gateway_paid = 7;
}
message TopSellingProductDto
{
int64 product_id = 1;
string product_title = 2;
google.protobuf.StringValue image_path = 3;
int32 quantity_sold = 4;
int64 total_revenue = 5;
int32 orders_count = 6;
}
@@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\discountproduct.proto" ProtoRoot="Protos\" GrpcServices="Client" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
<Protobuf Include="Protos\discountproduct.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
</ItemGroup>
<ItemGroup>
@@ -40,6 +40,37 @@ service DiscountProductContract
get: "/GetDiscountProducts"
};
};
// Product Image Gallery Operations
rpc AddDiscountProductImage(AddDiscountProductImageRequest) returns (AddDiscountProductImageResponse){
option (google.api.http) = {
post: "/AddDiscountProductImage"
body: "*"
};
};
rpc UpdateDiscountProductImage(UpdateDiscountProductImageRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
put: "/UpdateDiscountProductImage"
body: "*"
};
};
rpc DeleteDiscountProductImage(DeleteDiscountProductImageRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
delete: "/DeleteDiscountProductImage"
body: "*"
};
};
rpc ReorderDiscountProductImages(ReorderDiscountProductImagesRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
put: "/ReorderDiscountProductImages"
body: "*"
};
};
rpc GetDiscountProductImages(GetDiscountProductImagesRequest) returns (GetDiscountProductImagesResponse){
option (google.api.http) = {
get: "/GetDiscountProductImages"
};
};
}
// Create Product
@@ -150,3 +181,68 @@ message DiscountProductDto
bool is_active = 10;
google.protobuf.Timestamp created = 11;
}
// ===== Product Image Gallery Messages =====
// Add Product Image
message AddDiscountProductImageRequest
{
int64 discount_product_id = 1;
string image_path = 2;
string thumbnail_path = 3;
google.protobuf.StringValue title = 4;
google.protobuf.StringValue alt_text = 5;
}
message AddDiscountProductImageResponse
{
int64 image_id = 1;
}
// Update Product Image
message UpdateDiscountProductImageRequest
{
int64 id = 1;
string image_path = 2;
string thumbnail_path = 3;
google.protobuf.StringValue title = 4;
google.protobuf.StringValue alt_text = 5;
bool is_active = 6;
}
// Delete Product Image
message DeleteDiscountProductImageRequest
{
int64 id = 1;
}
// Reorder Product Images
message ReorderDiscountProductImagesRequest
{
int64 discount_product_id = 1;
repeated int64 image_ids = 2;
}
// Get Product Images
message GetDiscountProductImagesRequest
{
int64 discount_product_id = 1;
bool only_active = 2;
}
message GetDiscountProductImagesResponse
{
repeated DiscountProductImageDto images = 1;
}
message DiscountProductImageDto
{
int64 id = 1;
int64 discount_product_id = 2;
string image_path = 3;
string thumbnail_path = 4;
google.protobuf.StringValue title = 5;
google.protobuf.StringValue alt_text = 6;
int32 sort_order = 7;
bool is_active = 8;
}
@@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\discountshoppingcart.proto" ProtoRoot="Protos\" GrpcServices="Client" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
<Protobuf Include="Protos\discountshoppingcart.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
</ItemGroup>
<ItemGroup>
@@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\producttag.proto" ProtoRoot="Protos\" GrpcServices="Client" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
<Protobuf Include="Protos\producttag.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
</ItemGroup>
<ItemGroup>
@@ -4,7 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.4</Version>
<Version>0.0.5</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\tag.proto" ProtoRoot="Protos\" GrpcServices="Client" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
<Protobuf Include="Protos\tag.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
</ItemGroup>
<ItemGroup>