init
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Inventory struct {
|
||||
ID uuid.UUID
|
||||
OutletID uuid.UUID
|
||||
ProductID uuid.UUID
|
||||
Quantity int
|
||||
ReorderLevel int
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type CreateInventoryRequest struct {
|
||||
OutletID uuid.UUID
|
||||
ProductID uuid.UUID
|
||||
Quantity int
|
||||
ReorderLevel int
|
||||
}
|
||||
|
||||
type UpdateInventoryRequest struct {
|
||||
Quantity *int
|
||||
ReorderLevel *int
|
||||
}
|
||||
|
||||
type InventoryAdjustmentRequest struct {
|
||||
Delta int
|
||||
Reason string
|
||||
}
|
||||
|
||||
type InventoryResponse struct {
|
||||
ID uuid.UUID
|
||||
OutletID uuid.UUID
|
||||
ProductID uuid.UUID
|
||||
Quantity int
|
||||
ReorderLevel int
|
||||
IsLowStock bool
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (i *Inventory) IsLowStock() bool {
|
||||
return i.Quantity <= i.ReorderLevel
|
||||
}
|
||||
|
||||
func (i *Inventory) CanFulfillOrder(requestedQuantity int) bool {
|
||||
return i.Quantity >= requestedQuantity
|
||||
}
|
||||
|
||||
func (i *Inventory) AdjustQuantity(delta int) int {
|
||||
newQuantity := i.Quantity + delta
|
||||
if newQuantity < 0 {
|
||||
newQuantity = 0
|
||||
}
|
||||
return newQuantity
|
||||
}
|
||||
Reference in New Issue
Block a user