-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor cart functionality and update exception handling
- Loading branch information
Showing
23 changed files
with
140 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
code/src/MicroCommerce.ApiService/Infrastructure/Behaviour/UnhandledExceptionBehaviour.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
code/src/MicroCommerce.ApiService/Infrastructure/Behaviour/ValidationBehaviour.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
code/src/MicroCommerce.ApiService/Infrastructure/Exceptions/CoreException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
code/src/MicroCommerce.ApiService/Infrastructure/Exceptions/InvalidValidationException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...c/MicroCommerce.ApiService/Infrastructure/Exceptions/InvalidValidationExceptionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,25 @@ | ||
using MicroCommerce.ApiService.Domain.Entities; | ||
using MicroCommerce.ApiService.Features.Carts; | ||
|
||
namespace MicroCommerce.Web; | ||
|
||
public class CartApiClient(HttpClient httpClient) | ||
{ | ||
public async Task<GetCart.Response?> GetCartById(Guid id, CancellationToken cancellationToken = default) | ||
{ | ||
var response = await httpClient.GetFromJsonAsync<GetCart.Response>($"/api/carts/{id}", cancellationToken); | ||
|
||
return response; | ||
} | ||
|
||
public async Task<AddProductToCart.Response?> AddProductToCart(AddProductToCart.Command request, CancellationToken cancellationToken = default) | ||
{ | ||
var response = await httpClient.PostAsJsonAsync($"/api/carts/{request.CartId}/products", request, cancellationToken); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var data = await response.Content.ReadFromJsonAsync<AddProductToCart.Response>(cancellationToken); | ||
|
||
return data; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 21 additions & 2 deletions
23
code/src/MicroCommerce.Web/Components/Layout/MainLayout.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 1,14 @@ | ||
using MicroCommerce.ApiService.Features.Products; | ||
|
||
namespace MicroCommerce.Web; | ||
|
||
public class ProductApiClient(HttpClient httpClient) | ||
{ | ||
public async Task<GetProductsResponse.Product[]?> GetProductsAsync(int maxItems = 10, CancellationToken cancellationToken = default) | ||
public async Task<GetProductsFromElasticsearch.ProductViewModel[]> GetProductsAsync(int maxItems = 10, CancellationToken cancellationToken = default) | ||
{ | ||
var response = await httpClient.GetFromJsonAsync<GetProductsResponse>("/api/products", cancellationToken); | ||
var response = await httpClient.GetFromJsonAsync<GetProductsFromElasticsearch.Response>("/api/products", cancellationToken); | ||
|
||
return response?.Data ?? []; | ||
return response?.Data.ToArray() ?? []; | ||
} | ||
} | ||
|
||
public record GetProductsResponse | ||
{ | ||
public Product[]? Data { get; init; } = []; | ||
|
||
public record Product | ||
{ | ||
public Guid Id { get; init; } | ||
public string Name { get; init; } = ""; | ||
public decimal Price { get; init; } | ||
public long RemainingStock { get; init; } | ||
public string ImageUrl { get; set; } = ""; | ||
} | ||
} |
Oops, something went wrong.