Skip to content

Feat/postgres cart read#23

Open
KopfSzmercen wants to merge 4 commits intomainfrom
feat/postgres-cart-read
Open

Feat/postgres cart read#23
KopfSzmercen wants to merge 4 commits intomainfrom
feat/postgres-cart-read

Conversation

@KopfSzmercen
Copy link
Copy Markdown
Collaborator

No description provided.


namespace DotNetBoilerplate.Core.Carts;

public class Quantity
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pododawać sealed do klas

public Quantity Quantity { get; private set; }
public Guid CartId { get; private set; }

public void UpdateItem(Quantity quantity){
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update quantity

public List<CartItem> Items { get; private set; }
public UserId Owner { get; private set; }
public DateTime CreatedAt { get; private set; }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dodać update at

// Relationships
builder.HasOne<Cart>()
.WithMany(c => c.Items)
.HasForeignKey("CartId")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateCartItem

command.Quantity,
cart.Id
);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cart.UpdateItem(item)


namespace DotNetBoilerplate.Application.Carts.Delete;

internal sealed class DeleteHandler(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeleteCart handler

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants