Generator Changes at 9/27/2025 8:46:36 AM
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
|
||||
public record GetAllUserRoleByFilterQuery : IRequest<GetAllUserRoleByFilterResponseDto>
|
||||
{
|
||||
//موقعیت صفحه بندی
|
||||
public PaginationState? PaginationState { get; init; }
|
||||
//مرتب سازی بر اساس
|
||||
public string? SortBy { get; init; }
|
||||
//فیلتر
|
||||
public GetAllUserRoleByFilterFilter? Filter { get; init; }
|
||||
|
||||
}public class GetAllUserRoleByFilterFilter
|
||||
{
|
||||
//شناسه
|
||||
public long? Id { get; set; }
|
||||
//شناسه نقش
|
||||
public long? RoleId { get; set; }
|
||||
//شناسه کاربر
|
||||
public long? UserId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
|
||||
public class GetAllUserRoleByFilterQueryHandler : IRequestHandler<GetAllUserRoleByFilterQuery, GetAllUserRoleByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetAllUserRoleByFilterQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllUserRoleByFilterResponseDto> Handle(GetAllUserRoleByFilterQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.UserRoles
|
||||
.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.RoleId == null || x.RoleId == request.Filter.RoleId)
|
||||
.Where(x => request.Filter.UserId == null || x.UserId == request.Filter.UserId)
|
||||
;
|
||||
}
|
||||
return new GetAllUserRoleByFilterResponseDto
|
||||
{
|
||||
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
|
||||
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
|
||||
.ProjectToType<GetAllUserRoleByFilterResponseModel>().ToListAsync(cancellationToken)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
|
||||
public class GetAllUserRoleByFilterQueryValidator : AbstractValidator<GetAllUserRoleByFilterQuery>
|
||||
{
|
||||
public GetAllUserRoleByFilterQueryValidator()
|
||||
{
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetAllUserRoleByFilterQuery>.CreateWithOptions((GetAllUserRoleByFilterQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
|
||||
public class GetAllUserRoleByFilterResponseDto
|
||||
{
|
||||
//متادیتا
|
||||
public MetaData MetaData { get; set; }
|
||||
//مدل خروجی
|
||||
public List<GetAllUserRoleByFilterResponseModel>? Models { get; set; }
|
||||
|
||||
}public class GetAllUserRoleByFilterResponseModel
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
//شناسه نقش
|
||||
public long RoleId { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
|
||||
public record GetUserRoleQuery : IRequest<GetUserRoleResponseDto>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
|
||||
public class GetUserRoleQueryHandler : IRequestHandler<GetUserRoleQuery, GetUserRoleResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetUserRoleQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetUserRoleResponseDto> Handle(GetUserRoleQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.UserRoles
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.ProjectToType<GetUserRoleResponseDto>()
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return response ?? throw new NotFoundException(nameof(UserRole), request.Id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
|
||||
public class GetUserRoleQueryValidator : AbstractValidator<GetUserRoleQuery>
|
||||
{
|
||||
public GetUserRoleQueryValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetUserRoleQuery>.CreateWithOptions((GetUserRoleQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
|
||||
public class GetUserRoleResponseDto
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
//شناسه نقش
|
||||
public long RoleId { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user