initial inventory service

This commit is contained in:
matst80
2025-11-04 12:48:41 +01:00
parent 42e38504a3
commit c67ebd7a5f
7 changed files with 237 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
package inventory
import (
"errors"
"sync"
)
type MemoryInventoryService struct {
warehouses map[LocationID]*Warehouse
mu sync.RWMutex
}
func NewMemoryInventoryService() *MemoryInventoryService {
return &MemoryInventoryService{
warehouses: make(map[LocationID]*Warehouse),
}
}
func (s *MemoryInventoryService) AddWarehouse(warehouse *Warehouse) {
s.mu.Lock()
defer s.mu.Unlock()
s.warehouses[warehouse.ID] = warehouse
}
func (s *MemoryInventoryService) GetInventory(sku SKU, locationID LocationID) (*InventoryItem, error) {
s.mu.RLock()
defer s.mu.RUnlock()
warehouse, ok := s.warehouses[locationID]
if !ok {
return nil, errors.New("warehouse not found")
}
for _, item := range warehouse.Inventory {
if item.SKU == sku {
return &item, nil
}
}
return nil, errors.New("sku not found in warehouse")
}
func (s *MemoryInventoryService) ReserveInventory(req ...ReserveRequest) error {
// We'll implement the reservation logic using Lua script execution here
// For now, let's just return an error indicating it's not implemented
return errors.New("reservation not implemented yet")
}