veza/veza-backend-api/internal/models/gear_document.go

32 lines
854 B
Go
Raw Normal View History

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// GearDocument stores a document (invoice, manual, etc.) for a gear item
type GearDocument struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
GearID uuid.UUID `gorm:"type:uuid;not null" json:"gear_id"`
Type string `gorm:"size:50;not null;default:'invoice'" json:"type"`
StorageKey string `gorm:"type:text;not null" json:"storage_key"`
Filename string `gorm:"size:255;not null" json:"filename"`
UploadedAt time.Time `gorm:"autoCreateTime" json:"uploaded_at"`
Gear *GearItem `gorm:"foreignKey:GearID;constraint:OnDelete:CASCADE" json:"-"`
}
func (GearDocument) TableName() string {
return "gear_documents"
}
func (m *GearDocument) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}