111 lines
3.8 KiB
Go
111 lines
3.8 KiB
Go
|
|
package music
|
||
|
|
|
||
|
|
import (
|
||
|
|
"arimelody-web/model"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/jmoiron/sqlx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type MusicRepository interface {
|
||
|
|
// artists
|
||
|
|
|
||
|
|
GetAllArtists() ([]*model.Artist, error)
|
||
|
|
GetArtistCount() (int, error)
|
||
|
|
// Fetches an artist by ID, returning an error if one was encountered.
|
||
|
|
// If the artist does not exist, both response fields are nil.
|
||
|
|
GetArtistByID(id string) (*model.Artist, error)
|
||
|
|
GetArtistsNotOnRelease(releaseID string) ([]*model.Artist, error)
|
||
|
|
GetArtistCredits(artistID string, showHidden bool) ([]*model.Credit, error)
|
||
|
|
|
||
|
|
CreateArtist(id string, name string, website string, avatar string) error
|
||
|
|
|
||
|
|
UpdateArtist(artist *model.Artist) error
|
||
|
|
UpdateArtistID(oldID string, newID string) error
|
||
|
|
UpdateArtistName(id string, name string) error
|
||
|
|
UpdateArtistWebsite(id string, website string) error
|
||
|
|
UpdateArtistAvatar(id string, avatar string) error
|
||
|
|
|
||
|
|
DeleteArtist(id string) (string, error)
|
||
|
|
|
||
|
|
// releases
|
||
|
|
|
||
|
|
// Fetch all releases.
|
||
|
|
// Filters to visible releases if `onlyVisible = true`.
|
||
|
|
// If `limit > 0`, limits the number of results.
|
||
|
|
GetAllReleases(onlyVisible bool, limit int) ([]*model.Release, error)
|
||
|
|
GetReleaseCount(onlyVisible bool) (int, error)
|
||
|
|
GetReleaseByID(id string) (*model.Release, error)
|
||
|
|
|
||
|
|
GetReleaseTracks(id string) ([]*model.Track, error)
|
||
|
|
GetReleaseCredits(id string) ([]*model.Credit, error)
|
||
|
|
GetReleaseLinks(id string) ([]*model.Link, error)
|
||
|
|
|
||
|
|
CreateRelease(id string, title string, releaseType model.ReleaseType, releaseDate time.Time, artworkURL string) error
|
||
|
|
|
||
|
|
UpdateRelease(release *model.Release) error
|
||
|
|
UpdateReleaseID(oldID string, newID string) error
|
||
|
|
UpdateReleaseVisibility(id string, visible bool) error
|
||
|
|
UpdateReleaseTitle(id string, title string) error
|
||
|
|
UpdateReleaseDescription(id string, description string) error
|
||
|
|
UpdateReleaseType(id string, releaseType model.ReleaseType) error
|
||
|
|
UpdateReleaseDate(id string, releaseDate time.Time) error
|
||
|
|
UpdateReleaseArtwork(id string, artwork string) error
|
||
|
|
UpdateReleaseBuyInfo(id string, buyName string, buyLink string) error
|
||
|
|
UpdateReleaseCopyright(id string, copyright string, url string) error
|
||
|
|
UpdateReleaseTracks(id string, newTrackIDs []string) error
|
||
|
|
UpdateReleaseCredits(id string, newCredits []*model.Credit) error
|
||
|
|
UpdateReleaseLinks(id string, newLinks []*model.Link) error
|
||
|
|
|
||
|
|
DeleteRelease(id string) (string, error)
|
||
|
|
|
||
|
|
// tracks
|
||
|
|
|
||
|
|
GetAllTracks() ([]*model.Track, error)
|
||
|
|
GetTrackCount() (int, error)
|
||
|
|
GetTrackByID(id string) (*model.Track, error)
|
||
|
|
GetOrphanTracks() ([]*model.Track, error)
|
||
|
|
GetTracksNotOnRelease(releaseID string) ([]*model.Track, error)
|
||
|
|
GetTrackReleases(trackID string) ([]*model.Release, error)
|
||
|
|
|
||
|
|
CreateTrack(title string, description string, lyrics string, previewURL string) (string, error)
|
||
|
|
|
||
|
|
UpdateTrack(track *model.Track) error
|
||
|
|
UpdateTrackTitle(id string, title string) error
|
||
|
|
UpdateTrackDescription(id string, description string) error
|
||
|
|
UpdateTrackLyrics(id string, lyrics string) error
|
||
|
|
UpdateTrackPreviewURL(id string, previewURL string) error
|
||
|
|
|
||
|
|
DeleteTrack(id string) (string, error)
|
||
|
|
}
|
||
|
|
|
||
|
|
type (
|
||
|
|
MusicRepositoryPostgres struct {
|
||
|
|
db *sqlx.DB
|
||
|
|
}
|
||
|
|
|
||
|
|
MusicRepositoryMemory struct {
|
||
|
|
artists []*model.Artist
|
||
|
|
releases []*model.Release
|
||
|
|
tracks []*model.Track
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
var _ MusicRepository = new(MusicRepositoryPostgres)
|
||
|
|
func NewMusicRepositoryPostgres(db *sqlx.DB) *MusicRepositoryPostgres {
|
||
|
|
return &MusicRepositoryPostgres{ db: db }
|
||
|
|
}
|
||
|
|
|
||
|
|
var _ MusicRepository = new(MusicRepositoryMemory)
|
||
|
|
func NewMusicRepositoryMemory(
|
||
|
|
artists []*model.Artist,
|
||
|
|
releases []*model.Release,
|
||
|
|
tracks []*model.Track,
|
||
|
|
) *MusicRepositoryMemory {
|
||
|
|
return &MusicRepositoryMemory{
|
||
|
|
artists: artists,
|
||
|
|
releases: releases,
|
||
|
|
tracks: tracks,
|
||
|
|
}
|
||
|
|
}
|