Generator Changes at 11/17/2025 11:53:47 PM +03:30
This commit is contained in:
@@ -7,6 +7,8 @@ public class CreateNewCategoryCommandValidator : AbstractValidator<CreateNewCate
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.Title)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.IsActive)
|
||||
.NotNull();
|
||||
RuleFor(model => model.SortOrder)
|
||||
.NotNull();
|
||||
}
|
||||
@@ -18,4 +20,3 @@ public class CreateNewCategoryCommandValidator : AbstractValidator<CreateNewCate
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ public class UpdateCategoryCommandValidator : AbstractValidator<UpdateCategoryCo
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.Title)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.IsActive)
|
||||
.NotNull();
|
||||
RuleFor(model => model.SortOrder)
|
||||
.NotNull();
|
||||
}
|
||||
@@ -20,4 +22,3 @@ public class UpdateCategoryCommandValidator : AbstractValidator<UpdateCategoryCo
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ public interface IApplicationDbContext
|
||||
{
|
||||
DbSet<UserAddress> UserAddresss { get; }
|
||||
DbSet<Package> Packages { get; }
|
||||
DbSet<Category> Categories { get; }
|
||||
DbSet<Role> Roles { get; }
|
||||
DbSet<Category> Categorys { get; }
|
||||
DbSet<UserRole> UserRoles { get; }
|
||||
DbSet<UserWallet> UserWallets { get; }
|
||||
DbSet<UserWalletChangeLog> UserWalletChangeLogs { get; }
|
||||
@@ -20,5 +20,6 @@ public interface IApplicationDbContext
|
||||
DbSet<OtpToken> OtpTokens { get; }
|
||||
DbSet<Contract> Contracts { get; }
|
||||
DbSet<UserContract> UserContracts { get; }
|
||||
DbSet<PruductCategory> PruductCategorys { get; }
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace CMSMicroservice.Application.Common.Mappings;
|
||||
|
||||
public class PruductCategoryProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
//config.NewConfig<Source,Destination>()
|
||||
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory;
|
||||
public record CreateNewPruductCategoryCommand : IRequest<CreateNewPruductCategoryResponseDto>
|
||||
{
|
||||
//شناسه محصول
|
||||
public string ProductId { get; init; }
|
||||
//شناسه دسته بندی
|
||||
public string CategoryId { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory;
|
||||
public class CreateNewPruductCategoryCommandHandler : IRequestHandler<CreateNewPruductCategoryCommand, CreateNewPruductCategoryResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public CreateNewPruductCategoryCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<CreateNewPruductCategoryResponseDto> Handle(CreateNewPruductCategoryCommand request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = request.Adapt<PruductCategory>();
|
||||
await _context.PruductCategorys.AddAsync(entity, cancellationToken);
|
||||
entity.AddDomainEvent(new CreateNewPruductCategoryEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return entity.Adapt<CreateNewPruductCategoryResponseDto>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory;
|
||||
public class CreateNewPruductCategoryCommandValidator : AbstractValidator<CreateNewPruductCategoryCommand>
|
||||
{
|
||||
public CreateNewPruductCategoryCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.ProductId)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.CategoryId)
|
||||
.NotEmpty();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateNewPruductCategoryCommand>.CreateWithOptions((CreateNewPruductCategoryCommand)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.PruductCategoryCQ.Commands.CreateNewPruductCategory;
|
||||
public class CreateNewPruductCategoryResponseDto
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory;
|
||||
public record DeletePruductCategoryCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory;
|
||||
public class DeletePruductCategoryCommandHandler : IRequestHandler<DeletePruductCategoryCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public DeletePruductCategoryCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeletePruductCategoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.PruductCategorys
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(PruductCategory), request.Id);
|
||||
entity.IsDeleted = true;
|
||||
_context.PruductCategorys.Update(entity);
|
||||
entity.AddDomainEvent(new DeletePruductCategoryEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory;
|
||||
public class DeletePruductCategoryCommandValidator : AbstractValidator<DeletePruductCategoryCommand>
|
||||
{
|
||||
public DeletePruductCategoryCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<DeletePruductCategoryCommand>.CreateWithOptions((DeletePruductCategoryCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory;
|
||||
public record UpdatePruductCategoryCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
//شناسه محصول
|
||||
public string ProductId { get; init; }
|
||||
//شناسه دسته بندی
|
||||
public string CategoryId { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory;
|
||||
public class UpdatePruductCategoryCommandHandler : IRequestHandler<UpdatePruductCategoryCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public UpdatePruductCategoryCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdatePruductCategoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.PruductCategorys
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(PruductCategory), request.Id);
|
||||
request.Adapt(entity);
|
||||
_context.PruductCategorys.Update(entity);
|
||||
entity.AddDomainEvent(new UpdatePruductCategoryEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory;
|
||||
public class UpdatePruductCategoryCommandValidator : AbstractValidator<UpdatePruductCategoryCommand>
|
||||
{
|
||||
public UpdatePruductCategoryCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
RuleFor(model => model.ProductId)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.CategoryId)
|
||||
.NotEmpty();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdatePruductCategoryCommand>.CreateWithOptions((UpdatePruductCategoryCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers;
|
||||
|
||||
public class CreateNewPruductCategoryEventHandler : INotificationHandler<CreateNewPruductCategoryEvent>
|
||||
{
|
||||
private readonly ILogger<
|
||||
CreateNewPruductCategoryEventHandler> _logger;
|
||||
|
||||
public CreateNewPruductCategoryEventHandler(ILogger<CreateNewPruductCategoryEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(CreateNewPruductCategoryEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers;
|
||||
|
||||
public class DeletePruductCategoryEventHandler : INotificationHandler<DeletePruductCategoryEvent>
|
||||
{
|
||||
private readonly ILogger<
|
||||
DeletePruductCategoryEventHandler> _logger;
|
||||
|
||||
public DeletePruductCategoryEventHandler(ILogger<DeletePruductCategoryEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(DeletePruductCategoryEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers;
|
||||
|
||||
public class UpdatePruductCategoryEventHandler : INotificationHandler<UpdatePruductCategoryEvent>
|
||||
{
|
||||
private readonly ILogger<
|
||||
UpdatePruductCategoryEventHandler> _logger;
|
||||
|
||||
public UpdatePruductCategoryEventHandler(ILogger<UpdatePruductCategoryEventHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Handle(UpdatePruductCategoryEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
|
||||
public record GetAllPruductCategoryByFilterQuery : IRequest<GetAllPruductCategoryByFilterResponseDto>
|
||||
{
|
||||
//موقعیت صفحه بندی
|
||||
public PaginationState? PaginationState { get; init; }
|
||||
//مرتب سازی بر اساس
|
||||
public string? SortBy { get; init; }
|
||||
//فیلتر
|
||||
public GetAllPruductCategoryByFilterFilter? Filter { get; init; }
|
||||
|
||||
}public class GetAllPruductCategoryByFilterFilter
|
||||
{
|
||||
//شناسه
|
||||
public long? Id { get; set; }
|
||||
//شناسه محصول
|
||||
public string? ProductId { get; set; }
|
||||
//شناسه دسته بندی
|
||||
public string? CategoryId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
|
||||
public class GetAllPruductCategoryByFilterQueryHandler : IRequestHandler<GetAllPruductCategoryByFilterQuery, GetAllPruductCategoryByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetAllPruductCategoryByFilterQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllPruductCategoryByFilterResponseDto> Handle(GetAllPruductCategoryByFilterQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.PruductCategorys
|
||||
.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.ProductId == null || x.ProductId.Contains(request.Filter.ProductId))
|
||||
.Where(x => request.Filter.CategoryId == null || x.CategoryId.Contains(request.Filter.CategoryId))
|
||||
;
|
||||
}
|
||||
return new GetAllPruductCategoryByFilterResponseDto
|
||||
{
|
||||
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
|
||||
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
|
||||
.ProjectToType<GetAllPruductCategoryByFilterResponseModel>().ToListAsync(cancellationToken)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
|
||||
public class GetAllPruductCategoryByFilterQueryValidator : AbstractValidator<GetAllPruductCategoryByFilterQuery>
|
||||
{
|
||||
public GetAllPruductCategoryByFilterQueryValidator()
|
||||
{
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetAllPruductCategoryByFilterQuery>.CreateWithOptions((GetAllPruductCategoryByFilterQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
|
||||
public class GetAllPruductCategoryByFilterResponseDto
|
||||
{
|
||||
//متادیتا
|
||||
public MetaData MetaData { get; set; }
|
||||
//مدل خروجی
|
||||
public List<GetAllPruductCategoryByFilterResponseModel>? Models { get; set; }
|
||||
|
||||
}public class GetAllPruductCategoryByFilterResponseModel
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
//شناسه محصول
|
||||
public string ProductId { get; set; }
|
||||
//شناسه دسته بندی
|
||||
public string CategoryId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory;
|
||||
public record GetPruductCategoryQuery : IRequest<GetPruductCategoryResponseDto>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory;
|
||||
public class GetPruductCategoryQueryHandler : IRequestHandler<GetPruductCategoryQuery, GetPruductCategoryResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetPruductCategoryQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetPruductCategoryResponseDto> Handle(GetPruductCategoryQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.PruductCategorys
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.ProjectToType<GetPruductCategoryResponseDto>()
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return response ?? throw new NotFoundException(nameof(PruductCategory), request.Id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory;
|
||||
public class GetPruductCategoryQueryValidator : AbstractValidator<GetPruductCategoryQuery>
|
||||
{
|
||||
public GetPruductCategoryQueryValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetPruductCategoryQuery>.CreateWithOptions((GetPruductCategoryQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory;
|
||||
public class GetPruductCategoryResponseDto
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
//شناسه محصول
|
||||
public string ProductId { get; set; }
|
||||
//شناسه دسته بندی
|
||||
public string CategoryId { get; set; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user