Generator Changes at 9/27/2025 8:46:36 AM
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.CreateNewUserOrder;
|
||||
public record CreateNewUserOrderCommand : IRequest<CreateNewUserOrderResponseDto>
|
||||
{
|
||||
//قیمت
|
||||
public long Price { get; init; }
|
||||
//شناسه پکیج
|
||||
public long PackageId { get; init; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; init; }
|
||||
//وضعیت پرداخت
|
||||
public bool PaymentStatus { get; init; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; init; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.CreateNewUserOrder;
|
||||
public class CreateNewUserOrderCommandHandler : IRequestHandler<CreateNewUserOrderCommand, CreateNewUserOrderResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public CreateNewUserOrderCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<CreateNewUserOrderResponseDto> Handle(CreateNewUserOrderCommand request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = request.Adapt<UserOrder>();
|
||||
await _context.UserOrders.AddAsync(entity, cancellationToken);
|
||||
entity.AddDomainEvent(new CreateNewUserOrderEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return entity.Adapt<CreateNewUserOrderResponseDto>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.CreateNewUserOrder;
|
||||
public class CreateNewUserOrderCommandValidator : AbstractValidator<CreateNewUserOrderCommand>
|
||||
{
|
||||
public CreateNewUserOrderCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Price)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PackageId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PaymentStatus)
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateNewUserOrderCommand>.CreateWithOptions((CreateNewUserOrderCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.CreateNewUserOrder;
|
||||
public class CreateNewUserOrderResponseDto
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.DeleteUserOrder;
|
||||
public record DeleteUserOrderCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.DeleteUserOrder;
|
||||
public class DeleteUserOrderCommandHandler : IRequestHandler<DeleteUserOrderCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public DeleteUserOrderCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeleteUserOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.UserOrders
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserOrder), request.Id);
|
||||
entity.IsDeleted = true;
|
||||
_context.UserOrders.Update(entity);
|
||||
entity.AddDomainEvent(new DeleteUserOrderEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.DeleteUserOrder;
|
||||
public class DeleteUserOrderCommandValidator : AbstractValidator<DeleteUserOrderCommand>
|
||||
{
|
||||
public DeleteUserOrderCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<DeleteUserOrderCommand>.CreateWithOptions((DeleteUserOrderCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.UpdateUserOrder;
|
||||
public record UpdateUserOrderCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
//قیمت
|
||||
public long Price { get; init; }
|
||||
//شناسه پکیج
|
||||
public long PackageId { get; init; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; init; }
|
||||
//وضعیت پرداخت
|
||||
public bool PaymentStatus { get; init; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; init; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.UpdateUserOrder;
|
||||
public class UpdateUserOrderCommandHandler : IRequestHandler<UpdateUserOrderCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public UpdateUserOrderCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdateUserOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.UserOrders
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserOrder), request.Id);
|
||||
request.Adapt(entity);
|
||||
_context.UserOrders.Update(entity);
|
||||
entity.AddDomainEvent(new UpdateUserOrderEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Commands.UpdateUserOrder;
|
||||
public class UpdateUserOrderCommandValidator : AbstractValidator<UpdateUserOrderCommand>
|
||||
{
|
||||
public UpdateUserOrderCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
RuleFor(model => model.Price)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PackageId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PaymentStatus)
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateUserOrderCommand>.CreateWithOptions((UpdateUserOrderCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.EventHandlers;
|
||||
|
||||
public class CreateNewUserOrderEventHandler : INotificationHandler<CreateNewUserOrderEvent>
|
||||
{
|
||||
private readonly ILogger<CreateNewUserOrderEventHandler> _logger;
|
||||
|
||||
public CreateNewUserOrderEventHandler(ILogger<CreateNewUserOrderEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(CreateNewUserOrderEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.EventHandlers;
|
||||
|
||||
public class DeleteUserOrderEventHandler : INotificationHandler<DeleteUserOrderEvent>
|
||||
{
|
||||
private readonly ILogger<DeleteUserOrderEventHandler> _logger;
|
||||
|
||||
public DeleteUserOrderEventHandler(ILogger<DeleteUserOrderEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(DeleteUserOrderEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.EventHandlers;
|
||||
|
||||
public class UpdateUserOrderEventHandler : INotificationHandler<UpdateUserOrderEvent>
|
||||
{
|
||||
private readonly ILogger<UpdateUserOrderEventHandler> _logger;
|
||||
|
||||
public UpdateUserOrderEventHandler(ILogger<UpdateUserOrderEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(UpdateUserOrderEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetAllUserOrderByFilter;
|
||||
public record GetAllUserOrderByFilterQuery : IRequest<GetAllUserOrderByFilterResponseDto>
|
||||
{
|
||||
//موقعیت صفحه بندی
|
||||
public PaginationState? PaginationState { get; init; }
|
||||
//مرتب سازی بر اساس
|
||||
public string? SortBy { get; init; }
|
||||
//فیلتر
|
||||
public GetAllUserOrderByFilterFilter? Filter { get; init; }
|
||||
|
||||
}public class GetAllUserOrderByFilterFilter
|
||||
{
|
||||
//شناسه
|
||||
public long? Id { get; set; }
|
||||
//قیمت
|
||||
public long? Price { get; set; }
|
||||
//شناسه پکیج
|
||||
public long? PackageId { get; set; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; set; }
|
||||
//وضعیت پرداخت
|
||||
public bool? PaymentStatus { get; set; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long? UserId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetAllUserOrderByFilter;
|
||||
public class GetAllUserOrderByFilterQueryHandler : IRequestHandler<GetAllUserOrderByFilterQuery, GetAllUserOrderByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetAllUserOrderByFilterQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllUserOrderByFilterResponseDto> Handle(GetAllUserOrderByFilterQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.UserOrders
|
||||
.ApplyOrder(sortBy: request.SortBy)
|
||||
.AsNoTracking()
|
||||
.AsQueryable();
|
||||
if (request.Filter is not null)
|
||||
{
|
||||
query = query
|
||||
.Where(x => request.Filter.Id == null || x.Id == request.Filter.Id)
|
||||
.Where(x => request.Filter.Price == null || x.Price == request.Filter.Price)
|
||||
.Where(x => request.Filter.PackageId == null || x.PackageId == request.Filter.PackageId)
|
||||
.Where(x => request.Filter.TransactionId == null || x.TransactionId == request.Filter.TransactionId)
|
||||
.Where(x => request.Filter.PaymentStatus == null || x.PaymentStatus == request.Filter.PaymentStatus)
|
||||
.Where(x => request.Filter.PaymentDate == null || x.PaymentDate == request.Filter.PaymentDate)
|
||||
.Where(x => request.Filter.UserId == null || x.UserId == request.Filter.UserId)
|
||||
;
|
||||
}
|
||||
return new GetAllUserOrderByFilterResponseDto
|
||||
{
|
||||
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
|
||||
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
|
||||
.ProjectToType<GetAllUserOrderByFilterResponseModel>().ToListAsync(cancellationToken)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetAllUserOrderByFilter;
|
||||
public class GetAllUserOrderByFilterQueryValidator : AbstractValidator<GetAllUserOrderByFilterQuery>
|
||||
{
|
||||
public GetAllUserOrderByFilterQueryValidator()
|
||||
{
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetAllUserOrderByFilterQuery>.CreateWithOptions((GetAllUserOrderByFilterQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetAllUserOrderByFilter;
|
||||
public class GetAllUserOrderByFilterResponseDto
|
||||
{
|
||||
//متادیتا
|
||||
public MetaData MetaData { get; set; }
|
||||
//مدل خروجی
|
||||
public List<GetAllUserOrderByFilterResponseModel>? Models { get; set; }
|
||||
|
||||
}public class GetAllUserOrderByFilterResponseModel
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
//قیمت
|
||||
public long Price { get; set; }
|
||||
//شناسه پکیج
|
||||
public long PackageId { get; set; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; set; }
|
||||
//وضعیت پرداخت
|
||||
public bool PaymentStatus { get; set; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetUserOrder;
|
||||
public record GetUserOrderQuery : IRequest<GetUserOrderResponseDto>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetUserOrder;
|
||||
public class GetUserOrderQueryHandler : IRequestHandler<GetUserOrderQuery, GetUserOrderResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetUserOrderQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetUserOrderResponseDto> Handle(GetUserOrderQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.UserOrders
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.ProjectToType<GetUserOrderResponseDto>()
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return response ?? throw new NotFoundException(nameof(UserOrder), request.Id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetUserOrder;
|
||||
public class GetUserOrderQueryValidator : AbstractValidator<GetUserOrderQuery>
|
||||
{
|
||||
public GetUserOrderQueryValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetUserOrderQuery>.CreateWithOptions((GetUserOrderQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetUserOrder;
|
||||
public class GetUserOrderResponseDto
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
//قیمت
|
||||
public long Price { get; set; }
|
||||
//شناسه پکیج
|
||||
public long PackageId { get; set; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; set; }
|
||||
//وضعیت پرداخت
|
||||
public bool PaymentStatus { get; set; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user