package models import ( "gorm.io/gorm" ) // UploadedFile represents a file uploaded to the server type UploadedFile struct { gorm.Model Filename string `gorm:"not null" json:"filename"` FilePath string `gorm:"uniqueIndex;not null" json:"file_path"` FileURL string `gorm:"not null" json:"file_url"` FileSize int64 `gorm:"default:0" json:"file_size"` MimeType string `json:"mime_type"` UploadedByID *uint `gorm:"index" json:"uploaded_by_id,omitempty"` UploadedBy *User `gorm:"foreignKey:UploadedByID" json:"uploaded_by,omitempty"` Usages []FileUsage `gorm:"foreignKey:FileID" json:"usages,omitempty"` } // FileUsage tracks where a file is being used type FileUsage struct { gorm.Model FileID uint `gorm:"not null;index" json:"file_id"` File *UploadedFile `gorm:"foreignKey:FileID" json:"file,omitempty"` EntityType string `gorm:"not null;index" json:"entity_type"` // article, player, sponsor, event, contact, settings EntityID uint `gorm:"not null;index" json:"entity_id"` FieldName string `json:"field_name"` // image_url, logo_url, attachments, etc. } // TableName specifies the table name for UploadedFile func (UploadedFile) TableName() string { return "uploaded_files" } // TableName specifies the table name for FileUsage func (FileUsage) TableName() string { return "file_usages" }