Rename domain to model
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Album struct {
|
||||
ID string
|
||||
Name string
|
||||
ArtistID string `parent:"artist"`
|
||||
CoverArtPath string
|
||||
CoverArtId string
|
||||
Artist string
|
||||
AlbumArtist string
|
||||
Year int `idx:"Year"`
|
||||
Compilation bool
|
||||
Starred bool
|
||||
PlayCount int
|
||||
PlayDate time.Time
|
||||
SongCount int
|
||||
Duration int
|
||||
Rating int
|
||||
Genre string
|
||||
StarredAt time.Time `idx:"Starred"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type Albums []Album
|
||||
|
||||
type AlbumRepository interface {
|
||||
BaseRepository
|
||||
Put(m *Album) error
|
||||
Get(id string) (*Album, error)
|
||||
FindByArtist(artistId string) (Albums, error)
|
||||
GetAll(...QueryOptions) (Albums, error)
|
||||
PurgeInactive(active Albums) error
|
||||
GetAllIds() ([]string, error)
|
||||
GetStarred(...QueryOptions) (Albums, error)
|
||||
Search(q string, offset int, size int) (Albums, error)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
type Artist struct {
|
||||
ID string
|
||||
Name string
|
||||
AlbumCount int
|
||||
}
|
||||
|
||||
type ArtistRepository interface {
|
||||
BaseRepository
|
||||
Put(m *Artist) error
|
||||
Get(id string) (*Artist, error)
|
||||
PurgeInactive(active Artists) error
|
||||
Search(q string, offset int, size int) (Artists, error)
|
||||
}
|
||||
|
||||
type Artists []Artist
|
||||
@@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
import "errors"
|
||||
|
||||
type BaseRepository interface {
|
||||
CountAll() (int64, error)
|
||||
Exists(id string) (bool, error)
|
||||
}
|
||||
|
||||
var (
|
||||
ErrNotFound = errors.New("data not found")
|
||||
)
|
||||
|
||||
type QueryOptions struct {
|
||||
SortBy string
|
||||
Alpha bool
|
||||
Desc bool
|
||||
Offset int
|
||||
Size int
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type CheckSumRepository interface {
|
||||
Get(id string) (string, error)
|
||||
SetData(newSums map[string]string) error
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import "github.com/cloudsonic/sonic-server/utils"
|
||||
|
||||
type ArtistInfo struct {
|
||||
ArtistID string
|
||||
Artist string
|
||||
AlbumCount int
|
||||
}
|
||||
|
||||
type ArtistIndex struct {
|
||||
ID string
|
||||
Artists ArtistInfos
|
||||
}
|
||||
|
||||
type ArtistInfos []ArtistInfo
|
||||
|
||||
func (a ArtistInfos) Len() int { return len(a) }
|
||||
func (a ArtistInfos) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ArtistInfos) Less(i, j int) bool {
|
||||
return utils.NoArticle(a[i].Artist) < utils.NoArticle(a[j].Artist)
|
||||
}
|
||||
|
||||
type ArtistIndexes []ArtistIndex
|
||||
|
||||
type ArtistIndexRepository interface {
|
||||
BaseRepository
|
||||
Put(m *ArtistIndex) error
|
||||
Get(id string) (*ArtistIndex, error)
|
||||
GetAll() (ArtistIndexes, error)
|
||||
DeleteAll() error
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MediaFile struct {
|
||||
ID string
|
||||
Path string
|
||||
Title string
|
||||
Album string
|
||||
Artist string
|
||||
ArtistID string
|
||||
AlbumArtist string
|
||||
AlbumID string `parent:"album"`
|
||||
HasCoverArt bool
|
||||
TrackNumber int
|
||||
DiscNumber int
|
||||
Year int
|
||||
Size string
|
||||
Suffix string
|
||||
Duration int
|
||||
BitRate int
|
||||
Genre string
|
||||
Compilation bool
|
||||
PlayCount int
|
||||
PlayDate time.Time
|
||||
Rating int
|
||||
Starred bool
|
||||
StarredAt time.Time `idx:"Starred"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (mf *MediaFile) ContentType() string {
|
||||
return mime.TypeByExtension("." + mf.Suffix)
|
||||
}
|
||||
|
||||
type MediaFiles []MediaFile
|
||||
|
||||
func (a MediaFiles) Len() int { return len(a) }
|
||||
func (a MediaFiles) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a MediaFiles) Less(i, j int) bool {
|
||||
return (a[i].DiscNumber*1000 + a[i].TrackNumber) < (a[j].DiscNumber*1000 + a[j].TrackNumber)
|
||||
}
|
||||
|
||||
type MediaFileRepository interface {
|
||||
BaseRepository
|
||||
Put(m *MediaFile) error
|
||||
Get(id string) (*MediaFile, error)
|
||||
FindByAlbum(albumId string) (MediaFiles, error)
|
||||
GetStarred(options ...QueryOptions) (MediaFiles, error)
|
||||
PurgeInactive(active MediaFiles) error
|
||||
GetAllIds() ([]string, error)
|
||||
Search(q string, offset int, size int) (MediaFiles, error)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
type MediaFolder struct {
|
||||
ID string
|
||||
Name string
|
||||
Path string
|
||||
}
|
||||
|
||||
type MediaFolders []MediaFolder
|
||||
|
||||
type MediaFolderRepository interface {
|
||||
GetAll() (MediaFolders, error)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
const NowPlayingExpire = 60 * time.Minute
|
||||
|
||||
type NowPlayingInfo struct {
|
||||
TrackID string
|
||||
Start time.Time
|
||||
Username string
|
||||
PlayerId int
|
||||
PlayerName string
|
||||
}
|
||||
|
||||
// This repo must have the semantics of a FIFO queue, for each playerId
|
||||
type NowPlayingRepository interface {
|
||||
// Insert at the head of the queue
|
||||
Enqueue(*NowPlayingInfo) error
|
||||
|
||||
// Removes and returns the element at the end of the queue
|
||||
Dequeue(playerId int) (*NowPlayingInfo, error)
|
||||
|
||||
// Returns the element at the head of the queue (last inserted one)
|
||||
Head(playerId int) (*NowPlayingInfo, error)
|
||||
|
||||
// Returns the element at the end of the queue (first inserted one)
|
||||
Tail(playerId int) (*NowPlayingInfo, error)
|
||||
|
||||
// Size of the queue for the playerId
|
||||
Count(playerId int) (int64, error)
|
||||
|
||||
// Returns all heads from all playerIds
|
||||
GetAll() ([]*NowPlayingInfo, error)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package model
|
||||
|
||||
type Playlist struct {
|
||||
ID string
|
||||
Name string
|
||||
Comment string
|
||||
FullPath string
|
||||
Duration int
|
||||
Owner string
|
||||
Public bool
|
||||
Tracks []string
|
||||
}
|
||||
|
||||
type PlaylistRepository interface {
|
||||
BaseRepository
|
||||
Put(m *Playlist) error
|
||||
Get(id string) (*Playlist, error)
|
||||
GetAll(options ...QueryOptions) (Playlists, error)
|
||||
PurgeInactive(active Playlists) ([]string, error)
|
||||
}
|
||||
|
||||
type Playlists []Playlist
|
||||
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
PropLastScan = "LastScan"
|
||||
)
|
||||
|
||||
type Property struct {
|
||||
ID string
|
||||
Value string
|
||||
}
|
||||
|
||||
type PropertyRepository interface {
|
||||
Put(id string, value string) error
|
||||
Get(id string) (string, error)
|
||||
DefaultGet(id string, defaultValue string) (string, error)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type User struct {
|
||||
ID string
|
||||
Name string
|
||||
Password string
|
||||
IsAdmin bool
|
||||
CreatedAt time.Time
|
||||
}
|
||||
Reference in New Issue
Block a user