veza/veza-backend-api/internal/models/gear.go
2026-03-05 23:03:43 +01:00

57 lines
3.4 KiB
Go

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// GearItem represents a user's equipment/gear in their inventory
type GearItem struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id" db:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id" db:"user_id"`
Name string `gorm:"size:200;not null" json:"name" db:"name"`
Category string `gorm:"size:100" json:"category" db:"category"`
Brand string `gorm:"size:200" json:"brand" db:"brand"`
Model string `gorm:"size:200" json:"model" db:"model"`
SerialNumber string `gorm:"size:100" json:"serialNumber" db:"serial_number"`
Image string `gorm:"size:500" json:"image" db:"image"`
Images []string `gorm:"type:jsonb;default:'[]'" json:"images" db:"images"`
Status string `gorm:"size:50;default:'Active'" json:"status" db:"status"`
Condition string `gorm:"size:50;default:'Good'" json:"condition" db:"condition"`
PurchaseDate *time.Time `json:"purchaseDate" db:"purchase_date"`
PurchasePrice float64 `gorm:"type:decimal(12,2);default:0" json:"purchasePrice" db:"purchase_price"`
Currency string `gorm:"size:3;default:'USD'" json:"currency" db:"currency"`
Vendor string `gorm:"size:200" json:"vendor" db:"vendor"`
OrderNumber string `gorm:"size:100" json:"orderNumber" db:"order_number"`
WarrantyStart *time.Time `json:"warrantyStart" db:"warranty_start"`
WarrantyExpire *time.Time `json:"warrantyExpire" db:"warranty_expire"`
WarrantyType string `gorm:"size:50" json:"warrantyType" db:"warranty_type"`
WarrantyNotes string `gorm:"type:text" json:"warrantyNotes" db:"warranty_notes"`
SupportContact string `gorm:"size:200" json:"supportContact" db:"support_contact"`
Specs map[string]interface{} `gorm:"type:jsonb;default:'{}'" json:"specs" db:"specs"`
Notes string `gorm:"type:text" json:"notes" db:"notes"`
Documents []map[string]interface{} `gorm:"type:jsonb;default:'[]'" json:"documents" db:"documents"`
MaintenanceHistory []map[string]interface{} `gorm:"type:jsonb;default:'[]'" json:"maintenanceHistory" db:"maintenance_history"`
IsPublic bool `gorm:"default:false" json:"is_public" db:"is_public"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" db:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" db:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" db:"deleted_at"`
User *User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"-"`
GearImages []GearImage `gorm:"foreignKey:GearID;constraint:OnDelete:CASCADE" json:"gear_images,omitempty"`
}
// TableName defines the table name for GORM
func (GearItem) TableName() string {
return "gear_items"
}
// BeforeCreate hook for GORM to generate UUID
func (m *GearItem) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}