inventory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventPlay     = "play"
	EventSkip     = "skip"
	EventComplete = "complete"
)

Listen event type constants

View Source
const (
	StatusApproved = "approved"
)

Status constants

Variables

This section is empty.

Functions

This section is empty.

Types

type ListenEvent

type ListenEvent struct {
	TrackID          int64  `json:"track_id"`
	Mood             string `json:"mood"`
	EventType        string `json:"event"`
	ListenSeconds    int    `json:"listen_seconds"`
	PlaylistPosition *int   `json:"position,omitempty"`
}

ListenEvent represents a single listen engagement event

type MoodStats

type MoodStats struct {
	Mood         string
	TrackCount   int
	TotalSeconds int
}

MoodStats holds aggregated stats for a mood

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository handles track storage operations

func NewRepository

func NewRepository(dbPath string) (*Repository, error)

NewRepository creates a new inventory repository

func (*Repository) BeginTx

func (r *Repository) BeginTx(ctx context.Context) (*sql.Tx, error)

BeginTx starts a new database transaction

func (*Repository) Close

func (r *Repository) Close() error

Close closes the database connection

func (*Repository) GetByID

func (r *Repository) GetByID(id int64) (*Track, error)

GetByID retrieves a track by ID

func (*Repository) GetByMood

func (r *Repository) GetByMood(mood string, instrumentalOnly bool) ([]*Track, error)

GetByMood retrieves all approved tracks for a mood. If instrumentalOnly is true, only tracks with has_vocals=0 are returned.

func (*Repository) GetMoodStats

func (r *Repository) GetMoodStats() ([]MoodStats, error)

GetMoodStats returns track count and total duration per mood

func (*Repository) Ping

func (r *Repository) Ping() error

Ping checks database connectivity (for readiness probes)

func (*Repository) RecordListenEventTx

func (r *Repository) RecordListenEventTx(tx *sql.Tx, evt ListenEvent) error

RecordListenEventTx inserts a listen event within an existing transaction

func (*Repository) UpdatePlayStats

func (r *Repository) UpdatePlayStats(id int64) error

UpdatePlayStats increments play count in the play_stats table. Uses a single INSERT...SELECT to atomically resolve file_path and UPSERT.

func (*Repository) UpdatePlayStatsTx

func (r *Repository) UpdatePlayStatsTx(tx *sql.Tx, id int64) error

UpdatePlayStatsTx increments play count within an existing transaction

type Track

type Track struct {
	ID       int64  `json:"id"`
	FilePath string `json:"file_path"`

	// AudioURL is the resolved playable URL (computed at runtime, not stored)
	AudioURL string `json:"audio_url,omitempty"`

	// Display metadata
	Title  *string `json:"title,omitempty"`
	Artist *string `json:"artist,omitempty"`

	// Classification
	Mood       string  `json:"mood"`
	Energy     string  `json:"energy"`
	TempoBPM   *int    `json:"tempo_bpm,omitempty"`
	HasVocals  bool    `json:"has_vocals"`
	MusicalKey *string `json:"musical_key,omitempty"`

	// Moodlet discovery
	Intensity    *int    `json:"intensity,omitempty"`     // 1-10: 1=light, 10=deep
	TimeAffinity *string `json:"time_affinity,omitempty"` // morning, afternoon, evening, night, any

	// Content
	Lyrics *string `json:"lyrics,omitempty"`

	// Audio properties
	DurationSeconds int `json:"duration_seconds"`

	// Status and tracking
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`

	// Play stats (sourced from play_stats table via LEFT JOIN, not from tracks)
	PlayCount    int        `json:"play_count"`
	LastPlayedAt *time.Time `json:"last_played_at,omitempty"`
}

Track represents an audio track in the inventory

Jump to

Keyboard shortcuts

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