Generator Changes at 11/17/2025 11:53:47 PM +03:30

This commit is contained in:
masoodafar-web
2025-11-17 23:57:51 +03:30
parent da07a3da38
commit dba8aecc97
50 changed files with 978 additions and 19 deletions

View File

@@ -7,6 +7,8 @@ public class CreateNewCategoryCommandValidator : AbstractValidator<CreateNewCate
.NotEmpty();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.IsActive)
.NotNull();
RuleFor(model => model.SortOrder)
.NotNull();
}
@@ -18,4 +20,3 @@ public class CreateNewCategoryCommandValidator : AbstractValidator<CreateNewCate
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -9,6 +9,8 @@ public class UpdateCategoryCommandValidator : AbstractValidator<UpdateCategoryCo
.NotEmpty();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.IsActive)
.NotNull();
RuleFor(model => model.SortOrder)
.NotNull();
}
@@ -20,4 +22,3 @@ public class UpdateCategoryCommandValidator : AbstractValidator<UpdateCategoryCo
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -4,8 +4,8 @@ public interface IApplicationDbContext
{
DbSet<UserAddress> UserAddresss { get; }
DbSet<Package> Packages { get; }
DbSet<Category> Categories { get; }
DbSet<Role> Roles { get; }
DbSet<Category> Categorys { get; }
DbSet<UserRole> UserRoles { get; }
DbSet<UserWallet> UserWallets { get; }
DbSet<UserWalletChangeLog> UserWalletChangeLogs { get; }
@@ -20,5 +20,6 @@ public interface IApplicationDbContext
DbSet<OtpToken> OtpTokens { get; }
DbSet<Contract> Contracts { get; }
DbSet<UserContract> UserContracts { get; }
DbSet<PruductCategory> PruductCategorys { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.Application.Common.Mappings;
public class PruductCategoryProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
}
}

View File

@@ -0,0 +1,9 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory;
public record CreateNewPruductCategoryCommand : IRequest<CreateNewPruductCategoryResponseDto>
{
//شناسه محصول
public string ProductId { get; init; }
//شناسه دسته بندی
public string CategoryId { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory;
public class CreateNewPruductCategoryCommandHandler : IRequestHandler<CreateNewPruductCategoryCommand, CreateNewPruductCategoryResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewPruductCategoryCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewPruductCategoryResponseDto> Handle(CreateNewPruductCategoryCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<PruductCategory>();
await _context.PruductCategorys.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewPruductCategoryEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewPruductCategoryResponseDto>();
}
}

View File

@@ -0,0 +1,18 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory;
public class CreateNewPruductCategoryCommandValidator : AbstractValidator<CreateNewPruductCategoryCommand>
{
public CreateNewPruductCategoryCommandValidator()
{
RuleFor(model => model.ProductId)
.NotEmpty();
RuleFor(model => model.CategoryId)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewPruductCategoryCommand>.CreateWithOptions((CreateNewPruductCategoryCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.CreateNewPruductCategory;
public class CreateNewPruductCategoryResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory;
public record DeletePruductCategoryCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory;
public class DeletePruductCategoryCommandHandler : IRequestHandler<DeletePruductCategoryCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeletePruductCategoryCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeletePruductCategoryCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PruductCategorys
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(PruductCategory), request.Id);
entity.IsDeleted = true;
_context.PruductCategorys.Update(entity);
entity.AddDomainEvent(new DeletePruductCategoryEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.DeletePruductCategory;
public class DeletePruductCategoryCommandValidator : AbstractValidator<DeletePruductCategoryCommand>
{
public DeletePruductCategoryCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeletePruductCategoryCommand>.CreateWithOptions((DeletePruductCategoryCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory;
public record UpdatePruductCategoryCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//شناسه محصول
public string ProductId { get; init; }
//شناسه دسته بندی
public string CategoryId { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory;
public class UpdatePruductCategoryCommandHandler : IRequestHandler<UpdatePruductCategoryCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdatePruductCategoryCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdatePruductCategoryCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PruductCategorys
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(PruductCategory), request.Id);
request.Adapt(entity);
_context.PruductCategorys.Update(entity);
entity.AddDomainEvent(new UpdatePruductCategoryEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,20 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Commands.UpdatePruductCategory;
public class UpdatePruductCategoryCommandValidator : AbstractValidator<UpdatePruductCategoryCommand>
{
public UpdatePruductCategoryCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.ProductId)
.NotEmpty();
RuleFor(model => model.CategoryId)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdatePruductCategoryCommand>.CreateWithOptions((UpdatePruductCategoryCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers;
public class CreateNewPruductCategoryEventHandler : INotificationHandler<CreateNewPruductCategoryEvent>
{
private readonly ILogger<
CreateNewPruductCategoryEventHandler> _logger;
public CreateNewPruductCategoryEventHandler(ILogger<CreateNewPruductCategoryEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewPruductCategoryEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers;
public class DeletePruductCategoryEventHandler : INotificationHandler<DeletePruductCategoryEvent>
{
private readonly ILogger<
DeletePruductCategoryEventHandler> _logger;
public DeletePruductCategoryEventHandler(ILogger<DeletePruductCategoryEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeletePruductCategoryEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.PruductCategoryCQ.EventHandlers;
public class UpdatePruductCategoryEventHandler : INotificationHandler<UpdatePruductCategoryEvent>
{
private readonly ILogger<
UpdatePruductCategoryEventHandler> _logger;
public UpdatePruductCategoryEventHandler(ILogger<UpdatePruductCategoryEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdatePruductCategoryEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
public record GetAllPruductCategoryByFilterQuery : IRequest<GetAllPruductCategoryByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllPruductCategoryByFilterFilter? Filter { get; init; }
}public class GetAllPruductCategoryByFilterFilter
{
//شناسه
public long? Id { get; set; }
//شناسه محصول
public string? ProductId { get; set; }
//شناسه دسته بندی
public string? CategoryId { get; set; }
}

View File

@@ -0,0 +1,32 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
public class GetAllPruductCategoryByFilterQueryHandler : IRequestHandler<GetAllPruductCategoryByFilterQuery, GetAllPruductCategoryByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllPruductCategoryByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllPruductCategoryByFilterResponseDto> Handle(GetAllPruductCategoryByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.PruductCategorys
.ApplyOrder(sortBy: request.SortBy)
.AsNoTracking()
.AsQueryable();
if (request.Filter is not null)
{
query = query
.Where(x => request.Filter.Id == null || x.Id == request.Filter.Id)
.Where(x => request.Filter.ProductId == null || x.ProductId.Contains(request.Filter.ProductId))
.Where(x => request.Filter.CategoryId == null || x.CategoryId.Contains(request.Filter.CategoryId))
;
}
return new GetAllPruductCategoryByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllPruductCategoryByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
public class GetAllPruductCategoryByFilterQueryValidator : AbstractValidator<GetAllPruductCategoryByFilterQuery>
{
public GetAllPruductCategoryByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllPruductCategoryByFilterQuery>.CreateWithOptions((GetAllPruductCategoryByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,17 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetAllPruductCategoryByFilter;
public class GetAllPruductCategoryByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllPruductCategoryByFilterResponseModel>? Models { get; set; }
}public class GetAllPruductCategoryByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//شناسه محصول
public string ProductId { get; set; }
//شناسه دسته بندی
public string CategoryId { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory;
public record GetPruductCategoryQuery : IRequest<GetPruductCategoryResponseDto>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory;
public class GetPruductCategoryQueryHandler : IRequestHandler<GetPruductCategoryQuery, GetPruductCategoryResponseDto>
{
private readonly IApplicationDbContext _context;
public GetPruductCategoryQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetPruductCategoryResponseDto> Handle(GetPruductCategoryQuery request,
CancellationToken cancellationToken)
{
var response = await _context.PruductCategorys
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetPruductCategoryResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(PruductCategory), request.Id);
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.PruductCategoryCQ.Queries.GetPruductCategory;
public class GetPruductCategoryQueryValidator : AbstractValidator<GetPruductCategoryQuery>
{
public GetPruductCategoryQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetPruductCategoryQuery>.CreateWithOptions((GetPruductCategoryQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -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; }
}

View File

@@ -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<Category> Categories { get; set; }
//فعال؟
//فعال؟
public bool IsActive { get; set; }
//ترتیب نمایش
//ترتیب نمایش
public int SortOrder { get; set; }
//Category Collection Navigation Reference
public virtual ICollection<Category> Categorys { get; set; }
//PruductCategory Collection Navigation Reference
public virtual ICollection<PruductCategory> PruductCategorys { get; set; }
}

View File

@@ -20,4 +20,6 @@ public class Products : BaseAuditableEntity
public virtual ICollection<ProductGallerys> ProductGalleryss { get; set; }
//FactorDetails Collection Navigation Reference
public virtual ICollection<FactorDetails> FactorDetailss { get; set; }
//PruductCategory Collection Navigation Reference
public virtual ICollection<PruductCategory> PruductCategorys { get; set; }
}

View File

@@ -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; }
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Domain.Events;
public class CreateNewPruductCategoryEvent : BaseEvent
{
public CreateNewPruductCategoryEvent(PruductCategory item)
{
}
public PruductCategory Item { get; }
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Domain.Events;
public class DeletePruductCategoryEvent : BaseEvent
{
public DeletePruductCategoryEvent(PruductCategory item)
{
}
public PruductCategory Item { get; }
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Domain.Events;
public class UpdatePruductCategoryEvent : BaseEvent
{
public UpdatePruductCategoryEvent(PruductCategory item)
{
}
public PruductCategory Item { get; }
}

View File

@@ -41,8 +41,8 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
}
public DbSet<UserAddress> UserAddresss => Set<UserAddress>();
public DbSet<Package> Packages => Set<Package>();
public DbSet<Category> Categories => Set<Category>();
public DbSet<Role> Roles => Set<Role>();
public DbSet<Category> Categorys => Set<Category>();
public DbSet<UserRole> UserRoles => Set<UserRole>();
public DbSet<UserWallet> UserWallets => Set<UserWallet>();
public DbSet<UserWalletChangeLog> UserWalletChangeLogs => Set<UserWalletChangeLog>();
@@ -57,4 +57,5 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
public DbSet<OtpToken> OtpTokens => Set<OtpToken>();
public DbSet<Contract> Contracts => Set<Contract>();
public DbSet<UserContract> UserContracts => Set<UserContract>();
public DbSet<PruductCategory> PruductCategorys => Set<PruductCategory>();
}

View File

@@ -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<PruductCategory>
{
public void Configure(EntityTypeBuilder<PruductCategory> 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);
}
}

View File

@@ -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<User>
{
public void Configure(EntityTypeBuilder<User> builder)
@@ -31,5 +30,7 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
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);
}
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,25 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.Category;
namespace CMSMicroservice.Protobuf.Validator.Category;
public class CreateNewCategoryRequestValidator : AbstractValidator<CreateNewCategoryRequest>
{
public CreateNewCategoryRequestValidator()
{
RuleFor(model => model.Name)
.NotEmpty();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.IsActive)
.NotNull();
RuleFor(model => model.SortOrder)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewCategoryRequest>.CreateWithOptions((CreateNewCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,19 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.Category;
namespace CMSMicroservice.Protobuf.Validator.Category;
public class DeleteCategoryRequestValidator : AbstractValidator<DeleteCategoryRequest>
{
public DeleteCategoryRequestValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteCategoryRequest>.CreateWithOptions((DeleteCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,17 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.Category;
namespace CMSMicroservice.Protobuf.Validator.Category;
public class GetAllCategoryByFilterRequestValidator : AbstractValidator<GetAllCategoryByFilterRequest>
{
public GetAllCategoryByFilterRequestValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllCategoryByFilterRequest>.CreateWithOptions((GetAllCategoryByFilterRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,19 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.Category;
namespace CMSMicroservice.Protobuf.Validator.Category;
public class GetCategoryRequestValidator : AbstractValidator<GetCategoryRequest>
{
public GetCategoryRequestValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetCategoryRequest>.CreateWithOptions((GetCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,27 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.Category;
namespace CMSMicroservice.Protobuf.Validator.Category;
public class UpdateCategoryRequestValidator : AbstractValidator<UpdateCategoryRequest>
{
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<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateCategoryRequest>.CreateWithOptions((UpdateCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,21 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.PruductCategory;
namespace CMSMicroservice.Protobuf.Validator.PruductCategory;
public class CreateNewPruductCategoryRequestValidator : AbstractValidator<CreateNewPruductCategoryRequest>
{
public CreateNewPruductCategoryRequestValidator()
{
RuleFor(model => model.ProductId)
.NotEmpty();
RuleFor(model => model.CategoryId)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewPruductCategoryRequest>.CreateWithOptions((CreateNewPruductCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,19 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.PruductCategory;
namespace CMSMicroservice.Protobuf.Validator.PruductCategory;
public class DeletePruductCategoryRequestValidator : AbstractValidator<DeletePruductCategoryRequest>
{
public DeletePruductCategoryRequestValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeletePruductCategoryRequest>.CreateWithOptions((DeletePruductCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,17 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.PruductCategory;
namespace CMSMicroservice.Protobuf.Validator.PruductCategory;
public class GetAllPruductCategoryByFilterRequestValidator : AbstractValidator<GetAllPruductCategoryByFilterRequest>
{
public GetAllPruductCategoryByFilterRequestValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllPruductCategoryByFilterRequest>.CreateWithOptions((GetAllPruductCategoryByFilterRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,19 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.PruductCategory;
namespace CMSMicroservice.Protobuf.Validator.PruductCategory;
public class GetPruductCategoryRequestValidator : AbstractValidator<GetPruductCategoryRequest>
{
public GetPruductCategoryRequestValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetPruductCategoryRequest>.CreateWithOptions((GetPruductCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,23 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.PruductCategory;
namespace CMSMicroservice.Protobuf.Validator.PruductCategory;
public class UpdatePruductCategoryRequestValidator : AbstractValidator<UpdatePruductCategoryRequest>
{
public UpdatePruductCategoryRequestValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.ProductId)
.NotEmpty();
RuleFor(model => model.CategoryId)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdatePruductCategoryRequest>.CreateWithOptions((UpdatePruductCategoryRequest)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.WebApi.Common.Mappings;
public class CategoryProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
}
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.WebApi.Common.Mappings;
public class PruductCategoryProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
}
}

View File

@@ -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<CreateNewCategoryResponse> CreateNewCategory(CreateNewCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateNewCategoryRequest, CreateNewCategoryCommand, CreateNewCategoryResponse>(request, context);
}
public override async Task<Empty> UpdateCategory(UpdateCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateCategoryRequest, UpdateCategoryCommand>(request, context);
}
public override async Task<Empty> DeleteCategory(DeleteCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeleteCategoryRequest, DeleteCategoryCommand>(request, context);
}
public override async Task<GetCategoryResponse> GetCategory(GetCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetCategoryRequest, GetCategoryQuery, GetCategoryResponse>(request, context);
}
public override async Task<GetAllCategoryByFilterResponse> GetAllCategoryByFilter(GetAllCategoryByFilterRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllCategoryByFilterRequest, GetAllCategoryByFilterQuery, GetAllCategoryByFilterResponse>(request, context);
}
}

View File

@@ -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<CreateNewPruductCategoryResponse> CreateNewPruductCategory(CreateNewPruductCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateNewPruductCategoryRequest, CreateNewPruductCategoryCommand, CreateNewPruductCategoryResponse>(request, context);
}
public override async Task<Empty> UpdatePruductCategory(UpdatePruductCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdatePruductCategoryRequest, UpdatePruductCategoryCommand>(request, context);
}
public override async Task<Empty> DeletePruductCategory(DeletePruductCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeletePruductCategoryRequest, DeletePruductCategoryCommand>(request, context);
}
public override async Task<GetPruductCategoryResponse> GetPruductCategory(GetPruductCategoryRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetPruductCategoryRequest, GetPruductCategoryQuery, GetPruductCategoryResponse>(request, context);
}
public override async Task<GetAllPruductCategoryByFilterResponse> GetAllPruductCategoryByFilter(GetAllPruductCategoryByFilterRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllPruductCategoryByFilterRequest, GetAllPruductCategoryByFilterQuery, GetAllPruductCategoryByFilterResponse>(request, context);
}
}