From dba8aecc971a449ae1cb3115b984bcebc141856c Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Mon, 17 Nov 2025 23:57:51 +0330 Subject: [PATCH] =?UTF-8?q?Generator=20Changes=20at=2011/17/2025=2011:53:4?= =?UTF-8?q?7=E2=80=AFPM=20+03:30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateNewCategoryCommandValidator.cs | 3 +- .../UpdateCategoryCommandValidator.cs | 3 +- .../Interfaces/IApplicationDbContext.cs | 5 +- .../Common/Mappings/PruductCategoryProfile.cs | 10 ++ .../CreateNewPruductCategoryCommand.cs | 9 ++ .../CreateNewPruductCategoryCommandHandler.cs | 21 +++ ...reateNewPruductCategoryCommandValidator.cs | 18 +++ .../CreateNewPruductCategoryResponseDto.cs | 7 + .../DeletePruductCategoryCommand.cs | 7 + .../DeletePruductCategoryCommandHandler.cs | 22 ++++ .../DeletePruductCategoryCommandValidator.cs | 16 +++ .../UpdatePruductCategoryCommand.cs | 11 ++ .../UpdatePruductCategoryCommandHandler.cs | 22 ++++ .../UpdatePruductCategoryCommandValidator.cs | 20 +++ .../CreateNewPruductCategoryEventHandler.cs | 22 ++++ .../DeletePruductCategoryEventHandler.cs | 22 ++++ .../UpdatePruductCategoryEventHandler.cs | 22 ++++ .../GetAllPruductCategoryByFilterQuery.cs | 19 +++ ...tAllPruductCategoryByFilterQueryHandler.cs | 32 +++++ ...llPruductCategoryByFilterQueryValidator.cs | 14 ++ ...etAllPruductCategoryByFilterResponseDto.cs | 17 +++ .../GetPruductCategoryQuery.cs | 7 + .../GetPruductCategoryQueryHandler.cs | 22 ++++ .../GetPruductCategoryQueryValidator.cs | 16 +++ .../GetPruductCategoryResponseDto.cs | 11 ++ .../Entities/Category.cs | 23 ++-- .../Entities/Products.cs | 2 + .../Entities/PruductCategory.cs | 13 ++ .../CreateNewPruductCategoryEvent.cs | 8 ++ .../DeletePruductCategoryEvent.cs | 8 ++ .../UpdatePruductCategoryEvent.cs | 8 ++ .../Persistence/ApplicationDbContext.cs | 3 +- .../PruductCategoryConfiguration.cs | 26 ++++ .../Configurations/UserConfiguration.cs | 7 +- .../Protos/category.proto | 123 ++++++++++++++++++ .../Protos/pruductcategory.proto | 98 ++++++++++++++ .../CreateNewCategoryRequestValidator.cs | 25 ++++ .../DeleteCategoryRequestValidator.cs | 19 +++ .../GetAllCategoryByFilterRequestValidator.cs | 17 +++ .../Category/GetCategoryRequestValidator.cs | 19 +++ .../UpdateCategoryRequestValidator.cs | 27 ++++ ...reateNewPruductCategoryRequestValidator.cs | 21 +++ .../DeletePruductCategoryRequestValidator.cs | 19 +++ ...PruductCategoryByFilterRequestValidator.cs | 17 +++ .../GetPruductCategoryRequestValidator.cs | 19 +++ .../UpdatePruductCategoryRequestValidator.cs | 23 ++++ .../Common/Mappings/CategoryProfile.cs | 10 ++ .../Common/Mappings/PruductCategoryProfile.cs | 10 ++ .../Services/CategoryService.cs | 37 ++++++ .../Services/PruductCategoryService.cs | 37 ++++++ 50 files changed, 978 insertions(+), 19 deletions(-) create mode 100644 src/CMSMicroservice.Application/Common/Mappings/PruductCategoryProfile.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommand.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandValidator.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryResponseDto.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommand.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandValidator.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommand.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandValidator.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/CreateNewPruductCategoryEventHandlers/CreateNewPruductCategoryEventHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/DeletePruductCategoryEventHandlers/DeletePruductCategoryEventHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/UpdatePruductCategoryEventHandlers/UpdatePruductCategoryEventHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQuery.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryValidator.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterResponseDto.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQuery.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryHandler.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryValidator.cs create mode 100644 src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryResponseDto.cs create mode 100644 src/CMSMicroservice.Domain/Entities/PruductCategory.cs create mode 100644 src/CMSMicroservice.Domain/Events/PruductCategoryEvents/CreateNewPruductCategoryEvent.cs create mode 100644 src/CMSMicroservice.Domain/Events/PruductCategoryEvents/DeletePruductCategoryEvent.cs create mode 100644 src/CMSMicroservice.Domain/Events/PruductCategoryEvents/UpdatePruductCategoryEvent.cs create mode 100644 src/CMSMicroservice.Infrastructure/Persistence/Configurations/PruductCategoryConfiguration.cs create mode 100644 src/CMSMicroservice.Protobuf/Protos/category.proto create mode 100644 src/CMSMicroservice.Protobuf/Protos/pruductcategory.proto create mode 100644 src/CMSMicroservice.Protobuf/Validator/Category/CreateNewCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/Category/DeleteCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/Category/GetAllCategoryByFilterRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/Category/GetCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/Category/UpdateCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/PruductCategory/CreateNewPruductCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/PruductCategory/DeletePruductCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/PruductCategory/GetAllPruductCategoryByFilterRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/PruductCategory/GetPruductCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/PruductCategory/UpdatePruductCategoryRequestValidator.cs create mode 100644 src/CMSMicroservice.WebApi/Common/Mappings/CategoryProfile.cs create mode 100644 src/CMSMicroservice.WebApi/Common/Mappings/PruductCategoryProfile.cs create mode 100644 src/CMSMicroservice.WebApi/Services/CategoryService.cs create mode 100644 src/CMSMicroservice.WebApi/Services/PruductCategoryService.cs diff --git a/src/CMSMicroservice.Application/CategoryCQ/Commands/CreateNewCategory/CreateNewCategoryCommandValidator.cs b/src/CMSMicroservice.Application/CategoryCQ/Commands/CreateNewCategory/CreateNewCategoryCommandValidator.cs index f21d411..9e6bbea 100644 --- a/src/CMSMicroservice.Application/CategoryCQ/Commands/CreateNewCategory/CreateNewCategoryCommandValidator.cs +++ b/src/CMSMicroservice.Application/CategoryCQ/Commands/CreateNewCategory/CreateNewCategoryCommandValidator.cs @@ -7,6 +7,8 @@ public class CreateNewCategoryCommandValidator : AbstractValidator model.Title) .NotEmpty(); + RuleFor(model => model.IsActive) + .NotNull(); RuleFor(model => model.SortOrder) .NotNull(); } @@ -18,4 +20,3 @@ public class CreateNewCategoryCommandValidator : AbstractValidator e.ErrorMessage); }; } - diff --git a/src/CMSMicroservice.Application/CategoryCQ/Commands/UpdateCategory/UpdateCategoryCommandValidator.cs b/src/CMSMicroservice.Application/CategoryCQ/Commands/UpdateCategory/UpdateCategoryCommandValidator.cs index 9634318..7dbf8b4 100644 --- a/src/CMSMicroservice.Application/CategoryCQ/Commands/UpdateCategory/UpdateCategoryCommandValidator.cs +++ b/src/CMSMicroservice.Application/CategoryCQ/Commands/UpdateCategory/UpdateCategoryCommandValidator.cs @@ -9,6 +9,8 @@ public class UpdateCategoryCommandValidator : AbstractValidator model.Title) .NotEmpty(); + RuleFor(model => model.IsActive) + .NotNull(); RuleFor(model => model.SortOrder) .NotNull(); } @@ -20,4 +22,3 @@ public class UpdateCategoryCommandValidator : AbstractValidator e.ErrorMessage); }; } - diff --git a/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs b/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs index 9e33fdb..aec6300 100644 --- a/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs +++ b/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs @@ -4,8 +4,8 @@ public interface IApplicationDbContext { DbSet UserAddresss { get; } DbSet Packages { get; } - DbSet Categories { get; } DbSet Roles { get; } + DbSet Categorys { get; } DbSet UserRoles { get; } DbSet UserWallets { get; } DbSet UserWalletChangeLogs { get; } @@ -20,5 +20,6 @@ public interface IApplicationDbContext DbSet OtpTokens { get; } DbSet Contracts { get; } DbSet UserContracts { get; } + DbSet PruductCategorys { get; } Task SaveChangesAsync(CancellationToken cancellationToken = default); -} +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/Common/Mappings/PruductCategoryProfile.cs b/src/CMSMicroservice.Application/Common/Mappings/PruductCategoryProfile.cs new file mode 100644 index 0000000..f2d3316 --- /dev/null +++ b/src/CMSMicroservice.Application/Common/Mappings/PruductCategoryProfile.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.Application.Common.Mappings; + +public class PruductCategoryProfile : IRegister +{ + void IRegister.Register(TypeAdapterConfig config) + { + //config.NewConfig() + // .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}"); + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommand.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommand.cs new file mode 100644 index 0000000..968944b --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommand.cs @@ -0,0 +1,9 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory; +public record CreateNewPruductCategoryCommand : IRequest +{ + //شناسه محصول + public string ProductId { get; init; } + //شناسه دسته بندی + public string CategoryId { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandHandler.cs new file mode 100644 index 0000000..fea7cca --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandHandler.cs @@ -0,0 +1,21 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory; +public class CreateNewPruductCategoryCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public CreateNewPruductCategoryCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(CreateNewPruductCategoryCommand request, + CancellationToken cancellationToken) + { + var entity = request.Adapt(); + await _context.PruductCategorys.AddAsync(entity, cancellationToken); + entity.AddDomainEvent(new CreateNewPruductCategoryEvent(entity)); + await _context.SaveChangesAsync(cancellationToken); + return entity.Adapt(); + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandValidator.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandValidator.cs new file mode 100644 index 0000000..ed3950e --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryCommandValidator.cs @@ -0,0 +1,18 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory; +public class CreateNewPruductCategoryCommandValidator : AbstractValidator +{ + public CreateNewPruductCategoryCommandValidator() + { + RuleFor(model => model.ProductId) + .NotEmpty(); + RuleFor(model => model.CategoryId) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateNewPruductCategoryCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryResponseDto.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryResponseDto.cs new file mode 100644 index 0000000..3ae52b0 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/CreateNewPruductCategory/CreateNewPruductCategoryResponseDto.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory; +public class CreateNewPruductCategoryResponseDto +{ + //شناسه + public long Id { get; set; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommand.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommand.cs new file mode 100644 index 0000000..b1446e0 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommand.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory; +public record DeletePruductCategoryCommand : IRequest +{ + //شناسه + public long Id { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandHandler.cs new file mode 100644 index 0000000..e93487a --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory; +public class DeletePruductCategoryCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public DeletePruductCategoryCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task 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; + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandValidator.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandValidator.cs new file mode 100644 index 0000000..2d4aa9e --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/DeletePruductCategory/DeletePruductCategoryCommandValidator.cs @@ -0,0 +1,16 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory; +public class DeletePruductCategoryCommandValidator : AbstractValidator +{ + public DeletePruductCategoryCommandValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((DeletePruductCategoryCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommand.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommand.cs new file mode 100644 index 0000000..275f891 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommand.cs @@ -0,0 +1,11 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory; +public record UpdatePruductCategoryCommand : IRequest +{ + //شناسه + public long Id { get; init; } + //شناسه محصول + public string ProductId { get; init; } + //شناسه دسته بندی + public string CategoryId { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandHandler.cs new file mode 100644 index 0000000..f6ae54a --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory; +public class UpdatePruductCategoryCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public UpdatePruductCategoryCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task 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; + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandValidator.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandValidator.cs new file mode 100644 index 0000000..455e3ed --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Commands/UpdatePruductCategory/UpdatePruductCategoryCommandValidator.cs @@ -0,0 +1,20 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory; +public class UpdatePruductCategoryCommandValidator : AbstractValidator +{ + public UpdatePruductCategoryCommandValidator() + { + RuleFor(model => model.Id) + .NotNull(); + RuleFor(model => model.ProductId) + .NotEmpty(); + RuleFor(model => model.CategoryId) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((UpdatePruductCategoryCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/CreateNewPruductCategoryEventHandlers/CreateNewPruductCategoryEventHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/CreateNewPruductCategoryEventHandlers/CreateNewPruductCategoryEventHandler.cs new file mode 100644 index 0000000..9fa2fd5 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/CreateNewPruductCategoryEventHandlers/CreateNewPruductCategoryEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers; + +public class CreateNewPruductCategoryEventHandler : INotificationHandler +{ + private readonly ILogger< + CreateNewPruductCategoryEventHandler> _logger; + + public CreateNewPruductCategoryEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(CreateNewPruductCategoryEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/DeletePruductCategoryEventHandlers/DeletePruductCategoryEventHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/DeletePruductCategoryEventHandlers/DeletePruductCategoryEventHandler.cs new file mode 100644 index 0000000..1490cab --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/DeletePruductCategoryEventHandlers/DeletePruductCategoryEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers; + +public class DeletePruductCategoryEventHandler : INotificationHandler +{ + private readonly ILogger< + DeletePruductCategoryEventHandler> _logger; + + public DeletePruductCategoryEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(DeletePruductCategoryEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/UpdatePruductCategoryEventHandlers/UpdatePruductCategoryEventHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/UpdatePruductCategoryEventHandlers/UpdatePruductCategoryEventHandler.cs new file mode 100644 index 0000000..42fade5 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/EventHandlers/UpdatePruductCategoryEventHandlers/UpdatePruductCategoryEventHandler.cs @@ -0,0 +1,22 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers; + +public class UpdatePruductCategoryEventHandler : INotificationHandler +{ + private readonly ILogger< + UpdatePruductCategoryEventHandler> _logger; + + public UpdatePruductCategoryEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(UpdatePruductCategoryEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQuery.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQuery.cs new file mode 100644 index 0000000..89ba6f9 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQuery.cs @@ -0,0 +1,19 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter; +public record GetAllPruductCategoryByFilterQuery : IRequest +{ + //موقعیت صفحه بندی + 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; } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryHandler.cs new file mode 100644 index 0000000..21db9e0 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryHandler.cs @@ -0,0 +1,32 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter; +public class GetAllPruductCategoryByFilterQueryHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public GetAllPruductCategoryByFilterQueryHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task 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().ToListAsync(cancellationToken) + }; + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryValidator.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryValidator.cs new file mode 100644 index 0000000..dac1c0b --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterQueryValidator.cs @@ -0,0 +1,14 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter; +public class GetAllPruductCategoryByFilterQueryValidator : AbstractValidator +{ + public GetAllPruductCategoryByFilterQueryValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllPruductCategoryByFilterQuery)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterResponseDto.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterResponseDto.cs new file mode 100644 index 0000000..8e3c303 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetAllPruductCategoryByFilter/GetAllPruductCategoryByFilterResponseDto.cs @@ -0,0 +1,17 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter; +public class GetAllPruductCategoryByFilterResponseDto +{ + //متادیتا + public MetaData MetaData { get; set; } + //مدل خروجی + public List? Models { get; set; } + +}public class GetAllPruductCategoryByFilterResponseModel +{ + //شناسه + public long Id { get; set; } + //شناسه محصول + public string ProductId { get; set; } + //شناسه دسته بندی + public string CategoryId { get; set; } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQuery.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQuery.cs new file mode 100644 index 0000000..fef2914 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQuery.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory; +public record GetPruductCategoryQuery : IRequest +{ + //شناسه + public long Id { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryHandler.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryHandler.cs new file mode 100644 index 0000000..d36c484 --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryHandler.cs @@ -0,0 +1,22 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory; +public class GetPruductCategoryQueryHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public GetPruductCategoryQueryHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(GetPruductCategoryQuery request, + CancellationToken cancellationToken) + { + var response = await _context.PruductCategorys + .AsNoTracking() + .Where(x => x.Id == request.Id) + .ProjectToType() + .FirstOrDefaultAsync(cancellationToken); + + return response ?? throw new NotFoundException(nameof(PruductCategory), request.Id); + } +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryValidator.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryValidator.cs new file mode 100644 index 0000000..8bb4a8d --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryQueryValidator.cs @@ -0,0 +1,16 @@ +namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory; +public class GetPruductCategoryQueryValidator : AbstractValidator +{ + public GetPruductCategoryQueryValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetPruductCategoryQuery)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryResponseDto.cs b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryResponseDto.cs new file mode 100644 index 0000000..e6ca0be --- /dev/null +++ b/src/CMSMicroservice.Application/PruductCategoryCQ/Queries/GetPruductCategory/GetPruductCategoryResponseDto.cs @@ -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; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Domain/Entities/Category.cs b/src/CMSMicroservice.Domain/Entities/Category.cs index 00f2b45..d8936a6 100644 --- a/src/CMSMicroservice.Domain/Entities/Category.cs +++ b/src/CMSMicroservice.Domain/Entities/Category.cs @@ -2,23 +2,24 @@ namespace CMSMicroservice.Domain.Entities; //دسته بندی public class Category : BaseAuditableEntity { - //نام لاتین + //نام لاتین public string Name { get; set; } - //عنوان + //عنوان public string Title { get; set; } - //توضیحات + //توضیحات public string? Description { get; set; } - //آدرس تصویر + //آدرس تصویر public string? ImagePath { get; set; } - //شناسه والد + //شناسه والد public long? ParentId { get; set; } - //Category Navigation Property + //Category Navigation Property public virtual Category? Parent { get; set; } - //Category Collection Navigation Reference - public virtual ICollection Categories { get; set; } - //فعال؟ + //فعال؟ public bool IsActive { get; set; } - //ترتیب نمایش + //ترتیب نمایش public int SortOrder { get; set; } + //Category Collection Navigation Reference + public virtual ICollection Categorys { get; set; } + //PruductCategory Collection Navigation Reference + public virtual ICollection PruductCategorys { get; set; } } - diff --git a/src/CMSMicroservice.Domain/Entities/Products.cs b/src/CMSMicroservice.Domain/Entities/Products.cs index 1edf26d..4eaaee2 100644 --- a/src/CMSMicroservice.Domain/Entities/Products.cs +++ b/src/CMSMicroservice.Domain/Entities/Products.cs @@ -20,4 +20,6 @@ public class Products : BaseAuditableEntity public virtual ICollection ProductGalleryss { get; set; } //FactorDetails Collection Navigation Reference public virtual ICollection FactorDetailss { get; set; } + //PruductCategory Collection Navigation Reference + public virtual ICollection PruductCategorys { get; set; } } diff --git a/src/CMSMicroservice.Domain/Entities/PruductCategory.cs b/src/CMSMicroservice.Domain/Entities/PruductCategory.cs new file mode 100644 index 0000000..2438305 --- /dev/null +++ b/src/CMSMicroservice.Domain/Entities/PruductCategory.cs @@ -0,0 +1,13 @@ +namespace CMSMicroservice.Domain.Entities; +//دسته بندی +public class PruductCategory : BaseAuditableEntity +{ + //شناسه محصول + public string ProductId { get; set; } + //Product Navigation Property + public virtual Products Product { get; set; } + //شناسه دسته بندی + public string CategoryId { get; set; } + //Category Navigation Property + public virtual Category Category { get; set; } +} diff --git a/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/CreateNewPruductCategoryEvent.cs b/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/CreateNewPruductCategoryEvent.cs new file mode 100644 index 0000000..1697673 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/CreateNewPruductCategoryEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class CreateNewPruductCategoryEvent : BaseEvent +{ + public CreateNewPruductCategoryEvent(PruductCategory item) + { + } + public PruductCategory Item { get; } +} diff --git a/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/DeletePruductCategoryEvent.cs b/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/DeletePruductCategoryEvent.cs new file mode 100644 index 0000000..cf5e078 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/DeletePruductCategoryEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class DeletePruductCategoryEvent : BaseEvent +{ + public DeletePruductCategoryEvent(PruductCategory item) + { + } + public PruductCategory Item { get; } +} diff --git a/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/UpdatePruductCategoryEvent.cs b/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/UpdatePruductCategoryEvent.cs new file mode 100644 index 0000000..5604531 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/PruductCategoryEvents/UpdatePruductCategoryEvent.cs @@ -0,0 +1,8 @@ +namespace CMSMicroservice.Domain.Events; +public class UpdatePruductCategoryEvent : BaseEvent +{ + public UpdatePruductCategoryEvent(PruductCategory item) + { + } + public PruductCategory Item { get; } +} diff --git a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs index 1cb6bda..633f76d 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs @@ -41,8 +41,8 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext } public DbSet UserAddresss => Set(); public DbSet Packages => Set(); - public DbSet Categories => Set(); public DbSet Roles => Set(); + public DbSet Categorys => Set(); public DbSet UserRoles => Set(); public DbSet UserWallets => Set(); public DbSet UserWalletChangeLogs => Set(); @@ -57,4 +57,5 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext public DbSet OtpTokens => Set(); public DbSet Contracts => Set(); public DbSet UserContracts => Set(); + public DbSet PruductCategorys => Set(); } diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/PruductCategoryConfiguration.cs b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/PruductCategoryConfiguration.cs new file mode 100644 index 0000000..43b1e9d --- /dev/null +++ b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/PruductCategoryConfiguration.cs @@ -0,0 +1,26 @@ +using CMSMicroservice.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +namespace CMSMicroservice.Infrastructure.Persistence.Configurations; +//دسته بندی +public class PruductCategoryConfiguration : 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.Product) + .WithMany(entity => entity.ProductPruductCategorys) + .HasForeignKey(entity => entity.ProductId) + .IsRequired(true); + builder + .HasOne(entity => entity.Category) + .WithMany(entity => entity.PruductCategorys) + .HasForeignKey(entity => entity.CategoryId) + .IsRequired(true); + + } +} diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs index 5eac832..54ab59e 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs @@ -1,9 +1,8 @@ using CMSMicroservice.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; - namespace CMSMicroservice.Infrastructure.Persistence.Configurations; - +//کاربر public class UserConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) @@ -31,5 +30,7 @@ public class UserConfiguration : IEntityTypeConfiguration builder.Property(entity => entity.SmsNotifications).IsRequired(true); builder.Property(entity => entity.PushNotifications).IsRequired(true); builder.Property(entity => entity.BirthDate).IsRequired(false); + builder.Property(entity => entity.HashPassword).IsRequired(false); + } -} \ No newline at end of file +} diff --git a/src/CMSMicroservice.Protobuf/Protos/category.proto b/src/CMSMicroservice.Protobuf/Protos/category.proto new file mode 100644 index 0000000..74928cc --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Protos/category.proto @@ -0,0 +1,123 @@ +syntax = "proto3"; + +package category; + +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.Category"; + +service CategoryContract +{ + rpc CreateNewCategory(CreateNewCategoryRequest) returns (CreateNewCategoryResponse){ + option (google.api.http) = { + post: "/CreateNewCategory" + body: "*" + }; + }; + rpc UpdateCategory(UpdateCategoryRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + put: "/UpdateCategory" + body: "*" + }; + }; + rpc DeleteCategory(DeleteCategoryRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + delete: "/DeleteCategory" + body: "*" + }; + }; + rpc GetCategory(GetCategoryRequest) returns (GetCategoryResponse){ + option (google.api.http) = { + get: "/GetCategory" + + }; + }; + rpc GetAllCategoryByFilter(GetAllCategoryByFilterRequest) returns (GetAllCategoryByFilterResponse){ + option (google.api.http) = { + get: "/GetAllCategoryByFilter" + + }; + }; +} +message CreateNewCategoryRequest +{ + string name = 1; + string title = 2; + google.protobuf.StringValue description = 3; + google.protobuf.StringValue image_path = 4; + google.protobuf.Int64Value parent_id = 5; + bool is_active = 6; + int32 sort_order = 7; +} +message CreateNewCategoryResponse +{ + int64 id = 1; +} +message UpdateCategoryRequest +{ + int64 id = 1; + string name = 2; + string title = 3; + google.protobuf.StringValue description = 4; + google.protobuf.StringValue image_path = 5; + google.protobuf.Int64Value parent_id = 6; + bool is_active = 7; + int32 sort_order = 8; +} +message DeleteCategoryRequest +{ + int64 id = 1; +} +message GetCategoryRequest +{ + int64 id = 1; +} +message GetCategoryResponse +{ + int64 id = 1; + string name = 2; + string title = 3; + google.protobuf.StringValue description = 4; + google.protobuf.StringValue image_path = 5; + google.protobuf.Int64Value parent_id = 6; + bool is_active = 7; + int32 sort_order = 8; +} +message GetAllCategoryByFilterRequest +{ + messages.PaginationState pagination_state = 1; + google.protobuf.StringValue sort_by = 2; + GetAllCategoryByFilterFilter filter = 3; +} +message GetAllCategoryByFilterFilter +{ + google.protobuf.Int64Value id = 1; + google.protobuf.StringValue name = 2; + google.protobuf.StringValue title = 3; + google.protobuf.StringValue description = 4; + google.protobuf.StringValue image_path = 5; + google.protobuf.Int64Value parent_id = 6; + google.protobuf.BoolValue is_active = 7; + google.protobuf.Int32Value sort_order = 8; +} +message GetAllCategoryByFilterResponse +{ + messages.MetaData meta_data = 1; + repeated GetAllCategoryByFilterResponseModel models = 2; +} +message GetAllCategoryByFilterResponseModel +{ + int64 id = 1; + string name = 2; + string title = 3; + google.protobuf.StringValue description = 4; + google.protobuf.StringValue image_path = 5; + google.protobuf.Int64Value parent_id = 6; + bool is_active = 7; + int32 sort_order = 8; +} diff --git a/src/CMSMicroservice.Protobuf/Protos/pruductcategory.proto b/src/CMSMicroservice.Protobuf/Protos/pruductcategory.proto new file mode 100644 index 0000000..3fbed21 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Protos/pruductcategory.proto @@ -0,0 +1,98 @@ +syntax = "proto3"; + +package pruductcategory; + +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.PruductCategory"; + +service PruductCategoryContract +{ + rpc CreateNewPruductCategory(CreateNewPruductCategoryRequest) returns (CreateNewPruductCategoryResponse){ + option (google.api.http) = { + post: "/CreateNewPruductCategory" + body: "*" + }; + }; + rpc UpdatePruductCategory(UpdatePruductCategoryRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + put: "/UpdatePruductCategory" + body: "*" + }; + }; + rpc DeletePruductCategory(DeletePruductCategoryRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + delete: "/DeletePruductCategory" + body: "*" + }; + }; + rpc GetPruductCategory(GetPruductCategoryRequest) returns (GetPruductCategoryResponse){ + option (google.api.http) = { + get: "/GetPruductCategory" + + }; + }; + rpc GetAllPruductCategoryByFilter(GetAllPruductCategoryByFilterRequest) returns (GetAllPruductCategoryByFilterResponse){ + option (google.api.http) = { + get: "/GetAllPruductCategoryByFilter" + + }; + }; +} +message CreateNewPruductCategoryRequest +{ + string product_id = 1; + string category_id = 2; +} +message CreateNewPruductCategoryResponse +{ + int64 id = 1; +} +message UpdatePruductCategoryRequest +{ + int64 id = 1; + string product_id = 2; + string category_id = 3; +} +message DeletePruductCategoryRequest +{ + int64 id = 1; +} +message GetPruductCategoryRequest +{ + int64 id = 1; +} +message GetPruductCategoryResponse +{ + int64 id = 1; + string product_id = 2; + string category_id = 3; +} +message GetAllPruductCategoryByFilterRequest +{ + messages.PaginationState pagination_state = 1; + google.protobuf.StringValue sort_by = 2; + GetAllPruductCategoryByFilterFilter filter = 3; +} +message GetAllPruductCategoryByFilterFilter +{ + google.protobuf.Int64Value id = 1; + google.protobuf.StringValue product_id = 2; + google.protobuf.StringValue category_id = 3; +} +message GetAllPruductCategoryByFilterResponse +{ + messages.MetaData meta_data = 1; + repeated GetAllPruductCategoryByFilterResponseModel models = 2; +} +message GetAllPruductCategoryByFilterResponseModel +{ + int64 id = 1; + string product_id = 2; + string category_id = 3; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/Category/CreateNewCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Category/CreateNewCategoryRequestValidator.cs new file mode 100644 index 0000000..b507c2d --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Category/CreateNewCategoryRequestValidator.cs @@ -0,0 +1,25 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Category; +namespace CMSMicroservice.Protobuf.Validator.Category; + +public class CreateNewCategoryRequestValidator : AbstractValidator +{ + public CreateNewCategoryRequestValidator() + { + RuleFor(model => model.Name) + .NotEmpty(); + RuleFor(model => model.Title) + .NotEmpty(); + RuleFor(model => model.IsActive) + .NotNull(); + RuleFor(model => model.SortOrder) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateNewCategoryRequest)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/Category/DeleteCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Category/DeleteCategoryRequestValidator.cs new file mode 100644 index 0000000..4b8b284 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Category/DeleteCategoryRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Category; +namespace CMSMicroservice.Protobuf.Validator.Category; + +public class DeleteCategoryRequestValidator : AbstractValidator +{ + public DeleteCategoryRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((DeleteCategoryRequest)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/Category/GetAllCategoryByFilterRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Category/GetAllCategoryByFilterRequestValidator.cs new file mode 100644 index 0000000..87cc627 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Category/GetAllCategoryByFilterRequestValidator.cs @@ -0,0 +1,17 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Category; +namespace CMSMicroservice.Protobuf.Validator.Category; + +public class GetAllCategoryByFilterRequestValidator : AbstractValidator +{ + public GetAllCategoryByFilterRequestValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllCategoryByFilterRequest)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/Category/GetCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Category/GetCategoryRequestValidator.cs new file mode 100644 index 0000000..c04d609 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Category/GetCategoryRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Category; +namespace CMSMicroservice.Protobuf.Validator.Category; + +public class GetCategoryRequestValidator : AbstractValidator +{ + public GetCategoryRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetCategoryRequest)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/Category/UpdateCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/Category/UpdateCategoryRequestValidator.cs new file mode 100644 index 0000000..f3ab985 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/Category/UpdateCategoryRequestValidator.cs @@ -0,0 +1,27 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.Category; +namespace CMSMicroservice.Protobuf.Validator.Category; + +public class UpdateCategoryRequestValidator : AbstractValidator +{ + public UpdateCategoryRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + RuleFor(model => model.Name) + .NotEmpty(); + RuleFor(model => model.Title) + .NotEmpty(); + RuleFor(model => model.IsActive) + .NotNull(); + RuleFor(model => model.SortOrder) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((UpdateCategoryRequest)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/PruductCategory/CreateNewPruductCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/CreateNewPruductCategoryRequestValidator.cs new file mode 100644 index 0000000..bae94c8 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/CreateNewPruductCategoryRequestValidator.cs @@ -0,0 +1,21 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.PruductCategory; +namespace CMSMicroservice.Protobuf.Validator.PruductCategory; + +public class CreateNewPruductCategoryRequestValidator : AbstractValidator +{ + public CreateNewPruductCategoryRequestValidator() + { + RuleFor(model => model.ProductId) + .NotEmpty(); + RuleFor(model => model.CategoryId) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateNewPruductCategoryRequest)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/PruductCategory/DeletePruductCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/DeletePruductCategoryRequestValidator.cs new file mode 100644 index 0000000..fe12af0 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/DeletePruductCategoryRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.PruductCategory; +namespace CMSMicroservice.Protobuf.Validator.PruductCategory; + +public class DeletePruductCategoryRequestValidator : AbstractValidator +{ + public DeletePruductCategoryRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((DeletePruductCategoryRequest)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/PruductCategory/GetAllPruductCategoryByFilterRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/GetAllPruductCategoryByFilterRequestValidator.cs new file mode 100644 index 0000000..66206da --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/GetAllPruductCategoryByFilterRequestValidator.cs @@ -0,0 +1,17 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.PruductCategory; +namespace CMSMicroservice.Protobuf.Validator.PruductCategory; + +public class GetAllPruductCategoryByFilterRequestValidator : AbstractValidator +{ + public GetAllPruductCategoryByFilterRequestValidator() + { + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetAllPruductCategoryByFilterRequest)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/PruductCategory/GetPruductCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/GetPruductCategoryRequestValidator.cs new file mode 100644 index 0000000..3b751ea --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/GetPruductCategoryRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.PruductCategory; +namespace CMSMicroservice.Protobuf.Validator.PruductCategory; + +public class GetPruductCategoryRequestValidator : AbstractValidator +{ + public GetPruductCategoryRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((GetPruductCategoryRequest)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/PruductCategory/UpdatePruductCategoryRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/UpdatePruductCategoryRequestValidator.cs new file mode 100644 index 0000000..2bf4c71 --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/PruductCategory/UpdatePruductCategoryRequestValidator.cs @@ -0,0 +1,23 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.PruductCategory; +namespace CMSMicroservice.Protobuf.Validator.PruductCategory; + +public class UpdatePruductCategoryRequestValidator : AbstractValidator +{ + public UpdatePruductCategoryRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + RuleFor(model => model.ProductId) + .NotEmpty(); + RuleFor(model => model.CategoryId) + .NotEmpty(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((UpdatePruductCategoryRequest)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/CategoryProfile.cs b/src/CMSMicroservice.WebApi/Common/Mappings/CategoryProfile.cs new file mode 100644 index 0000000..713a3f8 --- /dev/null +++ b/src/CMSMicroservice.WebApi/Common/Mappings/CategoryProfile.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.WebApi.Common.Mappings; + +public class CategoryProfile : IRegister +{ + void IRegister.Register(TypeAdapterConfig config) + { + //config.NewConfig() + // .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}"); + } +} diff --git a/src/CMSMicroservice.WebApi/Common/Mappings/PruductCategoryProfile.cs b/src/CMSMicroservice.WebApi/Common/Mappings/PruductCategoryProfile.cs new file mode 100644 index 0000000..181037d --- /dev/null +++ b/src/CMSMicroservice.WebApi/Common/Mappings/PruductCategoryProfile.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.WebApi.Common.Mappings; + +public class PruductCategoryProfile : IRegister +{ + void IRegister.Register(TypeAdapterConfig config) + { + //config.NewConfig() + // .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}"); + } +} diff --git a/src/CMSMicroservice.WebApi/Services/CategoryService.cs b/src/CMSMicroservice.WebApi/Services/CategoryService.cs new file mode 100644 index 0000000..318c144 --- /dev/null +++ b/src/CMSMicroservice.WebApi/Services/CategoryService.cs @@ -0,0 +1,37 @@ +using CMSMicroservice.Protobuf.Protos.Category; +using CMSMicroservice.WebApi.Common.Services; +using CMSMicroservice.Application.CategoryCQ.Commands.CreateNewCategory; +using CMSMicroservice.Application.CategoryCQ.Commands.UpdateCategory; +using CMSMicroservice.Application.CategoryCQ.Commands.DeleteCategory; +using CMSMicroservice.Application.CategoryCQ.Queries.GetCategory; +using CMSMicroservice.Application.CategoryCQ.Queries.GetAllCategoryByFilter; +namespace CMSMicroservice.WebApi.Services; +public class CategoryService : CategoryContract.CategoryContractBase +{ + private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS; + + public CategoryService(IDispatchRequestToCQRS dispatchRequestToCQRS) + { + _dispatchRequestToCQRS = dispatchRequestToCQRS; + } + public override async Task CreateNewCategory(CreateNewCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task UpdateCategory(UpdateCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task DeleteCategory(DeleteCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetCategory(GetCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetAllCategoryByFilter(GetAllCategoryByFilterRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } +} diff --git a/src/CMSMicroservice.WebApi/Services/PruductCategoryService.cs b/src/CMSMicroservice.WebApi/Services/PruductCategoryService.cs new file mode 100644 index 0000000..0f5d244 --- /dev/null +++ b/src/CMSMicroservice.WebApi/Services/PruductCategoryService.cs @@ -0,0 +1,37 @@ +using CMSMicroservice.Protobuf.Protos.PruductCategory; +using CMSMicroservice.WebApi.Common.Services; +using CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory; +using CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory; +using CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory; +using CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory; +using CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter; +namespace CMSMicroservice.WebApi.Services; +public class PruductCategoryService : PruductCategoryContract.PruductCategoryContractBase +{ + private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS; + + public PruductCategoryService(IDispatchRequestToCQRS dispatchRequestToCQRS) + { + _dispatchRequestToCQRS = dispatchRequestToCQRS; + } + public override async Task CreateNewPruductCategory(CreateNewPruductCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task UpdatePruductCategory(UpdatePruductCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task DeletePruductCategory(DeletePruductCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetPruductCategory(GetPruductCategoryRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } + public override async Task GetAllPruductCategoryByFilter(GetAllPruductCategoryByFilterRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } +}