Generator Changes at 11/16/2025 12:48:45 AM +03:30

This commit is contained in:
masoodafar-web
2025-11-16 00:53:15 +03:30
parent 974f3c788f
commit 0a649325f8
75 changed files with 1460 additions and 7 deletions
@@ -0,0 +1,13 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract;
public record CreateNewContractCommand : IRequest<CreateNewContractResponseDto>
{
//عنوان
public string Title { get; init; }
//توضیحات
public string Description { get; init; }
//متن قرارداد
public string HtmlContent { get; init; }
//نوع قرارداد
public UnknownEnumType Type { get; init; }
}
@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract;
public class CreateNewContractCommandHandler : IRequestHandler<CreateNewContractCommand, CreateNewContractResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewContractCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewContractResponseDto> Handle(CreateNewContractCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<Contract>();
await _context.Contracts.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewContractEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewContractResponseDto>();
}
}
@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract;
public class CreateNewContractCommandValidator : AbstractValidator<CreateNewContractCommand>
{
public CreateNewContractCommandValidator()
{
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.HtmlContent)
.NotEmpty();
RuleFor(model => model.Type)
.IsInEnum()
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewContractCommand>.CreateWithOptions((CreateNewContractCommand)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.ContractCQ.Commands.CreateNewContract;
public class CreateNewContractResponseDto
{
//شناسه
public long Id { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract;
public record DeleteContractCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract;
public class DeleteContractCommandHandler : IRequestHandler<DeleteContractCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteContractCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteContractCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Contracts
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Contract), request.Id);
entity.IsDeleted = true;
_context.Contracts.Update(entity);
entity.AddDomainEvent(new DeleteContractEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract;
public class DeleteContractCommandValidator : AbstractValidator<DeleteContractCommand>
{
public DeleteContractCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteContractCommand>.CreateWithOptions((DeleteContractCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,15 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.UpdateContract;
public record UpdateContractCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//عنوان
public string Title { get; init; }
//توضیحات
public string Description { get; init; }
//متن قرارداد
public string HtmlContent { get; init; }
//نوع قرارداد
public UnknownEnumType Type { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ContractCQ.Commands.UpdateContract;
public class UpdateContractCommandHandler : IRequestHandler<UpdateContractCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateContractCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateContractCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Contracts
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Contract), request.Id);
request.Adapt(entity);
_context.Contracts.Update(entity);
entity.AddDomainEvent(new UpdateContractEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,25 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.UpdateContract;
public class UpdateContractCommandValidator : AbstractValidator<UpdateContractCommand>
{
public UpdateContractCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.HtmlContent)
.NotEmpty();
RuleFor(model => model.Type)
.IsInEnum()
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateContractCommand>.CreateWithOptions((UpdateContractCommand)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.ContractCQ.EventHandlers;
public class CreateNewContractEventHandler : INotificationHandler<CreateNewContractEvent>
{
private readonly ILogger<
CreateNewContractEventHandler> _logger;
public CreateNewContractEventHandler(ILogger<CreateNewContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewContractEvent 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.ContractCQ.EventHandlers;
public class DeleteContractEventHandler : INotificationHandler<DeleteContractEvent>
{
private readonly ILogger<
DeleteContractEventHandler> _logger;
public DeleteContractEventHandler(ILogger<DeleteContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteContractEvent 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.ContractCQ.EventHandlers;
public class UpdateContractEventHandler : INotificationHandler<UpdateContractEvent>
{
private readonly ILogger<
UpdateContractEventHandler> _logger;
public UpdateContractEventHandler(ILogger<UpdateContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateContractEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter;
public record GetAllContractByFilterQuery : IRequest<GetAllContractByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllContractByFilterFilter? Filter { get; init; }
}public class GetAllContractByFilterFilter
{
//شناسه
public long? Id { get; set; }
//عنوان
public string? Title { get; set; }
//توضیحات
public string? Description { get; set; }
//متن قرارداد
public string? HtmlContent { get; set; }
//نوع قرارداد
public UnknownEnumType Type { get; set; }
}
@@ -0,0 +1,34 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter;
public class GetAllContractByFilterQueryHandler : IRequestHandler<GetAllContractByFilterQuery, GetAllContractByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllContractByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllContractByFilterResponseDto> Handle(GetAllContractByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.Contracts
.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.Title == null || x.Title.Contains(request.Filter.Title))
.Where(x => request.Filter.Description == null || x.Description.Contains(request.Filter.Description))
.Where(x => request.Filter.HtmlContent == null || x.HtmlContent.Contains(request.Filter.HtmlContent))
.Where(x => request.Filter.Type == null || x.Type == request.Filter.Type)
;
}
return new GetAllContractByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllContractByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}
@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter;
public class GetAllContractByFilterQueryValidator : AbstractValidator<GetAllContractByFilterQuery>
{
public GetAllContractByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllContractByFilterQuery>.CreateWithOptions((GetAllContractByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,21 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter;
public class GetAllContractByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllContractByFilterResponseModel>? Models { get; set; }
}public class GetAllContractByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string Description { get; set; }
//متن قرارداد
public string HtmlContent { get; set; }
//نوع قرارداد
public UnknownEnumType Type { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public record GetContractQuery : IRequest<GetContractResponseDto>
{
//شناسه
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public class GetContractQueryHandler : IRequestHandler<GetContractQuery, GetContractResponseDto>
{
private readonly IApplicationDbContext _context;
public GetContractQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetContractResponseDto> Handle(GetContractQuery request,
CancellationToken cancellationToken)
{
var response = await _context.Contracts
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetContractResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(Contract), request.Id);
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public class GetContractQueryValidator : AbstractValidator<GetContractQuery>
{
public GetContractQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetContractQuery>.CreateWithOptions((GetContractQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,15 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public class GetContractResponseDto
{
//شناسه
public long Id { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string Description { get; set; }
//متن قرارداد
public string HtmlContent { get; set; }
//نوع قرارداد
public UnknownEnumType Type { get; set; }
}