Generator Changes at 9/27/2025 8:46:36 AM
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetUserAddress;
|
||||
public record GetUserAddressQuery : IRequest<GetUserAddressResponseDto>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetUserAddress;
|
||||
public class GetUserAddressQueryHandler : IRequestHandler<GetUserAddressQuery, GetUserAddressResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetUserAddressQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetUserAddressResponseDto> Handle(GetUserAddressQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.UserAddresss
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.ProjectToType<GetUserAddressResponseDto>()
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return response ?? throw new NotFoundException(nameof(UserAddress), request.Id);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetUserAddress;
|
||||
public class GetUserAddressQueryValidator : AbstractValidator<GetUserAddressQuery>
|
||||
{
|
||||
public GetUserAddressQueryValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetUserAddressQuery>.CreateWithOptions((GetUserAddressQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetUserAddress;
|
||||
public class GetUserAddressResponseDto
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
//عنوان
|
||||
public string Title { get; set; }
|
||||
//آدرس
|
||||
public string Address { get; set; }
|
||||
//کدپستی
|
||||
public string PostalCode { get; set; }
|
||||
//پیشفرض؟
|
||||
public bool IsDefault { get; set; }
|
||||
//شناسه شهر
|
||||
public long CityId { get; set; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user