Add validators and services for Product Galleries and Product Tags

- Implemented Create, Delete, Get, and Update validators for Product Galleries.
- Added Create, Delete, Get, and Update validators for Product Tags.
- Created service classes for handling Discount Categories, Discount Orders, Discount Products, Discount Shopping Cart, Product Categories, Product Galleries, and Product Tags.
- Each service class integrates with CQRS for command and query handling.
- Established mapping profiles for Product Galleries.
This commit is contained in:
masoodafar-web
2025-12-04 02:40:49 +03:30
parent 40d54d08fc
commit f0f48118e7
436 changed files with 33159 additions and 2005 deletions

View File

@@ -4,12 +4,12 @@ using CMSMicroservice.Domain.Enums;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.PackageCQ.Commands.PurchaseGoldenPackage;
namespace CMSMicroservice.Application.PackageCQ.Commands.PurchasePackage;
/// <summary>
/// دستور خرید پکیج طلایی از طریق درگاه بانکی
/// دستور خرید پکیج از طریق درگاه بانکی
/// </summary>
public class PurchaseGoldenPackageCommand : IRequest<PaymentInitiateResult>
public class PurchasePackageCommand : IRequest<PaymentInitiateResult>
{
/// <summary>
/// شناسه کاربر

View File

@@ -8,19 +8,19 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ValidationException = FluentValidation.ValidationException;
namespace CMSMicroservice.Application.PackageCQ.Commands.PurchaseGoldenPackage;
namespace CMSMicroservice.Application.PackageCQ.Commands.PurchasePackage;
public class PurchaseGoldenPackageCommandHandler
: IRequestHandler<PurchaseGoldenPackageCommand, PaymentInitiateResult>
public class PurchasePackageCommandHandler
: IRequestHandler<PurchasePackageCommand, PaymentInitiateResult>
{
private readonly IApplicationDbContext _context;
private readonly IPaymentGatewayService _paymentGateway;
private readonly ILogger<PurchaseGoldenPackageCommandHandler> _logger;
private readonly ILogger<PurchasePackageCommandHandler> _logger;
public PurchaseGoldenPackageCommandHandler(
public PurchasePackageCommandHandler(
IApplicationDbContext context,
IPaymentGatewayService paymentGateway,
ILogger<PurchaseGoldenPackageCommandHandler> logger)
ILogger<PurchasePackageCommandHandler> logger)
{
_context = context;
_paymentGateway = paymentGateway;
@@ -28,13 +28,13 @@ public class PurchaseGoldenPackageCommandHandler
}
public async Task<PaymentInitiateResult> Handle(
PurchaseGoldenPackageCommand request,
PurchasePackageCommand request,
CancellationToken cancellationToken)
{
try
{
_logger.LogInformation(
"Starting golden package purchase for UserId: {UserId}",
"Starting package purchase for UserId: {UserId}",
request.UserId
);
@@ -57,11 +57,11 @@ public class PurchaseGoldenPackageCommandHandler
user.PackagePurchaseMethod
);
throw new ValidationException(
"شما قبلاً پکیج طلایی را خریداری کرده‌اید"
"شما قبلاً پکیج را خریداری کرده‌اید"
);
}
// 3. پیدا کردن پکیج طلایی
// 3. پیدا کردن پکیج (فعلاً پکیج طلایی)
var goldenPackage = await _context.Packages
.FirstOrDefaultAsync(
p => p.Title.Contains("طلایی") || p.Title.Contains("Golden"),
@@ -70,12 +70,12 @@ public class PurchaseGoldenPackageCommandHandler
if (goldenPackage == null)
{
_logger.LogError("Golden package not found in database");
throw new NotFoundException("پکیج طلایی یافت نشد");
_logger.LogError("Package not found in database");
throw new NotFoundException("پکیج یافت نشد");
}
// 4. پیدا کردن آدرس پیش‌فرض کاربر (برای فیلد اجباری)
var defaultAddress = await _context.UserAddresss
var defaultAddress = await _context.UserAddresses
.Where(a => a.UserId == request.UserId)
.OrderByDescending(a => a.Created)
.FirstOrDefaultAsync(cancellationToken);
@@ -116,8 +116,8 @@ public class PurchaseGoldenPackageCommandHandler
Amount = order.Amount,
UserId = user.Id,
Mobile = user.Mobile ?? "",
CallbackUrl = $"https://yourdomain.com/api/package/verify-golden-package",
Description = $"خرید پکیج طلایی - سفارش #{order.Id}"
CallbackUrl = $"https://yourdomain.com/api/package/verify-package",
Description = $"خرید پکیج - سفارش #{order.Id}"
};
var paymentResult = await _paymentGateway.InitiatePaymentAsync(paymentRequest);
@@ -151,7 +151,7 @@ public class PurchaseGoldenPackageCommandHandler
{
_logger.LogError(
ex,
"Error in PurchaseGoldenPackageCommand for UserId: {UserId}",
"Error in PurchasePackageCommand for UserId: {UserId}",
request.UserId
);
throw;

View File

@@ -1,10 +1,10 @@
using FluentValidation;
namespace CMSMicroservice.Application.PackageCQ.Commands.PurchaseGoldenPackage;
namespace CMSMicroservice.Application.PackageCQ.Commands.PurchasePackage;
public class PurchaseGoldenPackageCommandValidator : AbstractValidator<PurchaseGoldenPackageCommand>
public class PurchasePackageCommandValidator : AbstractValidator<PurchasePackageCommand>
{
public PurchaseGoldenPackageCommandValidator()
public PurchasePackageCommandValidator()
{
RuleFor(x => x.UserId)
.GreaterThan(0)

View File

@@ -2,12 +2,12 @@ using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Models;
using MediatR;
namespace CMSMicroservice.Application.PackageCQ.Commands.VerifyGoldenPackagePurchase;
namespace CMSMicroservice.Application.PackageCQ.Commands.VerifyPackagePurchase;
/// <summary>
/// دستور تأیید پرداخت پکیج طلایی و شارژ کیف پول
/// دستور تأیید پرداخت پکیج و شارژ کیف پول
/// </summary>
public class VerifyGoldenPackagePurchaseCommand : IRequest<bool>
public class VerifyPackagePurchaseCommand : IRequest<bool>
{
/// <summary>
/// شناسه سفارش

View File

@@ -8,19 +8,19 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ValidationException = FluentValidation.ValidationException;
namespace CMSMicroservice.Application.PackageCQ.Commands.VerifyGoldenPackagePurchase;
namespace CMSMicroservice.Application.PackageCQ.Commands.VerifyPackagePurchase;
public class VerifyGoldenPackagePurchaseCommandHandler
: IRequestHandler<VerifyGoldenPackagePurchaseCommand, bool>
public class VerifyPackagePurchaseCommandHandler
: IRequestHandler<VerifyPackagePurchaseCommand, bool>
{
private readonly IApplicationDbContext _context;
private readonly IPaymentGatewayService _paymentGateway;
private readonly ILogger<VerifyGoldenPackagePurchaseCommandHandler> _logger;
private readonly ILogger<VerifyPackagePurchaseCommandHandler> _logger;
public VerifyGoldenPackagePurchaseCommandHandler(
public VerifyPackagePurchaseCommandHandler(
IApplicationDbContext context,
IPaymentGatewayService paymentGateway,
ILogger<VerifyGoldenPackagePurchaseCommandHandler> logger)
ILogger<VerifyPackagePurchaseCommandHandler> logger)
{
_context = context;
_paymentGateway = paymentGateway;
@@ -28,13 +28,13 @@ public class VerifyGoldenPackagePurchaseCommandHandler
}
public async Task<bool> Handle(
VerifyGoldenPackagePurchaseCommand request,
VerifyPackagePurchaseCommand request,
CancellationToken cancellationToken)
{
try
{
_logger.LogInformation(
"Verifying golden package purchase. OrderId: {OrderId}, Authority: {Authority}",
"Verifying package purchase. OrderId: {OrderId}, Authority: {Authority}",
request.OrderId,
request.Authority
);
@@ -111,17 +111,17 @@ public class VerifyGoldenPackagePurchaseCommandHandler
);
// 5. ثبت Transaction
var transaction = new Transactions
var transaction = new Transaction
{
Amount = order.Amount,
Description = $"خرید پکیج طلایی از درگاه - سفارش #{order.Id}",
Description = $"خرید پکیج از درگاه - سفارش #{order.Id}",
PaymentStatus = PaymentStatus.Success,
PaymentDate = DateTime.UtcNow,
RefId = verifyResult.RefId,
Type = TransactionType.DepositIpg
};
_context.Transactionss.Add(transaction);
_context.Transactions.Add(transaction);
await _context.SaveChangesAsync(cancellationToken);
// 6. ثبت لاگ تغییر Balance
@@ -166,7 +166,7 @@ public class VerifyGoldenPackagePurchaseCommandHandler
await _context.SaveChangesAsync(cancellationToken);
_logger.LogInformation(
"Golden package purchase verified successfully. " +
"Package purchase verified successfully. " +
"OrderId: {OrderId}, UserId: {UserId}, TransactionId: {TransactionId}, RefId: {RefId}",
order.Id,
order.UserId,
@@ -180,7 +180,7 @@ public class VerifyGoldenPackagePurchaseCommandHandler
{
_logger.LogError(
ex,
"Error in VerifyGoldenPackagePurchaseCommand. OrderId: {OrderId}",
"Error in VerifyPackagePurchaseCommand. OrderId: {OrderId}",
request.OrderId
);
throw;