Skip to content

Commit

Permalink
update: get basket
Browse files Browse the repository at this point in the history
  • Loading branch information
datsunbae committed Apr 20, 2024
1 parent 8ac0f86 commit 4ebf24b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/API/CleanArchitecture.Api/API.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public Task<string> ConfirmEmailAsync([FromQuery] Guid userId, [FromQuery] strin
return _userService.ConfirmEmailAsync(userId, code, cancellationToken);
}

[HttpGet("confirm-phone-number")]
[AllowAnonymous]
public Task<string> ConfirmPhoneNumberAsync([FromQuery] Guid userId, [FromQuery] string code)
{
return _userService.ConfirmPhoneNumberAsync(userId, code);
}
//[HttpGet("confirm-phone-number")]
//[AllowAnonymous]
//public Task<string> ConfirmPhoneNumberAsync([FromQuery] Guid userId, [FromQuery] string code)
//{
// return _userService.ConfirmPhoneNumberAsync(userId, code);
//}

[HttpPost("forgot-password")]
[AllowAnonymous]
Expand Down
13 changes: 4 additions & 9 deletions src/API/CleanArchitecture.Api/Controllers/V1/BasketController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Asp.Versioning;
using CleanArchitecture.Application.Common.Exceptions;
using CleanArchitecture.Application.Features.V1.Baskets.Commands.AddBasketProductItem;
using CleanArchitecture.Application.Features.V1.Baskets.Commands.CheckoutBasket;
using CleanArchitecture.Application.Features.V1.Baskets.Commands.ClearBasket;
Expand All @@ -22,17 +21,13 @@ public BasketController(ISender sender) : base(sender)
/// <summary>
/// Get basket by user id
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet("{userId}")]
[ProducesResponseType(typeof(Result<BasketReponse>), StatusCodes.Status200OK)]
[HttpGet]
[ProducesResponseType(typeof(Result<BasketResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> GetBasket(Guid userId)
public async Task<IActionResult> GetBasket()
{
var result = await Sender.Send(new GetBasketQuery(userId));

if (result.IsFailure)
throw new BadRequestException(new List<Error> { result.Error });
var result = await Sender.Send(new GetBasketQuery());

return Ok(result);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CleanArchitecture.Application.Features.V1.Baskets.Models.Responses;

public sealed record BasketResponse
(Guid UserId,
decimal TotalPrice,
IEnumerable<BasketProductItemResponse> BasketProductItems);
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

namespace CleanArchitecture.Application.Features.V1.Baskets.Queries.GetBasket;

public sealed record GetBasketQuery(
Guid UserId) : IQuery<BasketReponse>;
public sealed record GetBasketQuery : IQuery<BasketResponse>;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ardalis.Specification;
using CleanArchitecture.Application.Common.Interfaces.Auth;
using CleanArchitecture.Application.Common.Messaging;
using CleanArchitecture.Application.Features.V1.Baskets.Models.Responses;
using CleanArchitecture.Application.Features.V1.Baskets.Specifications;
Expand All @@ -8,20 +9,24 @@

namespace CleanArchitecture.Application.Features.V1.Baskets.Queries.GetBasket;

public sealed class GetBasketQueryHandler : IQueryHandler<GetBasketQuery, BasketReponse>
public sealed class GetBasketQueryHandler : IQueryHandler<GetBasketQuery, BasketResponse>
{
private readonly IBasketRepository _basketRepository;
public GetBasketQueryHandler(IBasketRepository basketRepository)
private readonly ICurrentUser _currentUser;
public GetBasketQueryHandler(IBasketRepository basketRepository, ICurrentUser currentUser)
{
_basketRepository = basketRepository;
_currentUser = currentUser;
}

public async Task<Result<BasketReponse>> Handle(GetBasketQuery request, CancellationToken cancellationToken)
public async Task<Result<BasketResponse>> Handle(GetBasketQuery request, CancellationToken cancellationToken)
{
Guid userId = _currentUser.GetUserId();

var result = await _basketRepository
.FirstOrDefaultAsync(
(ISpecification<Basket, BasketReponse>)new BasketByUserIdWithBasketItemResultSpec(request.UserId), cancellationToken)
?? Result.Failure<BasketReponse>(BasketErrors.NotFound);
(ISpecification<Basket, BasketResponse>)new BasketByUserIdWithBasketItemResultSpec(userId), cancellationToken)
?? new BasketResponse(userId, 0, Enumerable.Empty<BasketProductItemResponse>());

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CleanArchitecture.Application.Features.V1.Baskets.Specifications;

public class BasketByUserIdWithBasketItemResultSpec : Specification<Basket, BasketReponse>
public class BasketByUserIdWithBasketItemResultSpec : Specification<Basket, BasketResponse>
{
public BasketByUserIdWithBasketItemResultSpec(Guid userId) =>
Query
Expand Down

0 comments on commit 4ebf24b

Please sign in to comment.