48 lines
1.9 KiB
Go
48 lines
1.9 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
type Product struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name" binding:"required"`
|
|
Category string `json:"category" binding:"required"`
|
|
Description string `json:"description"`
|
|
Stock float64 `json:"stock"` // ← ajouter le stock ici
|
|
Unit string `json:"unit"` // kg | g | bag | l | cl | pcs | u
|
|
Prices []ProductPrice `json:"prices"`
|
|
Media []Media `json:"media,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type ProductPrice struct {
|
|
ID int `json:"id"`
|
|
ProductID int `json:"product_id"`
|
|
Quantity float64 `json:"quantity" binding:"required"`
|
|
Price float64 `json:"price" binding:"required"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type StockInfo struct {
|
|
ProductID int `json:"product_id"`
|
|
ProductName string `json:"product_name"`
|
|
Category string `json:"category"`
|
|
Quantity float64 `json:"quantity"`
|
|
Reserved float64 `json:"reserved"`
|
|
Available float64 `json:"available"`
|
|
LastUpdated string `json:"last_updated"`
|
|
}
|
|
|
|
// ============================================
|
|
// MÉTHODES POUR L'INTERFACE ProductInterface
|
|
// ============================================
|
|
func (p *Product) GetName() string { return p.Name }
|
|
func (p *Product) GetCategory() string { return p.Category }
|
|
func (p *Product) GetDescription() string { return p.Description }
|
|
func (p *Product) GetStock() float64 { return p.Stock }
|
|
func (p *Product) GetUnit() string { return p.Unit }
|
|
func (p *Product) GetPrices() []ProductPrice { return p.Prices }
|
|
func (p *Product) SetID(id int) { p.ID = id }
|
|
func (p *Product) SetCreatedAt(t time.Time) { p.CreatedAt = t }
|
|
func (p *Product) SetUpdatedAt(t time.Time) { p.UpdatedAt = t }
|