models

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	ID        uuid.UUID      `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // Soft delete support hidden from JSON
}

Base contains common columns for all tables. We use UUID v4 (gen_random_uuid) for ID obfuscation and security.

type Comment

type Comment struct {
	Base
	Content string `gorm:"type:text;not null" json:"content"`

	// Relationships
	AuthorID uuid.UUID `gorm:"type:uuid;index;not null" json:"author_id"`
	Author   *User     `gorm:"foreignKey:AuthorID" json:"author"`

	TrackID uuid.UUID `gorm:"type:uuid;index;not null" json:"track_id"`
	Track   *Track    `gorm:"foreignKey:TrackID" json:"track"`

	// Self-referencing replies
	ReplyToID *uuid.UUID `gorm:"type:uuid" json:"reply_to_id,omitempty"`
	Replies   []Comment  `gorm:"foreignKey:ReplyToID" json:"replies,omitempty"`
}

Comment supports nested (threaded) replies.

type FriendRequest

type FriendRequest struct {
	Base
	SenderID   uuid.UUID           `gorm:"index"`
	Sender     *User               `gorm:"foreignKey:SenderID;references:ID;onDelete:CASCADE"`
	ReceiverID uuid.UUID           `gorm:"index"`
	Receiver   *User               `gorm:"foreignKey:ReceiverID;references:ID;onDelete:CASCADE"`
	Status     FriendRequestStatus `gorm:"default:pending"`
}

type FriendRequestStatus

type FriendRequestStatus string
const (
	Pending  FriendRequestStatus = "pending"
	Accepted FriendRequestStatus = "accepted"
	Rejected FriendRequestStatus = "rejected"
)

type Genre

type Genre struct {
	Base
	Name string `gorm:"type:varchar(50);uniqueIndex;not null" json:"name"`

	// Self-referencing tree logic
	// TODO (pipo) : use anonymous TreeNode[uuid.UUID] field instead
	ParentID  *uuid.UUID `gorm:"type:uuid;index" json:"parent_id,omitempty"`
	Parent    *Genre     `gorm:"foreignKey:ParentID" json:"parent,omitempty"`
	SubGenres []Genre    `gorm:"foreignKey:ParentID" json:"sub_genres,omitempty"`

	// Back-reference to tracks (many2many)
	Tracks []Track `gorm:"many2many:track_genres;" json:"tracks,omitempty"`
}

Genre supports a recursive tree (Sub-genres) and many-to-many track linking.

type Project

type Project struct {
	Base
	Name        string            `gorm:"type:varchar(100);not null" json:"name"`
	Description string            `gorm:"type:text" json:"description"`
	Visibility  ProjectVisibility `gorm:"type:varchar(20);default:'private'" json:"visibility"`

	// The DAW State
	JSONProject datatypes.JSON `gorm:"type:jsonb" json:"json_project" swaggertype:"object"`

	// Ownership
	OwnerID uuid.UUID `gorm:"type:uuid;not null;index" json:"owner_id"`
	Owner   *User     `gorm:"foreignKey:OwnerID" json:"owner"`
}

type ProjectVisibility

type ProjectVisibility string

Visibility Enum

const (
	VisibilityPublic  ProjectVisibility = "public"
	VisibilityPrivate ProjectVisibility = "private"
	VisibilityFriends ProjectVisibility = "friends"
)

type Rating

type Rating struct {
	Base
	// GORM Check constraint ensures DB integrity (1-10)
	Value int `gorm:"check:value >= 1 AND value <= 10;not null" json:"value"`

	AuthorID uuid.UUID `gorm:"type:uuid;index:idx_author_track,unique;not null" json:"author_id"`
	Author   *User     `gorm:"foreignKey:AuthorID" json:"author"`

	TrackID uuid.UUID `gorm:"type:uuid;index:idx_author_track,unique;not null" json:"track_id"`
	Track   *Track    `gorm:"foreignKey:TrackID" json:"track"`
}

type Track

type Track struct {
	Base
	Name string `gorm:"not null" json:"name" binding:"required"`

	// S3 Links (Stored as string URLs)
	CoverImage string `gorm:"type:text" json:"cover_image"`
	AudioFile  string `gorm:"not null;type:text;default:'no audio file'" json:"audio_file" binding:"required"`

	OwnerID uuid.UUID `gorm:"type:uuid;index;not null" json:"owner_id"`
	Owner   *User     `gorm:"foreignKey:OwnerID" json:"owner,omitempty"`

	// Genres & Social
	GenreID uuid.UUID `gorm:"type:uuid;index" json:"genre_id"`
	Genre   *Genre    `gorm:"foreignKey:GenreID" json:"genre"`

	Comments *[]Comment `gorm:"foreignKey:TrackID" json:"comments,omitempty"`

	AverageRating float64 `gorm:"default:0" json:"average_rating"`
	RatingCount   int     `gorm:"default:0" json:"rating_count"`

	IsPublic bool `gorm:"not null" json:"is_public"`

	Ratings *[]Rating `gorm:"foreignKey:TrackID" json:"ratings,omitempty"`
}

Track represents a music upload.

type Upload

type Upload struct {
	Base
	UserID    uuid.UUID `gorm:"type:uuid;index;not null" json:"user_id"`
	ObjectKey string    `gorm:"uniqueIndex" json:"object_key"`
	Checked   bool      `gorm:"default:false" json:"checked"` // false initially
	Valid     bool      `gorm:"default:false" json:"valid"`   // false initially
}

type User

type User struct {
	Base
	Username       string `gorm:"type:citext;uniqueIndex;not null" json:"username"`
	Email          string `gorm:"type:citext;uniqueIndex;not null" json:"email"`
	HashedPassword string `gorm:"not null" json:"-"`
	Avatar         string `gorm:"type:text" json:"avatar"`

	IsVerified   bool      `gorm:"default:false" json:"is_verified"`
	LastActivity time.Time `gorm:"type:timestamp with time zone;index:idx_users_last_activity_at" json:"last_activity"`

	// Relationships
	PreferredGenres []Genre   `gorm:"many2many:user_preferred_genres;" json:"preferred_genres,omitempty"`
	OwnedTracks     []Track   `gorm:"foreignKey:OwnerID" json:"owned_tracks,omitempty"`
	Comments        []Comment `gorm:"foreignKey:AuthorID" json:"comments,omitempty"`
	IsFt            bool      `gorm:"default:false"`
	Friends         []*User   `gorm:"many2many:user_friends"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL