diff --git a/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs b/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs index d7bcc7b..cfbc275 100644 --- a/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs +++ b/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs @@ -6,8 +6,6 @@ public interface IApplicationDbContext DbSet Packages { get; } DbSet Roles { get; } DbSet UserRoles { get; } - DbSet OtpTokens { get; } - DbSet Users { get; } DbSet UserWallets { get; } DbSet UserWalletChangeLogs { get; } DbSet UserCartss { get; } @@ -17,5 +15,9 @@ public interface IApplicationDbContext DbSet Productss { get; } DbSet ProductImagess { get; } DbSet Transactionss { get; } + DbSet Users { get; } + DbSet OtpTokens { get; } + DbSet Contracts { get; } + DbSet UserContracts { get; } Task SaveChangesAsync(CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/CMSMicroservice.Application/Common/Mappings/ContractProfile.cs b/src/CMSMicroservice.Application/Common/Mappings/ContractProfile.cs new file mode 100644 index 0000000..304e2ae --- /dev/null +++ b/src/CMSMicroservice.Application/Common/Mappings/ContractProfile.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.Application.Common.Mappings; + +public class ContractProfile : IRegister +{ + void IRegister.Register(TypeAdapterConfig config) + { + //config.NewConfig() + // .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}"); + } +} diff --git a/src/CMSMicroservice.Application/Common/Mappings/UserContractProfile.cs b/src/CMSMicroservice.Application/Common/Mappings/UserContractProfile.cs new file mode 100644 index 0000000..a72e1d6 --- /dev/null +++ b/src/CMSMicroservice.Application/Common/Mappings/UserContractProfile.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.Application.Common.Mappings; + +public class UserContractProfile : IRegister +{ + void IRegister.Register(TypeAdapterConfig config) + { + //config.NewConfig() + // .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}"); + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommand.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommand.cs new file mode 100644 index 0000000..725bea9 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommand.cs @@ -0,0 +1,13 @@ +namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract; +public record CreateNewContractCommand : IRequest +{ + //عنوان + public string Title { get; init; } + //توضیحات + public string Description { get; init; } + //متن قرارداد + public string HtmlContent { get; init; } + //نوع قرارداد + public UnknownEnumType Type { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommandHandler.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommandHandler.cs new file mode 100644 index 0000000..87f5f48 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommandHandler.cs @@ -0,0 +1,21 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract; +public class CreateNewContractCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public CreateNewContractCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(CreateNewContractCommand request, + CancellationToken cancellationToken) + { + var entity = request.Adapt(); + await _context.Contracts.AddAsync(entity, cancellationToken); + entity.AddDomainEvent(new CreateNewContractEvent(entity)); + await _context.SaveChangesAsync(cancellationToken); + return entity.Adapt(); + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommandValidator.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommandValidator.cs new file mode 100644 index 0000000..5e5d6c1 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractCommandValidator.cs @@ -0,0 +1,23 @@ +namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract; +public class CreateNewContractCommandValidator : AbstractValidator +{ + 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>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateNewContractCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractResponseDto.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractResponseDto.cs new file mode 100644 index 0000000..8ca9147 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/CreateNewContract/CreateNewContractResponseDto.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract; +public class CreateNewContractResponseDto +{ + //شناسه + public long Id { get; set; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommand.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommand.cs new file mode 100644 index 0000000..1f5149f --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommand.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract; +public record DeleteContractCommand : IRequest +{ + //شناسه + public long Id { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommandHandler.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommandHandler.cs new file mode 100644 index 0000000..be21830 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommandHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract; +public class DeleteContractCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public DeleteContractCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task 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; + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommandValidator.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommandValidator.cs new file mode 100644 index 0000000..0135457 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/DeleteContract/DeleteContractCommandValidator.cs @@ -0,0 +1,16 @@ +namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract; +public class DeleteContractCommandValidator : AbstractValidator +{ + public DeleteContractCommandValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((DeleteContractCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommand.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommand.cs new file mode 100644 index 0000000..e938d0a --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommand.cs @@ -0,0 +1,15 @@ +namespace CMSMicroservice.Application.ContractCQ.Commands.UpdateContract; +public record UpdateContractCommand : IRequest +{ + //شناسه + 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; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommandHandler.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommandHandler.cs new file mode 100644 index 0000000..34991b7 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommandHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.ContractCQ.Commands.UpdateContract; +public class UpdateContractCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public UpdateContractCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task 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; + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommandValidator.cs b/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommandValidator.cs new file mode 100644 index 0000000..3a5ac20 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Commands/UpdateContract/UpdateContractCommandValidator.cs @@ -0,0 +1,25 @@ +namespace CMSMicroservice.Application.ContractCQ.Commands.UpdateContract; +public class UpdateContractCommandValidator : AbstractValidator +{ + 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>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((UpdateContractCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/ContractCQ/EventHandlers/CreateNewContractEventHandlers/CreateNewContractEventHandler.cs b/src/CMSMicroservice.Application/ContractCQ/EventHandlers/CreateNewContractEventHandlers/CreateNewContractEventHandler.cs new file mode 100644 index 0000000..c3c470a --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/EventHandlers/CreateNewContractEventHandlers/CreateNewContractEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.ContractCQ.EventHandlers; + +public class CreateNewContractEventHandler : INotificationHandler +{ + private readonly ILogger< + CreateNewContractEventHandler> _logger; + + public CreateNewContractEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(CreateNewContractEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/EventHandlers/DeleteContractEventHandlers/DeleteContractEventHandler.cs b/src/CMSMicroservice.Application/ContractCQ/EventHandlers/DeleteContractEventHandlers/DeleteContractEventHandler.cs new file mode 100644 index 0000000..73f9afd --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/EventHandlers/DeleteContractEventHandlers/DeleteContractEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.ContractCQ.EventHandlers; + +public class DeleteContractEventHandler : INotificationHandler +{ + private readonly ILogger< + DeleteContractEventHandler> _logger; + + public DeleteContractEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(DeleteContractEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/EventHandlers/UpdateContractEventHandlers/UpdateContractEventHandler.cs b/src/CMSMicroservice.Application/ContractCQ/EventHandlers/UpdateContractEventHandlers/UpdateContractEventHandler.cs new file mode 100644 index 0000000..af8b32e --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/EventHandlers/UpdateContractEventHandlers/UpdateContractEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.ContractCQ.EventHandlers; + +public class UpdateContractEventHandler : INotificationHandler +{ + private readonly ILogger< + UpdateContractEventHandler> _logger; + + public UpdateContractEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(UpdateContractEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQuery.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQuery.cs new file mode 100644 index 0000000..b8f2e60 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQuery.cs @@ -0,0 +1,23 @@ +namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter; +public record GetAllContractByFilterQuery : IRequest +{ + //موقعیت صفحه بندی + 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; } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQueryHandler.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQueryHandler.cs new file mode 100644 index 0000000..aa6b2fe --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQueryHandler.cs @@ -0,0 +1,34 @@ +namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter; +public class GetAllContractByFilterQueryHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public GetAllContractByFilterQueryHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task 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().ToListAsync(cancellationToken) + }; + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQueryValidator.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQueryValidator.cs new file mode 100644 index 0000000..02cafde --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterQueryValidator.cs @@ -0,0 +1,14 @@ +namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter; +public class GetAllContractByFilterQueryValidator : AbstractValidator +{ + public GetAllContractByFilterQueryValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllContractByFilterQuery)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterResponseDto.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterResponseDto.cs new file mode 100644 index 0000000..e84c515 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetAllContractByFilter/GetAllContractByFilterResponseDto.cs @@ -0,0 +1,21 @@ +namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter; +public class GetAllContractByFilterResponseDto +{ + //متادیتا + public MetaData MetaData { get; set; } + //مدل خروجی + public List? 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; } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQuery.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQuery.cs new file mode 100644 index 0000000..9170add --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQuery.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract; +public record GetContractQuery : IRequest +{ + //شناسه + public long Id { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQueryHandler.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQueryHandler.cs new file mode 100644 index 0000000..572121a --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQueryHandler.cs @@ -0,0 +1,22 @@ +namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract; +public class GetContractQueryHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public GetContractQueryHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(GetContractQuery request, + CancellationToken cancellationToken) + { + var response = await _context.Contracts + .AsNoTracking() + .Where(x => x.Id == request.Id) + .ProjectToType() + .FirstOrDefaultAsync(cancellationToken); + + return response ?? throw new NotFoundException(nameof(Contract), request.Id); + } +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQueryValidator.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQueryValidator.cs new file mode 100644 index 0000000..03d4d04 --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractQueryValidator.cs @@ -0,0 +1,16 @@ +namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract; +public class GetContractQueryValidator : AbstractValidator +{ + public GetContractQueryValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetContractQuery)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractResponseDto.cs b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractResponseDto.cs new file mode 100644 index 0000000..e404efb --- /dev/null +++ b/src/CMSMicroservice.Application/ContractCQ/Queries/GetContract/GetContractResponseDto.cs @@ -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; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/OtpTokenCQ/Commands/CreateNewOtpToken/CreateNewOtpTokenCommand.cs b/src/CMSMicroservice.Application/OtpTokenCQ/Commands/CreateNewOtpToken/CreateNewOtpTokenCommand.cs index 56871e8..dc2181b 100644 --- a/src/CMSMicroservice.Application/OtpTokenCQ/Commands/CreateNewOtpToken/CreateNewOtpTokenCommand.cs +++ b/src/CMSMicroservice.Application/OtpTokenCQ/Commands/CreateNewOtpToken/CreateNewOtpTokenCommand.cs @@ -5,7 +5,5 @@ public record CreateNewOtpTokenCommand : IRequest public string Mobile { get; init; } //مقصود public string Purpose { get; init; } - //اطلاعات بیشتر - public string? ExtraInfo { get; init; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommand.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommand.cs new file mode 100644 index 0000000..1684fd4 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommand.cs @@ -0,0 +1,13 @@ +namespace CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract; +public record CreateNewUserContractCommand : IRequest +{ + //شناسه کاربر + public long UserId { get; init; } + //شناسه قرارداد + public long ContractId { get; init; } + //شناسه یکتای امضا + public string SignGuid { get; init; } + //فایل قرارداد + public string SignedPdfFile { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommandHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommandHandler.cs new file mode 100644 index 0000000..87d242a --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommandHandler.cs @@ -0,0 +1,21 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract; +public class CreateNewUserContractCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public CreateNewUserContractCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(CreateNewUserContractCommand request, + CancellationToken cancellationToken) + { + var entity = request.Adapt(); + await _context.UserContracts.AddAsync(entity, cancellationToken); + entity.AddDomainEvent(new CreateNewUserContractEvent(entity)); + await _context.SaveChangesAsync(cancellationToken); + return entity.Adapt(); + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommandValidator.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommandValidator.cs new file mode 100644 index 0000000..f6658d8 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractCommandValidator.cs @@ -0,0 +1,22 @@ +namespace CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract; +public class CreateNewUserContractCommandValidator : AbstractValidator +{ + public CreateNewUserContractCommandValidator() + { + RuleFor(model => model.UserId) + .NotNull(); + RuleFor(model => model.ContractId) + .NotNull(); + RuleFor(model => model.SignGuid) + .NotEmpty(); + RuleFor(model => model.SignedPdfFile) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateNewUserContractCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractResponseDto.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractResponseDto.cs new file mode 100644 index 0000000..8f1de04 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/CreateNewUserContract/CreateNewUserContractResponseDto.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract; +public class CreateNewUserContractResponseDto +{ + //شناسه + public long Id { get; set; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommand.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommand.cs new file mode 100644 index 0000000..ce11f00 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommand.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.UserContractCQ.Commands.DeleteUserContract; +public record DeleteUserContractCommand : IRequest +{ + //شناسه + public long Id { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommandHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommandHandler.cs new file mode 100644 index 0000000..a8faf45 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommandHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.UserContractCQ.Commands.DeleteUserContract; +public class DeleteUserContractCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public DeleteUserContractCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(DeleteUserContractCommand request, CancellationToken cancellationToken) + { + var entity = await _context.UserContracts + .FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserContract), request.Id); + entity.IsDeleted = true; + _context.UserContracts.Update(entity); + entity.AddDomainEvent(new DeleteUserContractEvent(entity)); + await _context.SaveChangesAsync(cancellationToken); + return Unit.Value; + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommandValidator.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommandValidator.cs new file mode 100644 index 0000000..3c8e042 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/DeleteUserContract/DeleteUserContractCommandValidator.cs @@ -0,0 +1,16 @@ +namespace CMSMicroservice.Application.UserContractCQ.Commands.DeleteUserContract; +public class DeleteUserContractCommandValidator : AbstractValidator +{ + public DeleteUserContractCommandValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((DeleteUserContractCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommand.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommand.cs new file mode 100644 index 0000000..7a62a0d --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommand.cs @@ -0,0 +1,15 @@ +namespace CMSMicroservice.Application.UserContractCQ.Commands.UpdateUserContract; +public record UpdateUserContractCommand : IRequest +{ + //شناسه + public long Id { get; init; } + //شناسه کاربر + public long UserId { get; init; } + //شناسه قرارداد + public long ContractId { get; init; } + //شناسه یکتای امضا + public string SignGuid { get; init; } + //فایل قرارداد + public string SignedPdfFile { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommandHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommandHandler.cs new file mode 100644 index 0000000..3bacdb0 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommandHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.UserContractCQ.Commands.UpdateUserContract; +public class UpdateUserContractCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public UpdateUserContractCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(UpdateUserContractCommand request, CancellationToken cancellationToken) + { + var entity = await _context.UserContracts + .FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserContract), request.Id); + request.Adapt(entity); + _context.UserContracts.Update(entity); + entity.AddDomainEvent(new UpdateUserContractEvent(entity)); + await _context.SaveChangesAsync(cancellationToken); + return Unit.Value; + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommandValidator.cs b/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommandValidator.cs new file mode 100644 index 0000000..c92c989 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Commands/UpdateUserContract/UpdateUserContractCommandValidator.cs @@ -0,0 +1,24 @@ +namespace CMSMicroservice.Application.UserContractCQ.Commands.UpdateUserContract; +public class UpdateUserContractCommandValidator : AbstractValidator +{ + public UpdateUserContractCommandValidator() + { + RuleFor(model => model.Id) + .NotNull(); + RuleFor(model => model.UserId) + .NotNull(); + RuleFor(model => model.ContractId) + .NotNull(); + RuleFor(model => model.SignGuid) + .NotEmpty(); + RuleFor(model => model.SignedPdfFile) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((UpdateUserContractCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/CreateNewUserContractEventHandlers/CreateNewUserContractEventHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/CreateNewUserContractEventHandlers/CreateNewUserContractEventHandler.cs new file mode 100644 index 0000000..873241b --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/CreateNewUserContractEventHandlers/CreateNewUserContractEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.UserContractCQ.EventHandlers; + +public class CreateNewUserContractEventHandler : INotificationHandler +{ + private readonly ILogger< + CreateNewUserContractEventHandler> _logger; + + public CreateNewUserContractEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(CreateNewUserContractEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/DeleteUserContractEventHandlers/DeleteUserContractEventHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/DeleteUserContractEventHandlers/DeleteUserContractEventHandler.cs new file mode 100644 index 0000000..80f3fb1 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/DeleteUserContractEventHandlers/DeleteUserContractEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.UserContractCQ.EventHandlers; + +public class DeleteUserContractEventHandler : INotificationHandler +{ + private readonly ILogger< + DeleteUserContractEventHandler> _logger; + + public DeleteUserContractEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(DeleteUserContractEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/UpdateUserContractEventHandlers/UpdateUserContractEventHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/UpdateUserContractEventHandlers/UpdateUserContractEventHandler.cs new file mode 100644 index 0000000..ab350eb --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/EventHandlers/UpdateUserContractEventHandlers/UpdateUserContractEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.UserContractCQ.EventHandlers; + +public class UpdateUserContractEventHandler : INotificationHandler +{ + private readonly ILogger< + UpdateUserContractEventHandler> _logger; + + public UpdateUserContractEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(UpdateUserContractEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQuery.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQuery.cs new file mode 100644 index 0000000..ff880e8 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQuery.cs @@ -0,0 +1,23 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter; +public record GetAllUserContractByFilterQuery : IRequest +{ + //موقعیت صفحه بندی + public PaginationState? PaginationState { get; init; } + //مرتب سازی بر اساس + public string? SortBy { get; init; } + //فیلتر + public GetAllUserContractByFilterFilter? Filter { get; init; } + +}public class GetAllUserContractByFilterFilter +{ + //شناسه + public long? Id { get; set; } + //شناسه کاربر + public long? UserId { get; set; } + //شناسه قرارداد + public long? ContractId { get; set; } + //شناسه یکتای امضا + public string? SignGuid { get; set; } + //فایل قرارداد + public string? SignedPdfFile { get; set; } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQueryHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQueryHandler.cs new file mode 100644 index 0000000..f4ab96f --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQueryHandler.cs @@ -0,0 +1,34 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter; +public class GetAllUserContractByFilterQueryHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public GetAllUserContractByFilterQueryHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(GetAllUserContractByFilterQuery request, CancellationToken cancellationToken) + { + var query = _context.UserContracts + .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.UserId == null || x.UserId == request.Filter.UserId) + .Where(x => request.Filter.ContractId == null || x.ContractId == request.Filter.ContractId) + .Where(x => request.Filter.SignGuid == null || x.SignGuid.Contains(request.Filter.SignGuid)) + .Where(x => request.Filter.SignedPdfFile == null || x.SignedPdfFile.Contains(request.Filter.SignedPdfFile)) +; + } + return new GetAllUserContractByFilterResponseDto + { + MetaData = await query.GetMetaData(request.PaginationState, cancellationToken), + Models = await query.PaginatedListAsync(paginationState: request.PaginationState) + .ProjectToType().ToListAsync(cancellationToken) + }; + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQueryValidator.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQueryValidator.cs new file mode 100644 index 0000000..03af352 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterQueryValidator.cs @@ -0,0 +1,14 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter; +public class GetAllUserContractByFilterQueryValidator : AbstractValidator +{ + public GetAllUserContractByFilterQueryValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllUserContractByFilterQuery)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterResponseDto.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterResponseDto.cs new file mode 100644 index 0000000..7261346 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetAllUserContractByFilter/GetAllUserContractByFilterResponseDto.cs @@ -0,0 +1,21 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter; +public class GetAllUserContractByFilterResponseDto +{ + //متادیتا + public MetaData MetaData { get; set; } + //مدل خروجی + public List? Models { get; set; } + +}public class GetAllUserContractByFilterResponseModel +{ + //شناسه + public long Id { get; set; } + //شناسه کاربر + public long UserId { get; set; } + //شناسه قرارداد + public long ContractId { get; set; } + //شناسه یکتای امضا + public string SignGuid { get; set; } + //فایل قرارداد + public string SignedPdfFile { get; set; } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQuery.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQuery.cs new file mode 100644 index 0000000..364a1f6 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQuery.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract; +public record GetUserContractQuery : IRequest +{ + //شناسه + public long Id { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQueryHandler.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQueryHandler.cs new file mode 100644 index 0000000..0d83b58 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQueryHandler.cs @@ -0,0 +1,22 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract; +public class GetUserContractQueryHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public GetUserContractQueryHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(GetUserContractQuery request, + CancellationToken cancellationToken) + { + var response = await _context.UserContracts + .AsNoTracking() + .Where(x => x.Id == request.Id) + .ProjectToType() + .FirstOrDefaultAsync(cancellationToken); + + return response ?? throw new NotFoundException(nameof(UserContract), request.Id); + } +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQueryValidator.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQueryValidator.cs new file mode 100644 index 0000000..aa02329 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractQueryValidator.cs @@ -0,0 +1,16 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract; +public class GetUserContractQueryValidator : AbstractValidator +{ + public GetUserContractQueryValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetUserContractQuery)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractResponseDto.cs b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractResponseDto.cs new file mode 100644 index 0000000..b2e8d91 --- /dev/null +++ b/src/CMSMicroservice.Application/UserContractCQ/Queries/GetUserContract/GetUserContractResponseDto.cs @@ -0,0 +1,15 @@ +namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract; +public class GetUserContractResponseDto +{ + //شناسه + public long Id { get; set; } + //شناسه کاربر + public long UserId { get; set; } + //شناسه قرارداد + public long ContractId { get; set; } + //شناسه یکتای امضا + public string SignGuid { get; set; } + //فایل قرارداد + public string SignedPdfFile { get; set; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Domain/Entities/Contract.cs b/src/CMSMicroservice.Domain/Entities/Contract.cs new file mode 100644 index 0000000..368318c --- /dev/null +++ b/src/CMSMicroservice.Domain/Entities/Contract.cs @@ -0,0 +1,15 @@ +namespace CMSMicroservice.Domain.Entities; +//قراردادها +public class Contract : BaseAuditableEntity +{ + //عنوان + public string Title { get; set; } + //توضیحات + public string Description { get; set; } + //متن قرارداد + public string HtmlContent { get; set; } + //نوع قرارداد + public UnknownEnumType Type { get; set; } + //UserContract Collection Navigation Reference + public virtual ICollection UserContracts { get; set; } +} diff --git a/src/CMSMicroservice.Domain/Entities/User.cs b/src/CMSMicroservice.Domain/Entities/User.cs index 2cb98d7..472ee89 100644 --- a/src/CMSMicroservice.Domain/Entities/User.cs +++ b/src/CMSMicroservice.Domain/Entities/User.cs @@ -48,4 +48,6 @@ public class User : BaseAuditableEntity public virtual ICollection UserOrders { get; set; } //User Collection Navigation Reference public virtual ICollection Users { get; set; } + //UserContract Collection Navigation Reference + public virtual ICollection UserContracts { get; set; } } diff --git a/src/CMSMicroservice.Domain/Entities/UserContract.cs b/src/CMSMicroservice.Domain/Entities/UserContract.cs new file mode 100644 index 0000000..b9d9326 --- /dev/null +++ b/src/CMSMicroservice.Domain/Entities/UserContract.cs @@ -0,0 +1,17 @@ +namespace CMSMicroservice.Domain.Entities; +//قراردادها +public class UserContract : BaseAuditableEntity +{ + //شناسه کاربر + public long UserId { get; set; } + //User Navigation Property + public virtual User User { get; set; } + //شناسه قرارداد + public long ContractId { get; set; } + //Contract Navigation Property + public virtual Contract Contract { get; set; } + //شناسه یکتای امضا + public string SignGuid { get; set; } + //فایل قرارداد + public string SignedPdfFile { get; set; } +} diff --git a/src/CMSMicroservice.Domain/Events/ContractEvents/CreateNewContractEvent.cs b/src/CMSMicroservice.Domain/Events/ContractEvents/CreateNewContractEvent.cs new file mode 100644 index 0000000..c2f7cda --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/ContractEvents/CreateNewContractEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class CreateNewContractEvent : BaseEvent +{ + public CreateNewContractEvent(Contract item) + { + } + public Contract Item { get; } +} diff --git a/src/CMSMicroservice.Domain/Events/ContractEvents/DeleteContractEvent.cs b/src/CMSMicroservice.Domain/Events/ContractEvents/DeleteContractEvent.cs new file mode 100644 index 0000000..72b94cd --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/ContractEvents/DeleteContractEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class DeleteContractEvent : BaseEvent +{ + public DeleteContractEvent(Contract item) + { + } + public Contract Item { get; } +} diff --git a/src/CMSMicroservice.Domain/Events/ContractEvents/UpdateContractEvent.cs b/src/CMSMicroservice.Domain/Events/ContractEvents/UpdateContractEvent.cs new file mode 100644 index 0000000..a32c742 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/ContractEvents/UpdateContractEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class UpdateContractEvent : BaseEvent +{ + public UpdateContractEvent(Contract item) + { + } + public Contract Item { get; } +} diff --git a/src/CMSMicroservice.Domain/Events/UserContractEvents/CreateNewUserContractEvent.cs b/src/CMSMicroservice.Domain/Events/UserContractEvents/CreateNewUserContractEvent.cs new file mode 100644 index 0000000..4117159 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/UserContractEvents/CreateNewUserContractEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class CreateNewUserContractEvent : BaseEvent +{ + public CreateNewUserContractEvent(UserContract item) + { + } + public UserContract Item { get; } +} diff --git a/src/CMSMicroservice.Domain/Events/UserContractEvents/DeleteUserContractEvent.cs b/src/CMSMicroservice.Domain/Events/UserContractEvents/DeleteUserContractEvent.cs new file mode 100644 index 0000000..5898597 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/UserContractEvents/DeleteUserContractEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class DeleteUserContractEvent : BaseEvent +{ + public DeleteUserContractEvent(UserContract item) + { + } + public UserContract Item { get; } +} diff --git a/src/CMSMicroservice.Domain/Events/UserContractEvents/UpdateUserContractEvent.cs b/src/CMSMicroservice.Domain/Events/UserContractEvents/UpdateUserContractEvent.cs new file mode 100644 index 0000000..8bd4623 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/UserContractEvents/UpdateUserContractEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class UpdateUserContractEvent : BaseEvent +{ + public UpdateUserContractEvent(UserContract item) + { + } + public UserContract Item { get; } +} diff --git a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs index 418baff..d498fd4 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs @@ -43,8 +43,6 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext public DbSet Packages => Set(); public DbSet Roles => Set(); public DbSet UserRoles => Set(); - public DbSet OtpTokens => Set(); - public DbSet Users => Set(); public DbSet UserWallets => Set(); public DbSet UserWalletChangeLogs => Set(); public DbSet UserCartss => Set(); @@ -54,4 +52,8 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext public DbSet Productss => Set(); public DbSet ProductImagess => Set(); public DbSet Transactionss => Set(); + public DbSet Users => Set(); + public DbSet OtpTokens => Set(); + public DbSet Contracts => Set(); + public DbSet UserContracts => Set(); } diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/ContractConfiguration.cs b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/ContractConfiguration.cs new file mode 100644 index 0000000..c310892 --- /dev/null +++ b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/ContractConfiguration.cs @@ -0,0 +1,20 @@ +using CMSMicroservice.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +namespace CMSMicroservice.Infrastructure.Persistence.Configurations; +//قراردادها +public class ContractConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasQueryFilter(p => !p.IsDeleted); + builder.Ignore(entity => entity.DomainEvents); + builder.HasKey(entity => entity.Id); + builder.Property(entity => entity.Id).UseIdentityColumn(); + builder.Property(entity => entity.Title).IsRequired(true); + builder.Property(entity => entity.Description).IsRequired(true); + builder.Property(entity => entity.HtmlContent).IsRequired(true); + builder.Property(entity => entity.Type).IsRequired(true); + + } +} diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserContractConfiguration.cs b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserContractConfiguration.cs new file mode 100644 index 0000000..f620f4b --- /dev/null +++ b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserContractConfiguration.cs @@ -0,0 +1,28 @@ +using CMSMicroservice.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +namespace CMSMicroservice.Infrastructure.Persistence.Configurations; +//قراردادها +public class UserContractConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasQueryFilter(p => !p.IsDeleted); + builder.Ignore(entity => entity.DomainEvents); + builder.HasKey(entity => entity.Id); + builder.Property(entity => entity.Id).UseIdentityColumn(); + builder + .HasOne(entity => entity.User) + .WithMany(entity => entity.UserContracts) + .HasForeignKey(entity => entity.UserId) + .IsRequired(true); + builder + .HasOne(entity => entity.Contract) + .WithMany(entity => entity.UserContracts) + .HasForeignKey(entity => entity.ContractId) + .IsRequired(true); + builder.Property(entity => entity.SignGuid).IsRequired(true); + builder.Property(entity => entity.SignedPdfFile).IsRequired(true); + + } +} diff --git a/src/CMSMicroservice.Protobuf/Protos/contract.proto b/src/CMSMicroservice.Protobuf/Protos/contract.proto new file mode 100644 index 0000000..a73cbf1 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Protos/contract.proto @@ -0,0 +1,108 @@ +syntax = "proto3"; + +package contract; + +import "public_messages.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/wrappers.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/api/annotations.proto"; + +option csharp_namespace = "CMSMicroservice.Protobuf.Protos.Contract"; + +service ContractContract +{ + rpc CreateNewContract(CreateNewContractRequest) returns (CreateNewContractResponse){ + option (google.api.http) = { + post: "/CreateNewContract" + body: "*" + }; + }; + rpc UpdateContract(UpdateContractRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + put: "/UpdateContract" + body: "*" + }; + }; + rpc DeleteContract(DeleteContractRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + delete: "/DeleteContract" + body: "*" + }; + }; + rpc GetContract(GetContractRequest) returns (GetContractResponse){ + option (google.api.http) = { + get: "/GetContract" + + }; + }; + rpc GetAllContractByFilter(GetAllContractByFilterRequest) returns (GetAllContractByFilterResponse){ + option (google.api.http) = { + get: "/GetAllContractByFilter" + + }; + }; +} +message CreateNewContractRequest +{ + string title = 1; + string description = 2; + string html_content = 3; + Unknown type = 4; +} +message CreateNewContractResponse +{ + int64 id = 1; +} +message UpdateContractRequest +{ + int64 id = 1; + string title = 2; + string description = 3; + string html_content = 4; + Unknown type = 5; +} +message DeleteContractRequest +{ + int64 id = 1; +} +message GetContractRequest +{ + int64 id = 1; +} +message GetContractResponse +{ + int64 id = 1; + string title = 2; + string description = 3; + string html_content = 4; + Unknown type = 5; +} +message GetAllContractByFilterRequest +{ + messages.PaginationState pagination_state = 1; + google.protobuf.StringValue sort_by = 2; + GetAllContractByFilterFilter filter = 3; +} +message GetAllContractByFilterFilter +{ + google.protobuf.Int64Value id = 1; + google.protobuf.StringValue title = 2; + google.protobuf.StringValue description = 3; + google.protobuf.StringValue html_content = 4; + Unknown type = 5; +} +message GetAllContractByFilterResponse +{ + messages.MetaData meta_data = 1; + repeated GetAllContractByFilterResponseModel models = 2; +} +message GetAllContractByFilterResponseModel +{ + int64 id = 1; + string title = 2; + string description = 3; + string html_content = 4; + Unknown type = 5; +} diff --git a/src/CMSMicroservice.Protobuf/Protos/otptoken.proto b/src/CMSMicroservice.Protobuf/Protos/otptoken.proto index 839fc4a..0c787e1 100644 --- a/src/CMSMicroservice.Protobuf/Protos/otptoken.proto +++ b/src/CMSMicroservice.Protobuf/Protos/otptoken.proto @@ -36,7 +36,6 @@ message CreateNewOtpTokenRequest { string mobile = 1; string purpose = 2; - google.protobuf.StringValue extra_info = 3; } message CreateNewOtpTokenResponse { diff --git a/src/CMSMicroservice.Protobuf/Protos/usercontract.proto b/src/CMSMicroservice.Protobuf/Protos/usercontract.proto new file mode 100644 index 0000000..5eed482 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Protos/usercontract.proto @@ -0,0 +1,108 @@ +syntax = "proto3"; + +package usercontract; + +import "public_messages.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/wrappers.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/api/annotations.proto"; + +option csharp_namespace = "CMSMicroservice.Protobuf.Protos.UserContract"; + +service UserContractContract +{ + rpc CreateNewUserContract(CreateNewUserContractRequest) returns (CreateNewUserContractResponse){ + option (google.api.http) = { + post: "/CreateNewUserContract" + body: "*" + }; + }; + rpc UpdateUserContract(UpdateUserContractRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + put: "/UpdateUserContract" + body: "*" + }; + }; + rpc DeleteUserContract(DeleteUserContractRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + delete: "/DeleteUserContract" + body: "*" + }; + }; + rpc GetUserContract(GetUserContractRequest) returns (GetUserContractResponse){ + option (google.api.http) = { + get: "/GetUserContract" + + }; + }; + rpc GetAllUserContractByFilter(GetAllUserContractByFilterRequest) returns (GetAllUserContractByFilterResponse){ + option (google.api.http) = { + get: "/GetAllUserContractByFilter" + + }; + }; +} +message CreateNewUserContractRequest +{ + int64 user_id = 1; + int64 contract_id = 2; + string sign_guid = 3; + string signed_pdf_file = 4; +} +message CreateNewUserContractResponse +{ + int64 id = 1; +} +message UpdateUserContractRequest +{ + int64 id = 1; + int64 user_id = 2; + int64 contract_id = 3; + string sign_guid = 4; + string signed_pdf_file = 5; +} +message DeleteUserContractRequest +{ + int64 id = 1; +} +message GetUserContractRequest +{ + int64 id = 1; +} +message GetUserContractResponse +{ + int64 id = 1; + int64 user_id = 2; + int64 contract_id = 3; + string sign_guid = 4; + string signed_pdf_file = 5; +} +message GetAllUserContractByFilterRequest +{ + messages.PaginationState pagination_state = 1; + google.protobuf.StringValue sort_by = 2; + GetAllUserContractByFilterFilter filter = 3; +} +message GetAllUserContractByFilterFilter +{ + google.protobuf.Int64Value id = 1; + google.protobuf.Int64Value user_id = 2; + google.protobuf.Int64Value contract_id = 3; + google.protobuf.StringValue sign_guid = 4; + google.protobuf.StringValue signed_pdf_file = 5; +} +message GetAllUserContractByFilterResponse +{ + messages.MetaData meta_data = 1; + repeated GetAllUserContractByFilterResponseModel models = 2; +} +message GetAllUserContractByFilterResponseModel +{ + int64 id = 1; + int64 user_id = 2; + int64 contract_id = 3; + string sign_guid = 4; + string signed_pdf_file = 5; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/Contract/CreateNewContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Contract/CreateNewContractRequestValidator.cs new file mode 100644 index 0000000..eff6d42 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Contract/CreateNewContractRequestValidator.cs @@ -0,0 +1,26 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Contract; +namespace CMSMicroservice.Protobuf.Validator.Contract; + +public class CreateNewContractRequestValidator : AbstractValidator +{ + public CreateNewContractRequestValidator() + { + RuleFor(model => model.Title) + .NotEmpty(); + RuleFor(model => model.Description) + .NotEmpty(); + RuleFor(model => model.HtmlContent) + .NotEmpty(); + RuleFor(model => model.Type) + .IsInEnum() + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateNewContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/Contract/DeleteContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Contract/DeleteContractRequestValidator.cs new file mode 100644 index 0000000..3e208b4 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Contract/DeleteContractRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Contract; +namespace CMSMicroservice.Protobuf.Validator.Contract; + +public class DeleteContractRequestValidator : AbstractValidator +{ + public DeleteContractRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((DeleteContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/Contract/GetAllContractByFilterRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Contract/GetAllContractByFilterRequestValidator.cs new file mode 100644 index 0000000..54855ee --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Contract/GetAllContractByFilterRequestValidator.cs @@ -0,0 +1,17 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Contract; +namespace CMSMicroservice.Protobuf.Validator.Contract; + +public class GetAllContractByFilterRequestValidator : AbstractValidator +{ + public GetAllContractByFilterRequestValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllContractByFilterRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/Contract/GetContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Contract/GetContractRequestValidator.cs new file mode 100644 index 0000000..5466985 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Contract/GetContractRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Contract; +namespace CMSMicroservice.Protobuf.Validator.Contract; + +public class GetContractRequestValidator : AbstractValidator +{ + public GetContractRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/Contract/UpdateContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Contract/UpdateContractRequestValidator.cs new file mode 100644 index 0000000..b34e69f --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Contract/UpdateContractRequestValidator.cs @@ -0,0 +1,28 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Contract; +namespace CMSMicroservice.Protobuf.Validator.Contract; + +public class UpdateContractRequestValidator : AbstractValidator +{ + public UpdateContractRequestValidator() + { + 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>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((UpdateContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/UserContract/CreateNewUserContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserContract/CreateNewUserContractRequestValidator.cs new file mode 100644 index 0000000..269f980 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/UserContract/CreateNewUserContractRequestValidator.cs @@ -0,0 +1,25 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.UserContract; +namespace CMSMicroservice.Protobuf.Validator.UserContract; + +public class CreateNewUserContractRequestValidator : AbstractValidator +{ + public CreateNewUserContractRequestValidator() + { + RuleFor(model => model.UserId) + .NotNull(); + RuleFor(model => model.ContractId) + .NotNull(); + RuleFor(model => model.SignGuid) + .NotEmpty(); + RuleFor(model => model.SignedPdfFile) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateNewUserContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/UserContract/DeleteUserContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserContract/DeleteUserContractRequestValidator.cs new file mode 100644 index 0000000..b2f1f3b --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/UserContract/DeleteUserContractRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.UserContract; +namespace CMSMicroservice.Protobuf.Validator.UserContract; + +public class DeleteUserContractRequestValidator : AbstractValidator +{ + public DeleteUserContractRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((DeleteUserContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/UserContract/GetAllUserContractByFilterRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserContract/GetAllUserContractByFilterRequestValidator.cs new file mode 100644 index 0000000..ea0dcab --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/UserContract/GetAllUserContractByFilterRequestValidator.cs @@ -0,0 +1,17 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.UserContract; +namespace CMSMicroservice.Protobuf.Validator.UserContract; + +public class GetAllUserContractByFilterRequestValidator : AbstractValidator +{ + public GetAllUserContractByFilterRequestValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllUserContractByFilterRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/UserContract/GetUserContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserContract/GetUserContractRequestValidator.cs new file mode 100644 index 0000000..a3122a0 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/UserContract/GetUserContractRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.UserContract; +namespace CMSMicroservice.Protobuf.Validator.UserContract; + +public class GetUserContractRequestValidator : AbstractValidator +{ + public GetUserContractRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetUserContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/UserContract/UpdateUserContractRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserContract/UpdateUserContractRequestValidator.cs new file mode 100644 index 0000000..794350e --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/UserContract/UpdateUserContractRequestValidator.cs @@ -0,0 +1,27 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.UserContract; +namespace CMSMicroservice.Protobuf.Validator.UserContract; + +public class UpdateUserContractRequestValidator : AbstractValidator +{ + public UpdateUserContractRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + RuleFor(model => model.UserId) + .NotNull(); + RuleFor(model => model.ContractId) + .NotNull(); + RuleFor(model => model.SignGuid) + .NotEmpty(); + RuleFor(model => model.SignedPdfFile) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((UpdateUserContractRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.WebApi/Common/Mappings/ContractProfile.cs b/src/CMSMicroservice.WebApi/Common/Mappings/ContractProfile.cs new file mode 100644 index 0000000..77fa767 --- /dev/null +++ b/src/CMSMicroservice.WebApi/Common/Mappings/ContractProfile.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.WebApi.Common.Mappings; + +public class ContractProfile : IRegister +{ + void IRegister.Register(TypeAdapterConfig config) + { + config.NewConfig() + .IgnoreIf((src, dest) => !src.Filter.HasType, dest => dest.Filter.Type); + } +} diff --git a/src/CMSMicroservice.WebApi/Common/Mappings/UserContractProfile.cs b/src/CMSMicroservice.WebApi/Common/Mappings/UserContractProfile.cs new file mode 100644 index 0000000..a1cf3ed --- /dev/null +++ b/src/CMSMicroservice.WebApi/Common/Mappings/UserContractProfile.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.WebApi.Common.Mappings; + +public class UserContractProfile : IRegister +{ + void IRegister.Register(TypeAdapterConfig config) + { + //config.NewConfig() + // .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}"); + } +} diff --git a/src/CMSMicroservice.WebApi/Services/ContractService.cs b/src/CMSMicroservice.WebApi/Services/ContractService.cs new file mode 100644 index 0000000..b99edb4 --- /dev/null +++ b/src/CMSMicroservice.WebApi/Services/ContractService.cs @@ -0,0 +1,37 @@ +using CMSMicroservice.Protobuf.Protos.Contract; +using CMSMicroservice.WebApi.Common.Services; +using CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract; +using CMSMicroservice.Application.ContractCQ.Commands.UpdateContract; +using CMSMicroservice.Application.ContractCQ.Commands.DeleteContract; +using CMSMicroservice.Application.ContractCQ.Queries.GetContract; +using CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter; +namespace CMSMicroservice.WebApi.Services; +public class ContractService : ContractContract.ContractContractBase +{ + private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS; + + public ContractService(IDispatchRequestToCQRS dispatchRequestToCQRS) + { + _dispatchRequestToCQRS = dispatchRequestToCQRS; + } + public override async Task CreateNewContract(CreateNewContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task UpdateContract(UpdateContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task DeleteContract(DeleteContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetContract(GetContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetAllContractByFilter(GetAllContractByFilterRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } +} diff --git a/src/CMSMicroservice.WebApi/Services/UserContractService.cs b/src/CMSMicroservice.WebApi/Services/UserContractService.cs new file mode 100644 index 0000000..84ce33e --- /dev/null +++ b/src/CMSMicroservice.WebApi/Services/UserContractService.cs @@ -0,0 +1,37 @@ +using CMSMicroservice.Protobuf.Protos.UserContract; +using CMSMicroservice.WebApi.Common.Services; +using CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract; +using CMSMicroservice.Application.UserContractCQ.Commands.UpdateUserContract; +using CMSMicroservice.Application.UserContractCQ.Commands.DeleteUserContract; +using CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract; +using CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter; +namespace CMSMicroservice.WebApi.Services; +public class UserContractService : UserContractContract.UserContractContractBase +{ + private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS; + + public UserContractService(IDispatchRequestToCQRS dispatchRequestToCQRS) + { + _dispatchRequestToCQRS = dispatchRequestToCQRS; + } + public override async Task CreateNewUserContract(CreateNewUserContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task UpdateUserContract(UpdateUserContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task DeleteUserContract(DeleteUserContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetUserContract(GetUserContractRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetAllUserContractByFilter(GetAllUserContractByFilterRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } +}