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

61 lines
1.9 KiB
Go
Raw Normal View History

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// Queue represents a user's playback queue
type Queue struct {
2026-03-05 22:03:43 +00:00
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex" json:"user_id"`
CurrentTrackID *uuid.UUID `gorm:"type:uuid" json:"current_track_id,omitempty"`
CurrentPosition int `gorm:"not null;default:0" json:"current_position"`
IsPlaying bool `gorm:"not null;default:false" json:"is_playing"`
Shuffle bool `gorm:"not null;default:false" json:"shuffle"`
RepeatMode string `gorm:"size:20;not null;default:off" json:"repeat_mode"`
Volume int `gorm:"not null;default:100" json:"volume"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
Items []QueueItem `gorm:"foreignKey:QueueID;constraint:OnDelete:CASCADE" json:"items,omitempty"`
}
// TableName defines the table name for GORM
func (Queue) TableName() string {
return "queues"
}
// BeforeCreate GORM hook to generate UUID if not set
func (q *Queue) BeforeCreate(tx *gorm.DB) error {
if q.ID == uuid.Nil {
q.ID = uuid.New()
}
return nil
}
// QueueItem represents a track in a queue
type QueueItem struct {
2026-03-05 22:03:43 +00:00
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
QueueID uuid.UUID `gorm:"type:uuid;not null" json:"queue_id"`
TrackID uuid.UUID `gorm:"type:uuid;not null" json:"track_id"`
Position int `gorm:"not null" json:"position"`
AddedAt time.Time `gorm:"autoCreateTime" json:"added_at"`
Track Track `gorm:"foreignKey:TrackID" json:"track,omitempty"`
}
// TableName defines the table name for GORM
func (QueueItem) TableName() string {
return "queue_items"
}
// BeforeCreate GORM hook to generate UUID if not set
func (qi *QueueItem) BeforeCreate(tx *gorm.DB) error {
if qi.ID == uuid.Nil {
qi.ID = uuid.New()
}
return nil
}