From ba60e224042a3f777ed918568e97e58d95917c2d Mon Sep 17 00:00:00 2001 From: matst80 Date: Fri, 3 Jul 2026 23:11:03 +0200 Subject: [PATCH] fix --- pkg/inventory/doc.go | 11 +++++----- pkg/inventory/request_types.go | 37 ++++++++++++++++++++++++++++++++++ pkg/inventory/types.go | 30 --------------------------- 3 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 pkg/inventory/request_types.go diff --git a/pkg/inventory/doc.go b/pkg/inventory/doc.go index bfc312e..2cada83 100644 --- a/pkg/inventory/doc.go +++ b/pkg/inventory/doc.go @@ -17,9 +17,10 @@ // listener.go subscribes to the inventory_changed Redis pub/sub channel // and mirrors upstream events into the local cache. // -// TODO: types.go mixes storage types (InventoryItem, InventoryReference) -// with request types (CartReserveRequest, ReserveRequest). Split into -// `types/storage.go` and `types/cart.go` so callers can depend on only -// what they need. Start by moving CartReserveRequest + ReserveRequest to -// `types/cart.go` and adjusting the imports in cmd/*. +// Request and reservation DTOs (CartReserveRequest, ReserveRequest, +// CartID, ReservationStatus, ReservationSummary) now live in +// request_types.go. Storage types (InventoryItem, InventoryReference, +// InventoryResult) remain in types.go. When adding a new request shape, +// put it in request_types.go; when adding a new storage shape, put it +// in types.go. package inventory diff --git a/pkg/inventory/request_types.go b/pkg/inventory/request_types.go new file mode 100644 index 0000000..c35fb53 --- /dev/null +++ b/pkg/inventory/request_types.go @@ -0,0 +1,37 @@ +package inventory + +import "time" + +// Request and reservation DTOs — separated from storage types (types.go) +// so callers that only need read-side shapes don't pull in cart-reservation +// concepts. See doc.go for the split rationale. + +type CartID string + +type ReserveRequest struct { + *InventoryReference + Quantity uint32 +} + +type CartReserveRequest struct { + *InventoryReference + CartID CartID + Quantity uint32 + TTL time.Duration +} + +// CartReservationService interface was removed in favor of +// platform/inventory.ReservationPolicy. Consumers should depend on the +// platform seam; the concrete *RedisCartReservationService implements its +// methods directly. + +type ReservationStatus struct { + Active bool + RemainingTime time.Duration +} + +type ReservationSummary struct { + ReservationCount int64 `json:"reservation_count"` + EarliestRelease time.Time `json:"earliest_release"` + RemainingItems int64 `json:"remaining_items"` +} diff --git a/pkg/inventory/types.go b/pkg/inventory/types.go index 01bcb27..9ea066b 100644 --- a/pkg/inventory/types.go +++ b/pkg/inventory/types.go @@ -33,37 +33,7 @@ type InventoryService interface { ReservationCheck(ctx context.Context, req ...ReserveRequest) (*ReserveRequest, error) } -type ReserveRequest struct { - *InventoryReference - Quantity uint32 -} - type InventoryResult struct { *InventoryReference Quantity uint32 } - -type CartID string - -type CartReserveRequest struct { - *InventoryReference - CartID CartID - Quantity uint32 - TTL time.Duration -} - -// CartReservationService interface was removed in favor of -// platform/inventory.ReservationPolicy. Consumers should depend on the -// platform seam; the concrete *RedisCartReservationService implements its -// methods directly. - -type ReservationStatus struct { - Active bool - RemainingTime time.Duration -} - -type ReservationSummary struct { - ReservationCount int64 `json:"reservation_count"` - EarliestRelease time.Time `json:"earliest_release"` - RemainingItems int64 `json:"remaining_items"` -}