Conversation
|
|
||
| namespace DotNetBoilerplate.Core.Carts; | ||
|
|
||
| public class Quantity |
There was a problem hiding this comment.
pododawać sealed do klas
| public Quantity Quantity { get; private set; } | ||
| public Guid CartId { get; private set; } | ||
|
|
||
| public void UpdateItem(Quantity quantity){ |
There was a problem hiding this comment.
update quantity
| public List<CartItem> Items { get; private set; } | ||
| public UserId Owner { get; private set; } | ||
| public DateTime CreatedAt { get; private set; } | ||
|
|
There was a problem hiding this comment.
Dodać update at
| // Relationships | ||
| builder.HasOne<Cart>() | ||
| .WithMany(c => c.Items) | ||
| .HasForeignKey("CartId") |
There was a problem hiding this comment.
Powinien ten Id być dostępny przez lambda, jak tylko możliwe unikajmy stringów w konfigu
| builder.Property(x => x.CreatedAt) | ||
| .IsRequired(); | ||
|
|
||
| builder.HasMany(c => c.Items) |
There was a problem hiding this comment.
Zastanowić się czy nie zmienić na OwnsMany - poczytać co to, jak działa i zadecydować
|
|
||
| public async Task DeleteAsync(Cart cart, CartItem item) | ||
| { | ||
| if(item is null) |
There was a problem hiding this comment.
Tutaj to samo, te rzeczy z usuwaniem, dodawaniem, innymi operacjami biznesowymi powinny iść do domeny, repo powinno jedynie robić update i save, nic więcej
|
|
||
| namespace DotNetBoilerplate.Application.Carts.Update; | ||
|
|
||
| internal sealed class UpdateCartHandler( |
There was a problem hiding this comment.
UpdateCartItem
| command.Quantity, | ||
| cart.Id | ||
| ); | ||
|
|
There was a problem hiding this comment.
cart.UpdateItem(item)
|
|
||
| namespace DotNetBoilerplate.Application.Carts.Delete; | ||
|
|
||
| internal sealed class DeleteHandler( |
There was a problem hiding this comment.
DeleteCart handler
There was a problem hiding this comment.
Rodzielić na 2 commandy - usuwanie itemu a usunięcie koszyka to 2 różne rzecszy
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapPut("{bookId:guid}", Handle) |
There was a problem hiding this comment.
Ja bym zrobił tak
- dodanie po raz pierwszy produktu: post /cart/items { bookId: 22, quantity: 1 }
- zmiana quantity: PUT /cart/items/:itemId { quantity: 2}
- usunięcie produktu: DELETE /cart/items/:itemId
No description provided.