u
This commit is contained in:
@@ -1,16 +1,36 @@
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
|
||||
namespace FrontOffice.BFF.Application.UserOrderCQ.Commands.CreateNewUserOrder;
|
||||
public class CreateNewUserOrderCommandHandler : IRequestHandler<CreateNewUserOrderCommand, CreateNewUserOrderResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
||||
public CreateNewUserOrderCommandHandler(IApplicationContractContext context)
|
||||
public CreateNewUserOrderCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
|
||||
{
|
||||
_context = context;
|
||||
_currentUserService = currentUserService;
|
||||
}
|
||||
|
||||
public async Task<CreateNewUserOrderResponseDto> Handle(CreateNewUserOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
//TODO: Implement your business logic
|
||||
return new CreateNewUserOrderResponseDto();
|
||||
var userId = _currentUserService.UserId ?? throw new ForbiddenAccessException();
|
||||
var getAllUserAddress = await _context.UserAddress.GetAllUserAddressByFilterAsync(request: new()
|
||||
{
|
||||
Filter = new()
|
||||
{
|
||||
IsDefault = true,
|
||||
UserId = long.Parse(userId)
|
||||
}
|
||||
}, cancellationToken: cancellationToken);
|
||||
if (getAllUserAddress?.Models?.Any() == false)
|
||||
throw new Exception(message:"آدرس نامعتبر است!!");
|
||||
|
||||
var req = request.Adapt<CreateNewUserOrderRequest>();
|
||||
req.UserId = long.Parse(userId);
|
||||
req.UserAddressId = getAllUserAddress!.Models.First().Id;
|
||||
|
||||
var response = await _context.UserOrder.CreateNewUserOrderAsync(request: req, cancellationToken: cancellationToken);
|
||||
return response.Adapt<CreateNewUserOrderResponseDto>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user