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:
+18
@@ -0,0 +1,18 @@
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace CMSMicroservice.Application.DiscountShopCQ.Commands.UpdateOrderStatus;
|
||||
|
||||
public class UpdateOrderStatusCommand : IRequest<UpdateOrderStatusResponseDto>
|
||||
{
|
||||
public long OrderId { get; set; }
|
||||
public DeliveryStatus DeliveryStatus { get; set; }
|
||||
public string? TrackingCode { get; set; }
|
||||
public string? AdminNotes { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateOrderStatusResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CMSMicroservice.Application.DiscountShopCQ.Commands.UpdateOrderStatus;
|
||||
|
||||
public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatusCommand, UpdateOrderStatusResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public UpdateOrderStatusCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<UpdateOrderStatusResponseDto> Handle(UpdateOrderStatusCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var order = await _context.DiscountOrders
|
||||
.FirstOrDefaultAsync(o => o.Id == request.OrderId, cancellationToken);
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
return new UpdateOrderStatusResponseDto
|
||||
{
|
||||
Success = false,
|
||||
Message = "سفارش یافت نشد"
|
||||
};
|
||||
}
|
||||
|
||||
// بهروزرسانی وضعیت
|
||||
order.DeliveryStatus = request.DeliveryStatus;
|
||||
|
||||
if (!string.IsNullOrEmpty(request.TrackingCode))
|
||||
{
|
||||
order.TrackingCode = request.TrackingCode;
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateOrderStatusResponseDto
|
||||
{
|
||||
Success = true,
|
||||
Message = "وضعیت سفارش بهروزرسانی شد"
|
||||
};
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace CMSMicroservice.Application.DiscountShopCQ.Commands.UpdateOrderStatus;
|
||||
|
||||
public class UpdateOrderStatusCommandValidator : AbstractValidator<UpdateOrderStatusCommand>
|
||||
{
|
||||
public UpdateOrderStatusCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.OrderId)
|
||||
.GreaterThan(0).WithMessage("شناسه سفارش باید مثبت باشد");
|
||||
|
||||
RuleFor(x => x.DeliveryStatus)
|
||||
.IsInEnum().WithMessage("وضعیت ارسال نامعتبر است");
|
||||
|
||||
RuleFor(x => x.TrackingCode)
|
||||
.MaximumLength(50).WithMessage("کد رهگیری نباید بیشتر از 50 کاراکتر باشد")
|
||||
.When(x => !string.IsNullOrEmpty(x.TrackingCode));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user