mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-18 21:44:08 +01:00
feat: add inventory domain
This commit is contained in:
parent
e0dc49499b
commit
044a2856cf
61
backend/internal/domain/inventory.go
Normal file
61
backend/internal/domain/inventory.go
Normal file
@ -0,0 +1,61 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
)
|
||||
|
||||
type InventoryStatus string
|
||||
|
||||
const (
|
||||
StatusInStock InventoryStatus = "In Stock"
|
||||
StatusLowStock InventoryStatus = "Low Stock"
|
||||
StatusOutOfStock InventoryStatus = "Out of Stock"
|
||||
)
|
||||
|
||||
type InventoryItem struct {
|
||||
ID string
|
||||
Name string
|
||||
Category string
|
||||
Type string
|
||||
Quantity float64
|
||||
Unit string
|
||||
DateAdded time.Time
|
||||
Status InventoryStatus
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type InventoryFilter struct {
|
||||
Category string
|
||||
Type string
|
||||
Status InventoryStatus
|
||||
StartDate time.Time
|
||||
EndDate time.Time
|
||||
SearchQuery string
|
||||
}
|
||||
|
||||
type InventorySort struct {
|
||||
Field string
|
||||
Direction string
|
||||
}
|
||||
|
||||
func (i *InventoryItem) Validate() error {
|
||||
return validation.ValidateStruct(i,
|
||||
validation.Field(&i.Name, validation.Required),
|
||||
validation.Field(&i.Category, validation.Required),
|
||||
validation.Field(&i.Type, validation.Required),
|
||||
validation.Field(&i.Quantity, validation.Required, validation.Min(0.0)),
|
||||
validation.Field(&i.Unit, validation.Required),
|
||||
validation.Field(&i.Status, validation.Required, validation.In(StatusInStock, StatusLowStock, StatusOutOfStock)),
|
||||
)
|
||||
}
|
||||
|
||||
type InventoryRepository interface {
|
||||
GetByID(ctx context.Context, id string) (InventoryItem, error)
|
||||
GetWithFilter(ctx context.Context, filter InventoryFilter, sort InventorySort) ([]InventoryItem, error)
|
||||
CreateOrUpdate(ctx context.Context, item *InventoryItem) error
|
||||
Delete(ctx context.Context, id string) error
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user