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

30 lines
685 B
Go
Raw Normal View History

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type GearImage struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
GearID uuid.UUID `gorm:"type:uuid;not null" json:"gear_id"`
ImageURL string `gorm:"size:500;not null" json:"image_url"`
Position int `gorm:"not null;default:0" json:"position"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
GearItem GearItem `gorm:"foreignKey:GearID;constraint:OnDelete:CASCADE" json:"-"`
}
func (GearImage) TableName() string {
return "gear_images"
}
func (m *GearImage) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}