33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
|
|
using CMSMicroservice.Protobuf.Protos.DiscountShoppingCart;
|
||
|
|
|
||
|
|
namespace FrontOffice.BFF.Application.DiscountShopCQ.Commands.RemoveFromDiscountCart;
|
||
|
|
|
||
|
|
public class RemoveFromDiscountCartCommandHandler : IRequestHandler<RemoveFromDiscountCartCommand, RemoveFromDiscountCartResponseDto>
|
||
|
|
{
|
||
|
|
private readonly IApplicationContractContext _context;
|
||
|
|
private readonly ICurrentUserService _currentUserService;
|
||
|
|
|
||
|
|
public RemoveFromDiscountCartCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
|
||
|
|
{
|
||
|
|
_context = context;
|
||
|
|
_currentUserService = currentUserService;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<RemoveFromDiscountCartResponseDto> Handle(RemoveFromDiscountCartCommand request, CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
var userId = _currentUserService.UserId ?? throw new UnauthorizedAccessException("User not authenticated");
|
||
|
|
|
||
|
|
var response = await _context.DiscountCart.RemoveFromCartAsync(new RemoveFromCartRequest
|
||
|
|
{
|
||
|
|
UserId = userId,
|
||
|
|
ProductId = request.ProductId
|
||
|
|
}, cancellationToken: cancellationToken);
|
||
|
|
|
||
|
|
return new RemoveFromDiscountCartResponseDto
|
||
|
|
{
|
||
|
|
Success = response.Success,
|
||
|
|
Message = response.Message
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|