init
This commit is contained in:
@@ -11,6 +11,27 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type InventoryRepository interface {
|
||||
Create(ctx context.Context, inventory *entities.Inventory) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*entities.Inventory, error)
|
||||
GetWithRelations(ctx context.Context, id uuid.UUID) (*entities.Inventory, error)
|
||||
GetByProductAndOutlet(ctx context.Context, productID, outletID uuid.UUID) (*entities.Inventory, error)
|
||||
GetByOutlet(ctx context.Context, outletID uuid.UUID) ([]*entities.Inventory, error)
|
||||
GetByProduct(ctx context.Context, productID uuid.UUID) ([]*entities.Inventory, error)
|
||||
GetLowStock(ctx context.Context, outletID uuid.UUID) ([]*entities.Inventory, error)
|
||||
GetZeroStock(ctx context.Context, outletID uuid.UUID) ([]*entities.Inventory, error)
|
||||
Update(ctx context.Context, inventory *entities.Inventory) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
List(ctx context.Context, filters map[string]interface{}, limit, offset int) ([]*entities.Inventory, int64, error)
|
||||
Count(ctx context.Context, filters map[string]interface{}) (int64, error)
|
||||
AdjustQuantity(ctx context.Context, productID, outletID uuid.UUID, delta int) (*entities.Inventory, error)
|
||||
SetQuantity(ctx context.Context, productID, outletID uuid.UUID, quantity int) (*entities.Inventory, error)
|
||||
UpdateReorderLevel(ctx context.Context, id uuid.UUID, reorderLevel int) error
|
||||
BulkCreate(ctx context.Context, inventoryItems []*entities.Inventory) error
|
||||
BulkAdjustQuantity(ctx context.Context, adjustments map[uuid.UUID]int, outletID uuid.UUID) error
|
||||
GetTotalValueByOutlet(ctx context.Context, outletID uuid.UUID) (float64, error)
|
||||
}
|
||||
|
||||
type InventoryRepositoryImpl struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
@@ -209,10 +230,8 @@ func (r *InventoryRepositoryImpl) SetQuantity(ctx context.Context, productID, ou
|
||||
var inventory entities.Inventory
|
||||
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// Get current inventory
|
||||
if err := tx.Where("product_id = ? AND outlet_id = ?", productID, outletID).First(&inventory).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// Inventory doesn't exist, create it with the specified quantity
|
||||
inventory = entities.Inventory{
|
||||
ProductID: productID,
|
||||
OutletID: outletID,
|
||||
|
||||
Reference in New Issue
Block a user