Update payment
This commit is contained in:
@@ -28,6 +28,7 @@ type InventoryRepository interface {
|
||||
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
|
||||
BulkUpdate(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)
|
||||
}
|
||||
@@ -276,6 +277,22 @@ func (r *InventoryRepositoryImpl) BulkCreate(ctx context.Context, inventoryItems
|
||||
return r.db.WithContext(ctx).CreateInBatches(inventoryItems, 100).Error
|
||||
}
|
||||
|
||||
func (r *InventoryRepositoryImpl) BulkUpdate(ctx context.Context, inventoryItems []*entities.Inventory) error {
|
||||
if len(inventoryItems) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Use GORM's transaction for bulk updates
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
for _, inventory := range inventoryItems {
|
||||
if err := tx.Save(inventory).Error; err != nil {
|
||||
return fmt.Errorf("failed to update inventory for product %s: %w", inventory.ProductID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (r *InventoryRepositoryImpl) BulkAdjustQuantity(ctx context.Context, adjustments map[uuid.UUID]int, outletID uuid.UUID) error {
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
for productID, delta := range adjustments {
|
||||
|
||||
Reference in New Issue
Block a user