This commit is contained in:
masoodafar-web
2025-11-18 22:38:50 +03:30
parent dba8aecc97
commit f6dcd43346
76 changed files with 3778 additions and 1386 deletions

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.Common.Mappings;
public class TagProfile : 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.Application.PruductTagCQ.Commands.CreateNewPruductTag;
public record CreateNewPruductTagCommand : IRequest<CreateNewPruductTagResponseDto>
{
//شناسه محصول
public string ProductId { get; init; }
//شناسه تگ
public string TagId { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.PruductTagCQ.Commands.CreateNewPruductTag;
public class CreateNewPruductTagCommandHandler : IRequestHandler<CreateNewPruductTagCommand, CreateNewPruductTagResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewPruductTagCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewPruductTagResponseDto> Handle(CreateNewPruductTagCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<PruductTag>();
await _context.PruductTags.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewPruductTagEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewPruductTagResponseDto>();
}
}

View File

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

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Application.PruductTagCQ.Commands.CreateNewPruductTag;
public class CreateNewPruductTagResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Application.PruductTagCQ.Commands.DeletePruductTag;
public record DeletePruductTagCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,23 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.PruductTagCQ.Commands.DeletePruductTag;
public class DeletePruductTagCommandHandler : IRequestHandler<DeletePruductTagCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeletePruductTagCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeletePruductTagCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PruductTags
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(PruductTag), request.Id);
entity.IsDeleted = true;
_context.PruductTags.Update(entity);
entity.AddDomainEvent(new DeletePruductTagEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

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

View File

@@ -0,0 +1,12 @@
namespace CMSMicroservice.Application.PruductTagCQ.Commands.UpdatePruductTag;
public record UpdatePruductTagCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//شناسه محصول
public string ProductId { get; init; }
//شناسه تگ
public string TagId { get; init; }
}

View File

@@ -0,0 +1,23 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.PruductTagCQ.Commands.UpdatePruductTag;
public class UpdatePruductTagCommandHandler : IRequestHandler<UpdatePruductTagCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdatePruductTagCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdatePruductTagCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PruductTags
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(PruductTag), request.Id);
request.Adapt(entity);
_context.PruductTags.Update(entity);
entity.AddDomainEvent(new UpdatePruductTagEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,21 @@
namespace CMSMicroservice.Application.PruductTagCQ.Commands.UpdatePruductTag;
public class UpdatePruductTagCommandValidator : AbstractValidator<UpdatePruductTagCommand>
{
public UpdatePruductTagCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.ProductId)
.NotEmpty();
RuleFor(model => model.TagId)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdatePruductTagCommand>.CreateWithOptions((UpdatePruductTagCommand)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.PruductTagCQ.EventHandlers;
public class CreateNewPruductTagEventHandler : INotificationHandler<CreateNewPruductTagEvent>
{
private readonly ILogger<CreateNewPruductTagEventHandler> _logger;
public CreateNewPruductTagEventHandler(ILogger<CreateNewPruductTagEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewPruductTagEvent 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.PruductTagCQ.EventHandlers;
public class DeletePruductTagEventHandler : INotificationHandler<DeletePruductTagEvent>
{
private readonly ILogger<DeletePruductTagEventHandler> _logger;
public DeletePruductTagEventHandler(ILogger<DeletePruductTagEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeletePruductTagEvent 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.PruductTagCQ.EventHandlers;
public class UpdatePruductTagEventHandler : INotificationHandler<UpdatePruductTagEvent>
{
private readonly ILogger<UpdatePruductTagEventHandler> _logger;
public UpdatePruductTagEventHandler(ILogger<UpdatePruductTagEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdatePruductTagEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,21 @@
namespace CMSMicroservice.Application.PruductTagCQ.Queries.GetAllPruductTagByFilter;
public record GetAllPruductTagByFilterQuery : IRequest<GetAllPruductTagByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllPruductTagByFilterFilter? Filter { get; init; }
}
public class GetAllPruductTagByFilterFilter
{
//شناسه
public long? Id { get; set; }
//شناسه محصول
public string? ProductId { get; set; }
//شناسه تگ
public string? TagId { get; set; }
}

View File

@@ -0,0 +1,33 @@
namespace CMSMicroservice.Application.PruductTagCQ.Queries.GetAllPruductTagByFilter;
public class GetAllPruductTagByFilterQueryHandler : IRequestHandler<GetAllPruductTagByFilterQuery, GetAllPruductTagByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllPruductTagByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllPruductTagByFilterResponseDto> Handle(GetAllPruductTagByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.PruductTags
.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.TagId == null || x.TagId.Contains(request.Filter.TagId))
;
}
return new GetAllPruductTagByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllPruductTagByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

@@ -0,0 +1,15 @@
namespace CMSMicroservice.Application.PruductTagCQ.Queries.GetAllPruductTagByFilter;
public class GetAllPruductTagByFilterQueryValidator : AbstractValidator<GetAllPruductTagByFilterQuery>
{
public GetAllPruductTagByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllPruductTagByFilterQuery>.CreateWithOptions((GetAllPruductTagByFilterQuery)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 @@
namespace CMSMicroservice.Application.PruductTagCQ.Queries.GetAllPruductTagByFilter;
public class GetAllPruductTagByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllPruductTagByFilterResponseModel>? Models { get; set; }
}
public class GetAllPruductTagByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//شناسه محصول
public string ProductId { get; set; }
//شناسه تگ
public string TagId { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Application.PruductTagCQ.Queries.GetPruductTag;
public record GetPruductTagQuery : IRequest<GetPruductTagResponseDto>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.PruductTagCQ.Queries.GetPruductTag;
public class GetPruductTagQueryHandler : IRequestHandler<GetPruductTagQuery, GetPruductTagResponseDto>
{
private readonly IApplicationDbContext _context;
public GetPruductTagQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetPruductTagResponseDto> Handle(GetPruductTagQuery request,
CancellationToken cancellationToken)
{
var response = await _context.PruductTags
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetPruductTagResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(PruductTag), request.Id);
}
}

View File

@@ -0,0 +1,17 @@
namespace CMSMicroservice.Application.PruductTagCQ.Queries.GetPruductTag;
public class GetPruductTagQueryValidator : AbstractValidator<GetPruductTagQuery>
{
public GetPruductTagQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetPruductTagQuery>.CreateWithOptions((GetPruductTagQuery)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.PruductTagCQ.Queries.GetPruductTag;
public class GetPruductTagResponseDto
{
//شناسه
public long Id { get; set; }
//شناسه محصول
public string ProductId { get; set; }
//شناسه تگ
public string TagId { get; set; }
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.TagCQ.Commands.CreateNewTag;
public record CreateNewTagCommand : IRequest<CreateNewTagResponseDto>
{
//نام لاتین
public string Name { get; init; }
//عنوان
public string Title { get; init; }
//توضیحات
public string? Description { get; init; }
//فعال؟
public bool IsActive { get; init; }
//ترتیب نمایش
public int SortOrder { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.TagCQ.Commands.CreateNewTag;
public class CreateNewTagCommandHandler : IRequestHandler<CreateNewTagCommand, CreateNewTagResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewTagCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewTagResponseDto> Handle(CreateNewTagCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<Tag>();
await _context.Tags.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewTagEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewTagResponseDto>();
}
}

View File

@@ -0,0 +1,21 @@
namespace CMSMicroservice.Application.TagCQ.Commands.CreateNewTag;
public class CreateNewTagCommandValidator : AbstractValidator<CreateNewTagCommand>
{
public CreateNewTagCommandValidator()
{
RuleFor(model => model.Name)
.NotEmpty();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.SortOrder)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewTagCommand>.CreateWithOptions((CreateNewTagCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Application.TagCQ.Commands.CreateNewTag;
public class CreateNewTagResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Application.TagCQ.Commands.DeleteTag;
public record DeleteTagCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,23 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.TagCQ.Commands.DeleteTag;
public class DeleteTagCommandHandler : IRequestHandler<DeleteTagCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteTagCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteTagCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Tags
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Tag), request.Id);
entity.IsDeleted = true;
_context.Tags.Update(entity);
entity.AddDomainEvent(new DeleteTagEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

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

View File

@@ -0,0 +1,18 @@
namespace CMSMicroservice.Application.TagCQ.Commands.UpdateTag;
public record UpdateTagCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//نام لاتین
public string Name { get; init; }
//عنوان
public string Title { get; init; }
//توضیحات
public string? Description { get; init; }
//فعال؟
public bool IsActive { get; init; }
//ترتیب نمایش
public int SortOrder { get; init; }
}

View File

@@ -0,0 +1,23 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.TagCQ.Commands.UpdateTag;
public class UpdateTagCommandHandler : IRequestHandler<UpdateTagCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateTagCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateTagCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Tags
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Tag), request.Id);
request.Adapt(entity);
_context.Tags.Update(entity);
entity.AddDomainEvent(new UpdateTagEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.TagCQ.Commands.UpdateTag;
public class UpdateTagCommandValidator : AbstractValidator<UpdateTagCommand>
{
public UpdateTagCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Name)
.NotEmpty();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.SortOrder)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateTagCommand>.CreateWithOptions((UpdateTagCommand)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.TagCQ.EventHandlers;
public class CreateNewTagEventHandler : INotificationHandler<CreateNewTagEvent>
{
private readonly ILogger<CreateNewTagEventHandler> _logger;
public CreateNewTagEventHandler(ILogger<CreateNewTagEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewTagEvent 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.TagCQ.EventHandlers;
public class DeleteTagEventHandler : INotificationHandler<DeleteTagEvent>
{
private readonly ILogger<DeleteTagEventHandler> _logger;
public DeleteTagEventHandler(ILogger<DeleteTagEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteTagEvent 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.TagCQ.EventHandlers;
public class UpdateTagEventHandler : INotificationHandler<UpdateTagEvent>
{
private readonly ILogger<UpdateTagEventHandler> _logger;
public UpdateTagEventHandler(ILogger<UpdateTagEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateTagEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,27 @@
namespace CMSMicroservice.Application.TagCQ.Queries.GetAllTagByFilter;
public record GetAllTagByFilterQuery : IRequest<GetAllTagByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllTagByFilterFilter? Filter { get; init; }
}
public class GetAllTagByFilterFilter
{
//شناسه
public long? Id { get; set; }
//نام لاتین
public string? Name { get; set; }
//عنوان
public string? Title { get; set; }
//توضیحات
public string? Description { get; set; }
//فعال؟
public bool? IsActive { get; set; }
//ترتیب نمایش
public int? SortOrder { get; set; }
}

View File

@@ -0,0 +1,36 @@
namespace CMSMicroservice.Application.TagCQ.Queries.GetAllTagByFilter;
public class GetAllTagByFilterQueryHandler : IRequestHandler<GetAllTagByFilterQuery, GetAllTagByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllTagByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllTagByFilterResponseDto> Handle(GetAllTagByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.Tags
.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.Name == null || x.Name.Contains(request.Filter.Name))
.Where(x => request.Filter.Title == null || x.Title.Contains(request.Filter.Title))
.Where(x => request.Filter.Description == null || (x.Description != null && x.Description.Contains(request.Filter.Description)))
.Where(x => request.Filter.IsActive == null || x.IsActive == request.Filter.IsActive)
.Where(x => request.Filter.SortOrder == null || x.SortOrder == request.Filter.SortOrder)
;
}
return new GetAllTagByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllTagByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

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

View File

@@ -0,0 +1,25 @@
namespace CMSMicroservice.Application.TagCQ.Queries.GetAllTagByFilter;
public class GetAllTagByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllTagByFilterResponseModel>? Models { get; set; }
}
public class GetAllTagByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//نام لاتین
public string Name { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string? Description { get; set; }
//فعال؟
public bool IsActive { get; set; }
//ترتیب نمایش
public int SortOrder { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace CMSMicroservice.Application.TagCQ.Queries.GetTag;
public record GetTagQuery : IRequest<GetTagResponseDto>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.TagCQ.Queries.GetTag;
public class GetTagQueryHandler : IRequestHandler<GetTagQuery, GetTagResponseDto>
{
private readonly IApplicationDbContext _context;
public GetTagQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetTagResponseDto> Handle(GetTagQuery request,
CancellationToken cancellationToken)
{
var response = await _context.Tags
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetTagResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(Tag), request.Id);
}
}

View File

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

View File

@@ -0,0 +1,18 @@
namespace CMSMicroservice.Application.TagCQ.Queries.GetTag;
public class GetTagResponseDto
{
//شناسه
public long Id { get; set; }
//نام لاتین
public string Name { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string? Description { get; set; }
//فعال؟
public bool IsActive { get; set; }
//ترتیب نمایش
public int SortOrder { get; set; }
}

View File

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

View File

@@ -0,0 +1,14 @@
namespace CMSMicroservice.Domain.Entities;
//برچسب محصول
public class PruductTag : BaseAuditableEntity
{
//شناسه محصول
public string ProductId { get; set; }
//Product Navigation Property
public virtual Products Product { get; set; }
//شناسه تگ
public string TagId { get; set; }
//Tag Navigation Property
public virtual Tag Tag { get; set; }
}

View File

@@ -0,0 +1,18 @@
namespace CMSMicroservice.Domain.Entities;
//تگ
public class Tag : BaseAuditableEntity
{
//نام لاتین
public string Name { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string? Description { get; set; }
//فعال؟
public bool IsActive { get; set; }
//ترتیب نمایش
public int SortOrder { get; set; }
//PruductTag Collection Navigation Reference
public virtual ICollection<PruductTag> PruductTags { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.Domain.Events;
public class CreateNewPruductTagEvent : BaseEvent
{
public CreateNewPruductTagEvent(PruductTag item)
{
Item = item;
}
public PruductTag Item { get; }
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.Domain.Events;
public class DeletePruductTagEvent : BaseEvent
{
public DeletePruductTagEvent(PruductTag item)
{
Item = item;
}
public PruductTag Item { get; }
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.Domain.Events;
public class UpdatePruductTagEvent : BaseEvent
{
public UpdatePruductTagEvent(PruductTag item)
{
Item = item;
}
public PruductTag Item { get; }
}

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Domain.Events;
public class CreateNewTagEvent : BaseEvent
{
public CreateNewTagEvent(Tag item)
{
Item = item;
}
public Tag Item { get; }
}

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Domain.Events;
public class DeleteTagEvent : BaseEvent
{
public DeleteTagEvent(Tag item)
{
Item = item;
}
public Tag Item { get; }
}

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Domain.Events;
public class UpdateTagEvent : BaseEvent
{
public UpdateTagEvent(Tag item)
{
Item = item;
}
public Tag Item { get; }
}

View File

@@ -42,7 +42,8 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
public DbSet<UserAddress> UserAddresss => Set<UserAddress>();
public DbSet<Package> Packages => Set<Package>();
public DbSet<Role> Roles => Set<Role>();
public DbSet<Category> Categorys => Set<Category>();
public DbSet<Category> Categories => Set<Category>();
public DbSet<Tag> Tags => Set<Tag>();
public DbSet<UserRole> UserRoles => Set<UserRole>();
public DbSet<UserWallet> UserWallets => Set<UserWallet>();
public DbSet<UserWalletChangeLog> UserWalletChangeLogs => Set<UserWalletChangeLog>();

View File

@@ -13,7 +13,7 @@ public class PruductCategoryConfiguration : IEntityTypeConfiguration<PruductCate
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.ProductPruductCategorys)
.WithMany(entity => entity.PruductCategorys)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
builder

View File

@@ -0,0 +1,30 @@
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//برچسب محصول
public class PruductTagConfiguration : IEntityTypeConfiguration<PruductTag>
{
public void Configure(EntityTypeBuilder<PruductTag> 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.PruductTags)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
builder
.HasOne(entity => entity.Tag)
.WithMany(entity => entity.PruductTags)
.HasForeignKey(entity => entity.TagId)
.IsRequired(true);
}
}

View File

@@ -0,0 +1,23 @@
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class TagConfiguration : IEntityTypeConfiguration<Tag>
{
public void Configure(EntityTypeBuilder<Tag> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Id).UseIdentityColumn();
builder.Property(entity => entity.Name).IsRequired(true);
builder.Property(entity => entity.Title).IsRequired(true);
builder.Property(entity => entity.Description).IsRequired(false);
builder.Property(entity => entity.IsActive).IsRequired(true);
builder.Property(entity => entity.SortOrder).IsRequired(true);
}
}

View File

@@ -39,6 +39,9 @@
<!-- Added missing proto definitions so validators compile -->
<Protobuf Include="Protos\contract.proto" ProtoRoot="Protos\" GrpcServices="Both" />
<Protobuf Include="Protos\usercontract.proto" ProtoRoot="Protos\" GrpcServices="Both" />
<Protobuf Include="Protos\pruductcategory.proto" ProtoRoot="Protos\" GrpcServices="Both" />
<Protobuf Include="Protos\tag.proto" ProtoRoot="Protos\" GrpcServices="Both" />
<Protobuf Include="Protos\pruducttag.proto" ProtoRoot="Protos\" GrpcServices="Both" />
</ItemGroup>
<Target Name="PushToFoursatNuget" AfterTargets="Pack">

View File

@@ -0,0 +1,99 @@
syntax = "proto3";
package pruducttag;
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.PruductTag";
service PruductTagContract
{
rpc CreateNewPruductTag(CreateNewPruductTagRequest) returns (CreateNewPruductTagResponse){
option (google.api.http) = {
post: "/CreateNewPruductTag"
body: "*"
};
};
rpc UpdatePruductTag(UpdatePruductTagRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
put: "/UpdatePruductTag"
body: "*"
};
};
rpc DeletePruductTag(DeletePruductTagRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
delete: "/DeletePruductTag"
body: "*"
};
};
rpc GetPruductTag(GetPruductTagRequest) returns (GetPruductTagResponse){
option (google.api.http) = {
get: "/GetPruductTag"
};
};
rpc GetAllPruductTagByFilter(GetAllPruductTagByFilterRequest) returns (GetAllPruductTagByFilterResponse){
option (google.api.http) = {
get: "/GetAllPruductTagByFilter"
};
};
}
message CreateNewPruductTagRequest
{
string product_id = 1;
string tag_id = 2;
}
message CreateNewPruductTagResponse
{
int64 id = 1;
}
message UpdatePruductTagRequest
{
int64 id = 1;
string product_id = 2;
string tag_id = 3;
}
message DeletePruductTagRequest
{
int64 id = 1;
}
message GetPruductTagRequest
{
int64 id = 1;
}
message GetPruductTagResponse
{
int64 id = 1;
string product_id = 2;
string tag_id = 3;
}
message GetAllPruductTagByFilterRequest
{
messages.PaginationState pagination_state = 1;
google.protobuf.StringValue sort_by = 2;
GetAllPruductTagByFilterFilter filter = 3;
}
message GetAllPruductTagByFilterFilter
{
google.protobuf.Int64Value id = 1;
google.protobuf.StringValue product_id = 2;
google.protobuf.StringValue tag_id = 3;
}
message GetAllPruductTagByFilterResponse
{
messages.MetaData meta_data = 1;
repeated GetAllPruductTagByFilterResponseModel models = 2;
}
message GetAllPruductTagByFilterResponseModel
{
int64 id = 1;
string product_id = 2;
string tag_id = 3;
}

View File

@@ -0,0 +1,114 @@
syntax = "proto3";
package tag;
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.Tag";
service TagContract
{
rpc CreateNewTag(CreateNewTagRequest) returns (CreateNewTagResponse){
option (google.api.http) = {
post: "/CreateNewTag"
body: "*"
};
};
rpc UpdateTag(UpdateTagRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
put: "/UpdateTag"
body: "*"
};
};
rpc DeleteTag(DeleteTagRequest) returns (google.protobuf.Empty){
option (google.api.http) = {
delete: "/DeleteTag"
body: "*"
};
};
rpc GetTag(GetTagRequest) returns (GetTagResponse){
option (google.api.http) = {
get: "/GetTag"
};
};
rpc GetAllTagByFilter(GetAllTagByFilterRequest) returns (GetAllTagByFilterResponse){
option (google.api.http) = {
get: "/GetAllTagByFilter"
};
};
}
message CreateNewTagRequest
{
string name = 1;
string title = 2;
string description = 3;
bool is_active = 4;
int32 sort_order = 5;
}
message CreateNewTagResponse
{
int64 id = 1;
}
message UpdateTagRequest
{
int64 id = 1;
string name = 2;
string title = 3;
string description = 4;
bool is_active = 5;
int32 sort_order = 6;
}
message DeleteTagRequest
{
int64 id = 1;
}
message GetTagRequest
{
int64 id = 1;
}
message GetTagResponse
{
int64 id = 1;
string name = 2;
string title = 3;
string description = 4;
bool is_active = 5;
int32 sort_order = 6;
}
message GetAllTagByFilterRequest
{
messages.PaginationState pagination_state = 1;
google.protobuf.StringValue sort_by = 2;
GetAllTagByFilterFilter filter = 3;
}
message GetAllTagByFilterFilter
{
google.protobuf.Int64Value id = 1;
google.protobuf.StringValue name = 2;
google.protobuf.StringValue title = 3;
google.protobuf.StringValue description = 4;
google.protobuf.BoolValue is_active = 5;
google.protobuf.Int32Value sort_order = 6;
}
message GetAllTagByFilterResponse
{
messages.MetaData meta_data = 1;
repeated GetAllTagByFilterResponseModel models = 2;
}
message GetAllTagByFilterResponseModel
{
int64 id = 1;
string name = 2;
string title = 3;
string description = 4;
bool is_active = 5;
int32 sort_order = 6;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,26 @@
using FluentValidation;
using CMSMicroservice.Protobuf.Protos.Tag;
namespace CMSMicroservice.Protobuf.Validator.Tag;
public class UpdateTagRequestValidator : AbstractValidator<UpdateTagRequest>
{
public UpdateTagRequestValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Name)
.NotEmpty();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.SortOrder)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateTagRequest>.CreateWithOptions((UpdateTagRequest)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.WebApi.Common.Mappings;
public class PruductTagProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
}
}

View File

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

View File

@@ -0,0 +1,38 @@
using CMSMicroservice.Protobuf.Protos.PruductTag;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.PruductTagCQ.Commands.CreateNewPruductTag;
using CMSMicroservice.Application.PruductTagCQ.Commands.UpdatePruductTag;
using CMSMicroservice.Application.PruductTagCQ.Commands.DeletePruductTag;
using CMSMicroservice.Application.PruductTagCQ.Queries.GetPruductTag;
using CMSMicroservice.Application.PruductTagCQ.Queries.GetAllPruductTagByFilter;
namespace CMSMicroservice.WebApi.Services;
public class PruductTagService : PruductTagContract.PruductTagContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public PruductTagService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
public override async Task<CreateNewPruductTagResponse> CreateNewPruductTag(CreateNewPruductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateNewPruductTagRequest, CreateNewPruductTagCommand, CreateNewPruductTagResponse>(request, context);
}
public override async Task<Empty> UpdatePruductTag(UpdatePruductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdatePruductTagRequest, UpdatePruductTagCommand>(request, context);
}
public override async Task<Empty> DeletePruductTag(DeletePruductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeletePruductTagRequest, DeletePruductTagCommand>(request, context);
}
public override async Task<GetPruductTagResponse> GetPruductTag(GetPruductTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetPruductTagRequest, GetPruductTagQuery, GetPruductTagResponse>(request, context);
}
public override async Task<GetAllPruductTagByFilterResponse> GetAllPruductTagByFilter(GetAllPruductTagByFilterRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllPruductTagByFilterRequest, GetAllPruductTagByFilterQuery, GetAllPruductTagByFilterResponse>(request, context);
}
}

View File

@@ -0,0 +1,38 @@
using CMSMicroservice.Protobuf.Protos.Tag;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.TagCQ.Commands.CreateNewTag;
using CMSMicroservice.Application.TagCQ.Commands.UpdateTag;
using CMSMicroservice.Application.TagCQ.Commands.DeleteTag;
using CMSMicroservice.Application.TagCQ.Queries.GetTag;
using CMSMicroservice.Application.TagCQ.Queries.GetAllTagByFilter;
namespace CMSMicroservice.WebApi.Services;
public class TagService : TagContract.TagContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
public TagService(IDispatchRequestToCQRS dispatchRequestToCQRS)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
}
public override async Task<CreateNewTagResponse> CreateNewTag(CreateNewTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<CreateNewTagRequest, CreateNewTagCommand, CreateNewTagResponse>(request, context);
}
public override async Task<Empty> UpdateTag(UpdateTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateTagRequest, UpdateTagCommand>(request, context);
}
public override async Task<Empty> DeleteTag(DeleteTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<DeleteTagRequest, DeleteTagCommand>(request, context);
}
public override async Task<GetTagResponse> GetTag(GetTagRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetTagRequest, GetTagQuery, GetTagResponse>(request, context);
}
public override async Task<GetAllTagByFilterResponse> GetAllTagByFilter(GetAllTagByFilterRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllTagByFilterRequest, GetAllTagByFilterQuery, GetAllTagByFilterResponse>(request, context);
}
}