update
This commit is contained in:
@@ -2,6 +2,7 @@ package cart
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.k6n.net/go-cart-actor/pkg/actor"
|
||||
messages "git.k6n.net/go-cart-actor/pkg/messages"
|
||||
@@ -12,32 +13,48 @@ type CartMutationContext struct {
|
||||
reservationService inventory.CartReservationService
|
||||
}
|
||||
|
||||
func NewCartMutationContext(reservationService inventory.CartReservationService) CartMutationContext {
|
||||
return CartMutationContext{
|
||||
func NewCartMutationContext(reservationService inventory.CartReservationService) *CartMutationContext {
|
||||
return &CartMutationContext{
|
||||
reservationService: reservationService,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CartMutationContext) ReserveItem(ctx context.Context, cartId CartId, sku string, locationId string, quantity int) error {
|
||||
func (c *CartMutationContext) ReserveItem(ctx context.Context, cartId CartId, sku string, locationId *string, quantity uint16) (*time.Time, error) {
|
||||
if quantity <= 0 || c.reservationService == nil {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
return c.reservationService.ReserveForCart(ctx, inventory.CartReserveRequest{
|
||||
l := inventory.LocationID("se")
|
||||
if locationId != nil {
|
||||
l = inventory.LocationID(*locationId)
|
||||
}
|
||||
ttl := time.Minute * 15
|
||||
endTime := time.Now().Add(ttl)
|
||||
err := c.reservationService.ReserveForCart(ctx, inventory.CartReserveRequest{
|
||||
CartID: inventory.CartID(cartId.String()),
|
||||
InventoryReference: &inventory.InventoryReference{
|
||||
SKU: inventory.SKU(sku),
|
||||
LocationID: inventory.LocationID(locationId),
|
||||
LocationID: l,
|
||||
},
|
||||
|
||||
TTL: ttl,
|
||||
Quantity: uint32(quantity),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &endTime, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *CartMutationContext) ReleaseItem(ctx context.Context, cartId CartId, sku string, locationId string) error {
|
||||
func (c *CartMutationContext) ReleaseItem(ctx context.Context, cartId CartId, sku string, locationId *string) error {
|
||||
if c.reservationService == nil {
|
||||
return nil
|
||||
}
|
||||
return c.reservationService.ReleaseForCart(ctx, inventory.SKU(sku), inventory.LocationID(locationId), inventory.CartID(cartId.String()))
|
||||
l := inventory.LocationID("se")
|
||||
if locationId != nil {
|
||||
l = inventory.LocationID(*locationId)
|
||||
}
|
||||
return c.reservationService.ReleaseForCart(ctx, inventory.SKU(sku), l, inventory.CartID(cartId.String()))
|
||||
}
|
||||
|
||||
func NewCartMultationRegistry(context *CartMutationContext) actor.MutationRegistry {
|
||||
|
||||
Reference in New Issue
Block a user