mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Rename domain
to model
This commit is contained in:
parent
25686c1742
commit
0ea2bd79d9
54 changed files with 404 additions and 404 deletions
|
@ -7,9 +7,9 @@ import (
|
|||
|
||||
"github.com/cloudsonic/sonic-server/api/responses"
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
)
|
||||
|
||||
|
@ -86,7 +86,7 @@ func (c *BrowsingController) GetMusicDirectory(w http.ResponseWriter, r *http.Re
|
|||
id := ParamString(r, "id")
|
||||
dir, err := c.browser.Directory(r.Context(), id)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, "Requested ID not found ", "id", id)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "Directory not found")
|
||||
case err != nil:
|
||||
|
@ -103,7 +103,7 @@ func (c *BrowsingController) GetArtist(w http.ResponseWriter, r *http.Request) (
|
|||
id := ParamString(r, "id")
|
||||
dir, err := c.browser.Artist(r.Context(), id)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, "Requested ArtistID not found ", "id", id)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "Artist not found")
|
||||
case err != nil:
|
||||
|
@ -120,7 +120,7 @@ func (c *BrowsingController) GetAlbum(w http.ResponseWriter, r *http.Request) (*
|
|||
id := ParamString(r, "id")
|
||||
dir, err := c.browser.Album(r.Context(), id)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, "Requested ID not found ", "id", id)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "Album not found")
|
||||
case err != nil:
|
||||
|
@ -137,7 +137,7 @@ func (c *BrowsingController) GetSong(w http.ResponseWriter, r *http.Request) (*r
|
|||
id := ParamString(r, "id")
|
||||
song, err := c.browser.GetSong(id)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, "Requested ID not found ", "id", id)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "Song not found")
|
||||
case err != nil:
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/api/responses"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type MediaAnnotationController struct {
|
||||
|
@ -36,7 +36,7 @@ func (c *MediaAnnotationController) SetRating(w http.ResponseWriter, r *http.Req
|
|||
err = c.ratings.SetRating(r.Context(), id, rating)
|
||||
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, err)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "ID not found")
|
||||
case err != nil:
|
||||
|
@ -66,7 +66,7 @@ func (c *MediaAnnotationController) Star(w http.ResponseWriter, r *http.Request)
|
|||
log.Debug(r, "Starring items", "ids", ids)
|
||||
err = c.ratings.SetStar(r.Context(), true, ids...)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, err)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "ID not found")
|
||||
case err != nil:
|
||||
|
@ -85,7 +85,7 @@ func (c *MediaAnnotationController) Unstar(w http.ResponseWriter, r *http.Reques
|
|||
log.Debug(r, "Unstarring items", "ids", ids)
|
||||
err = c.ratings.SetStar(r.Context(), false, ids...)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, err)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "Directory not found")
|
||||
case err != nil:
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/api/responses"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type MediaRetrievalController struct {
|
||||
|
@ -42,7 +42,7 @@ func (c *MediaRetrievalController) GetCoverArt(w http.ResponseWriter, r *http.Re
|
|||
err = c.cover.Get(id, size, w)
|
||||
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, err.Error(), "id", id)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "Cover not found")
|
||||
case err != nil:
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"io"
|
||||
"net/http/httptest"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -58,7 +58,7 @@ var _ = Describe("MediaRetrievalController", func() {
|
|||
})
|
||||
|
||||
It("should fail when the file is not found", func() {
|
||||
cover.err = domain.ErrNotFound
|
||||
cover.err = model.ErrNotFound
|
||||
r := newTestRequest("id=34", "size=128")
|
||||
_, err := controller.GetCoverArt(w, r)
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/api/responses"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type PlaylistsController struct {
|
||||
|
@ -46,7 +46,7 @@ func (c *PlaylistsController) GetPlaylist(w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
pinfo, err := c.pls.Get(id)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, err.Error(), "id", id)
|
||||
return nil, NewError(responses.ErrorDataNotFound, "Directory not found")
|
||||
case err != nil:
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/api/responses"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@ func (c *StreamController) getMediaFile(r *http.Request) (mf *engine.Entry, err
|
|||
|
||||
mf, err = c.browser.GetSong(id)
|
||||
switch {
|
||||
case err == domain.ErrNotFound:
|
||||
case err == model.ErrNotFound:
|
||||
log.Error(r, "Mediafile not found", "id", id)
|
||||
return nil, NewError(responses.ErrorDataNotFound)
|
||||
case err != nil:
|
||||
|
|
|
@ -6,40 +6,40 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
)
|
||||
|
||||
type Browser interface {
|
||||
MediaFolders() (domain.MediaFolders, error)
|
||||
Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error)
|
||||
MediaFolders() (model.MediaFolders, error)
|
||||
Indexes(ifModifiedSince time.Time) (model.ArtistIndexes, time.Time, error)
|
||||
Directory(ctx context.Context, id string) (*DirectoryInfo, error)
|
||||
Artist(ctx context.Context, id string) (*DirectoryInfo, error)
|
||||
Album(ctx context.Context, id string) (*DirectoryInfo, error)
|
||||
GetSong(id string) (*Entry, error)
|
||||
}
|
||||
|
||||
func NewBrowser(pr domain.PropertyRepository, fr domain.MediaFolderRepository, ir domain.ArtistIndexRepository,
|
||||
ar domain.ArtistRepository, alr domain.AlbumRepository, mr domain.MediaFileRepository) Browser {
|
||||
func NewBrowser(pr model.PropertyRepository, fr model.MediaFolderRepository, ir model.ArtistIndexRepository,
|
||||
ar model.ArtistRepository, alr model.AlbumRepository, mr model.MediaFileRepository) Browser {
|
||||
return &browser{pr, fr, ir, ar, alr, mr}
|
||||
}
|
||||
|
||||
type browser struct {
|
||||
propRepo domain.PropertyRepository
|
||||
folderRepo domain.MediaFolderRepository
|
||||
indexRepo domain.ArtistIndexRepository
|
||||
artistRepo domain.ArtistRepository
|
||||
albumRepo domain.AlbumRepository
|
||||
mfileRepo domain.MediaFileRepository
|
||||
propRepo model.PropertyRepository
|
||||
folderRepo model.MediaFolderRepository
|
||||
indexRepo model.ArtistIndexRepository
|
||||
artistRepo model.ArtistRepository
|
||||
albumRepo model.AlbumRepository
|
||||
mfileRepo model.MediaFileRepository
|
||||
}
|
||||
|
||||
func (b *browser) MediaFolders() (domain.MediaFolders, error) {
|
||||
func (b *browser) MediaFolders() (model.MediaFolders, error) {
|
||||
return b.folderRepo.GetAll()
|
||||
}
|
||||
|
||||
func (b *browser) Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error) {
|
||||
l, err := b.propRepo.DefaultGet(domain.PropLastScan, "-1")
|
||||
func (b *browser) Indexes(ifModifiedSince time.Time) (model.ArtistIndexes, time.Time, error) {
|
||||
l, err := b.propRepo.DefaultGet(model.PropLastScan, "-1")
|
||||
ms, _ := strconv.ParseInt(l, 10, 64)
|
||||
lastModified := utils.ToTime(ms)
|
||||
|
||||
|
@ -100,7 +100,7 @@ func (b *browser) Directory(ctx context.Context, id string) (*DirectoryInfo, err
|
|||
return b.Album(ctx, id)
|
||||
default:
|
||||
log.Debug(ctx, "Directory not found", "id", id)
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ func (b *browser) GetSong(id string) (*Entry, error) {
|
|||
return &entry, nil
|
||||
}
|
||||
|
||||
func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
|
||||
func (b *browser) buildArtistDir(a *model.Artist, albums model.Albums) *DirectoryInfo {
|
||||
dir := &DirectoryInfo{
|
||||
Id: a.ID,
|
||||
Name: a.Name,
|
||||
|
@ -129,7 +129,7 @@ func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *Direct
|
|||
return dir
|
||||
}
|
||||
|
||||
func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *DirectoryInfo {
|
||||
func (b *browser) buildAlbumDir(al *model.Album, tracks model.MediaFiles) *DirectoryInfo {
|
||||
dir := &DirectoryInfo{
|
||||
Id: al.ID,
|
||||
Name: al.Name,
|
||||
|
@ -172,7 +172,7 @@ func (b *browser) isAlbum(ctx context.Context, id string) bool {
|
|||
return found
|
||||
}
|
||||
|
||||
func (b *browser) retrieveArtist(id string) (a *domain.Artist, as domain.Albums, err error) {
|
||||
func (b *browser) retrieveArtist(id string) (a *model.Artist, as model.Albums, err error) {
|
||||
a, err = b.artistRepo.Get(id)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error reading Artist %s from DB: %v", id, err)
|
||||
|
@ -185,7 +185,7 @@ func (b *browser) retrieveArtist(id string) (a *domain.Artist, as domain.Albums,
|
|||
return
|
||||
}
|
||||
|
||||
func (b *browser) retrieveAlbum(id string) (al *domain.Album, mfs domain.MediaFiles, err error) {
|
||||
func (b *browser) retrieveAlbum(id string) (al *model.Album, mfs model.MediaFiles, err error) {
|
||||
al, err = b.albumRepo.Get(id)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error reading Album %s from DB: %v", id, err)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type Entry struct {
|
||||
|
@ -45,7 +45,7 @@ type Entry struct {
|
|||
|
||||
type Entries []Entry
|
||||
|
||||
func FromArtist(ar *domain.Artist) Entry {
|
||||
func FromArtist(ar *model.Artist) Entry {
|
||||
e := Entry{}
|
||||
e.Id = ar.ID
|
||||
e.Title = ar.Name
|
||||
|
@ -54,7 +54,7 @@ func FromArtist(ar *domain.Artist) Entry {
|
|||
return e
|
||||
}
|
||||
|
||||
func FromAlbum(al *domain.Album) Entry {
|
||||
func FromAlbum(al *model.Album) Entry {
|
||||
e := Entry{}
|
||||
e.Id = al.ID
|
||||
e.Title = al.Name
|
||||
|
@ -76,7 +76,7 @@ func FromAlbum(al *domain.Album) Entry {
|
|||
return e
|
||||
}
|
||||
|
||||
func FromMediaFile(mf *domain.MediaFile) Entry {
|
||||
func FromMediaFile(mf *model.MediaFile) Entry {
|
||||
e := Entry{}
|
||||
e.Id = mf.ID
|
||||
e.Title = mf.Title
|
||||
|
@ -111,7 +111,7 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
|
|||
return e
|
||||
}
|
||||
|
||||
func realArtistName(mf *domain.MediaFile) string {
|
||||
func realArtistName(mf *model.MediaFile) string {
|
||||
switch {
|
||||
case mf.Compilation:
|
||||
return "Various Artists"
|
||||
|
@ -122,7 +122,7 @@ func realArtistName(mf *domain.MediaFile) string {
|
|||
return mf.Artist
|
||||
}
|
||||
|
||||
func FromAlbums(albums domain.Albums) Entries {
|
||||
func FromAlbums(albums model.Albums) Entries {
|
||||
entries := make(Entries, len(albums))
|
||||
for i, al := range albums {
|
||||
entries[i] = FromAlbum(&al)
|
||||
|
@ -130,7 +130,7 @@ func FromAlbums(albums domain.Albums) Entries {
|
|||
return entries
|
||||
}
|
||||
|
||||
func FromMediaFiles(mfs domain.MediaFiles) Entries {
|
||||
func FromMediaFiles(mfs model.MediaFiles) Entries {
|
||||
entries := make(Entries, len(mfs))
|
||||
for i, mf := range mfs {
|
||||
entries[i] = FromMediaFile(&mf)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/dhowden/tag"
|
||||
"github.com/nfnt/resize"
|
||||
)
|
||||
|
@ -20,11 +20,11 @@ type Cover interface {
|
|||
}
|
||||
|
||||
type cover struct {
|
||||
mfileRepo domain.MediaFileRepository
|
||||
albumRepo domain.AlbumRepository
|
||||
mfileRepo model.MediaFileRepository
|
||||
albumRepo model.AlbumRepository
|
||||
}
|
||||
|
||||
func NewCover(mr domain.MediaFileRepository, alr domain.AlbumRepository) Cover {
|
||||
func NewCover(mr model.MediaFileRepository, alr model.AlbumRepository) Cover {
|
||||
return &cover{mr, alr}
|
||||
}
|
||||
|
||||
|
@ -46,18 +46,18 @@ func (c *cover) getCoverPath(id string) (string, error) {
|
|||
return mf.Path, nil
|
||||
}
|
||||
}
|
||||
return "", domain.ErrNotFound
|
||||
return "", model.ErrNotFound
|
||||
}
|
||||
|
||||
func (c *cover) Get(id string, size int, out io.Writer) error {
|
||||
path, err := c.getCoverPath(id)
|
||||
if err != nil && err != domain.ErrNotFound {
|
||||
if err != nil && err != model.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
var reader io.Reader
|
||||
|
||||
if err != domain.ErrNotFound {
|
||||
if err != model.ErrNotFound {
|
||||
reader, err = readFromTag(path)
|
||||
} else {
|
||||
var f *os.File
|
||||
|
@ -69,7 +69,7 @@ func (c *cover) Get(id string, size int, out io.Writer) error {
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
return domain.ErrNotFound
|
||||
return model.ErrNotFound
|
||||
}
|
||||
|
||||
if size > 0 {
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"image"
|
||||
"testing"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/persistence"
|
||||
. "github.com/cloudsonic/sonic-server/tests"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
@ -54,7 +54,7 @@ func TestCover(t *testing.T) {
|
|||
err := cover.Get("2", 0, out)
|
||||
|
||||
Convey("Then it should return DatNotFound error", func() {
|
||||
So(err, ShouldEqual, domain.ErrNotFound)
|
||||
So(err, ShouldEqual, model.ErrNotFound)
|
||||
})
|
||||
})
|
||||
Convey("When specifying a size", func() {
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
)
|
||||
|
||||
|
@ -22,17 +22,17 @@ type ListGenerator interface {
|
|||
GetRandomSongs(size int) (Entries, error)
|
||||
}
|
||||
|
||||
func NewListGenerator(alr domain.AlbumRepository, mfr domain.MediaFileRepository, npr domain.NowPlayingRepository) ListGenerator {
|
||||
func NewListGenerator(alr model.AlbumRepository, mfr model.MediaFileRepository, npr model.NowPlayingRepository) ListGenerator {
|
||||
return &listGenerator{alr, mfr, npr}
|
||||
}
|
||||
|
||||
type listGenerator struct {
|
||||
albumRepo domain.AlbumRepository
|
||||
mfRepository domain.MediaFileRepository
|
||||
npRepo domain.NowPlayingRepository
|
||||
albumRepo model.AlbumRepository
|
||||
mfRepository model.MediaFileRepository
|
||||
npRepo model.NowPlayingRepository
|
||||
}
|
||||
|
||||
func (g *listGenerator) query(qo domain.QueryOptions, offset int, size int) (Entries, error) {
|
||||
func (g *listGenerator) query(qo model.QueryOptions, offset int, size int) (Entries, error) {
|
||||
qo.Offset = offset
|
||||
qo.Size = size
|
||||
albums, err := g.albumRepo.GetAll(qo)
|
||||
|
@ -41,32 +41,32 @@ func (g *listGenerator) query(qo domain.QueryOptions, offset int, size int) (Ent
|
|||
}
|
||||
|
||||
func (g *listGenerator) GetNewest(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{SortBy: "CreatedAt", Desc: true, Alpha: true}
|
||||
qo := model.QueryOptions{SortBy: "CreatedAt", Desc: true, Alpha: true}
|
||||
return g.query(qo, offset, size)
|
||||
}
|
||||
|
||||
func (g *listGenerator) GetRecent(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{SortBy: "PlayDate", Desc: true, Alpha: true}
|
||||
qo := model.QueryOptions{SortBy: "PlayDate", Desc: true, Alpha: true}
|
||||
return g.query(qo, offset, size)
|
||||
}
|
||||
|
||||
func (g *listGenerator) GetFrequent(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{SortBy: "PlayCount", Desc: true}
|
||||
qo := model.QueryOptions{SortBy: "PlayCount", Desc: true}
|
||||
return g.query(qo, offset, size)
|
||||
}
|
||||
|
||||
func (g *listGenerator) GetHighest(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{SortBy: "Rating", Desc: true}
|
||||
qo := model.QueryOptions{SortBy: "Rating", Desc: true}
|
||||
return g.query(qo, offset, size)
|
||||
}
|
||||
|
||||
func (g *listGenerator) GetByName(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{SortBy: "Name", Alpha: true}
|
||||
qo := model.QueryOptions{SortBy: "Name", Alpha: true}
|
||||
return g.query(qo, offset, size)
|
||||
}
|
||||
|
||||
func (g *listGenerator) GetByArtist(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{SortBy: "Artist", Alpha: true}
|
||||
qo := model.QueryOptions{SortBy: "Artist", Alpha: true}
|
||||
return g.query(qo, offset, size)
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ func (g *listGenerator) GetRandomSongs(size int) (Entries, error) {
|
|||
}
|
||||
|
||||
func (g *listGenerator) GetStarred(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{Offset: offset, Size: size, Desc: true}
|
||||
qo := model.QueryOptions{Offset: offset, Size: size, Desc: true}
|
||||
albums, err := g.albumRepo.GetStarred(qo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -126,7 +126,7 @@ func (g *listGenerator) GetAllStarred() (Entries, Entries, error) {
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
mediaFiles, err := g.mfRepository.GetStarred(domain.QueryOptions{Desc: true})
|
||||
mediaFiles, err := g.mfRepository.GetStarred(model.QueryOptions{Desc: true})
|
||||
|
||||
return albums, FromMediaFiles(mediaFiles), err
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
func CreateMockNowPlayingRepo() *MockNowPlaying {
|
||||
|
@ -12,8 +12,8 @@ func CreateMockNowPlayingRepo() *MockNowPlaying {
|
|||
}
|
||||
|
||||
type MockNowPlaying struct {
|
||||
domain.NowPlayingRepository
|
||||
data []domain.NowPlayingInfo
|
||||
model.NowPlayingRepository
|
||||
data []model.NowPlayingInfo
|
||||
t time.Time
|
||||
err bool
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ func (m *MockNowPlaying) SetError(err bool) {
|
|||
m.err = err
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Enqueue(info *domain.NowPlayingInfo) error {
|
||||
func (m *MockNowPlaying) Enqueue(info *model.NowPlayingInfo) error {
|
||||
if m.err {
|
||||
return errors.New("Error!")
|
||||
}
|
||||
|
||||
m.data = append(m.data, domain.NowPlayingInfo{})
|
||||
m.data = append(m.data, model.NowPlayingInfo{})
|
||||
copy(m.data[1:], m.data[0:])
|
||||
m.data[0] = *info
|
||||
|
||||
|
@ -39,7 +39,7 @@ func (m *MockNowPlaying) Enqueue(info *domain.NowPlayingInfo) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Dequeue(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) Dequeue(playerId int) (*model.NowPlayingInfo, error) {
|
||||
if len(m.data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -54,15 +54,15 @@ func (m *MockNowPlaying) Count(playerId int) (int64, error) {
|
|||
return int64(len(m.data)), nil
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) GetAll() ([]*domain.NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) GetAll() ([]*model.NowPlayingInfo, error) {
|
||||
np, err := m.Head(1)
|
||||
if np == nil || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []*domain.NowPlayingInfo{np}, err
|
||||
return []*model.NowPlayingInfo{np}, err
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Head(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) Head(playerId int) (*model.NowPlayingInfo, error) {
|
||||
if len(m.data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (m *MockNowPlaying) Head(playerId int) (*domain.NowPlayingInfo, error) {
|
|||
return &info, nil
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Tail(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (m *MockNowPlaying) Tail(playerId int) (*model.NowPlayingInfo, error) {
|
||||
if len(m.data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func (m *MockNowPlaying) Tail(playerId int) (*domain.NowPlayingInfo, error) {
|
|||
}
|
||||
|
||||
func (m *MockNowPlaying) ClearAll() {
|
||||
m.data = make([]domain.NowPlayingInfo, 0)
|
||||
m.data = make([]model.NowPlayingInfo, 0)
|
||||
m.err = false
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package engine
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
func CreateMockPropertyRepo() *MockProperty {
|
||||
|
@ -11,7 +11,7 @@ func CreateMockPropertyRepo() *MockProperty {
|
|||
}
|
||||
|
||||
type MockProperty struct {
|
||||
domain.PropertyRepository
|
||||
model.PropertyRepository
|
||||
data map[string]string
|
||||
err bool
|
||||
}
|
||||
|
|
|
@ -4,31 +4,31 @@ import (
|
|||
"context"
|
||||
"sort"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/itunesbridge"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type Playlists interface {
|
||||
GetAll() (domain.Playlists, error)
|
||||
GetAll() (model.Playlists, error)
|
||||
Get(id string) (*PlaylistInfo, error)
|
||||
Create(ctx context.Context, name string, ids []string) error
|
||||
Delete(ctx context.Context, playlistId string) error
|
||||
Update(playlistId string, name *string, idsToAdd []string, idxToRemove []int) error
|
||||
}
|
||||
|
||||
func NewPlaylists(itunes itunesbridge.ItunesControl, pr domain.PlaylistRepository, mr domain.MediaFileRepository) Playlists {
|
||||
func NewPlaylists(itunes itunesbridge.ItunesControl, pr model.PlaylistRepository, mr model.MediaFileRepository) Playlists {
|
||||
return &playlists{itunes, pr, mr}
|
||||
}
|
||||
|
||||
type playlists struct {
|
||||
itunes itunesbridge.ItunesControl
|
||||
plsRepo domain.PlaylistRepository
|
||||
mfileRepo domain.MediaFileRepository
|
||||
plsRepo model.PlaylistRepository
|
||||
mfileRepo model.MediaFileRepository
|
||||
}
|
||||
|
||||
func (p *playlists) GetAll() (domain.Playlists, error) {
|
||||
return p.plsRepo.GetAll(domain.QueryOptions{})
|
||||
func (p *playlists) GetAll() (model.Playlists, error) {
|
||||
return p.plsRepo.GetAll(model.QueryOptions{})
|
||||
}
|
||||
|
||||
type PlaylistInfo struct {
|
||||
|
|
|
@ -3,9 +3,9 @@ package engine
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/itunesbridge"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
)
|
||||
|
||||
|
@ -14,15 +14,15 @@ type Ratings interface {
|
|||
SetRating(ctx context.Context, id string, rating int) error
|
||||
}
|
||||
|
||||
func NewRatings(itunes itunesbridge.ItunesControl, mr domain.MediaFileRepository, alr domain.AlbumRepository, ar domain.ArtistRepository) Ratings {
|
||||
func NewRatings(itunes itunesbridge.ItunesControl, mr model.MediaFileRepository, alr model.AlbumRepository, ar model.ArtistRepository) Ratings {
|
||||
return &ratings{itunes, mr, alr, ar}
|
||||
}
|
||||
|
||||
type ratings struct {
|
||||
itunes itunesbridge.ItunesControl
|
||||
mfRepo domain.MediaFileRepository
|
||||
albumRepo domain.AlbumRepository
|
||||
artistRepo domain.ArtistRepository
|
||||
mfRepo model.MediaFileRepository
|
||||
albumRepo model.AlbumRepository
|
||||
artistRepo model.ArtistRepository
|
||||
}
|
||||
|
||||
func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
|
||||
|
@ -51,7 +51,7 @@ func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
return domain.ErrNotFound
|
||||
return model.ErrNotFound
|
||||
}
|
||||
|
||||
func (r ratings) SetStar(ctx context.Context, star bool, ids ...string) error {
|
||||
|
@ -79,7 +79,7 @@ func (r ratings) SetStar(ctx context.Context, star bool, ids ...string) error {
|
|||
}
|
||||
continue
|
||||
}
|
||||
return domain.ErrNotFound
|
||||
return model.ErrNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/itunesbridge"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -17,18 +17,18 @@ const (
|
|||
)
|
||||
|
||||
type Scrobbler interface {
|
||||
Register(ctx context.Context, playerId int, trackId string, playDate time.Time) (*domain.MediaFile, error)
|
||||
NowPlaying(ctx context.Context, playerId int, playerName, trackId, username string) (*domain.MediaFile, error)
|
||||
Register(ctx context.Context, playerId int, trackId string, playDate time.Time) (*model.MediaFile, error)
|
||||
NowPlaying(ctx context.Context, playerId int, playerName, trackId, username string) (*model.MediaFile, error)
|
||||
}
|
||||
|
||||
func NewScrobbler(itunes itunesbridge.ItunesControl, mr domain.MediaFileRepository, npr domain.NowPlayingRepository) Scrobbler {
|
||||
func NewScrobbler(itunes itunesbridge.ItunesControl, mr model.MediaFileRepository, npr model.NowPlayingRepository) Scrobbler {
|
||||
return &scrobbler{itunes, mr, npr}
|
||||
}
|
||||
|
||||
type scrobbler struct {
|
||||
itunes itunesbridge.ItunesControl
|
||||
mfRepo domain.MediaFileRepository
|
||||
npRepo domain.NowPlayingRepository
|
||||
mfRepo model.MediaFileRepository
|
||||
npRepo model.NowPlayingRepository
|
||||
}
|
||||
|
||||
func (s *scrobbler) detectSkipped(ctx context.Context, playerId int, trackId string) {
|
||||
|
@ -68,7 +68,7 @@ func (s *scrobbler) detectSkipped(ctx context.Context, playerId int, trackId str
|
|||
}
|
||||
}
|
||||
|
||||
func (s *scrobbler) Register(ctx context.Context, playerId int, trackId string, playTime time.Time) (*domain.MediaFile, error) {
|
||||
func (s *scrobbler) Register(ctx context.Context, playerId int, trackId string, playTime time.Time) (*model.MediaFile, error) {
|
||||
s.detectSkipped(ctx, playerId, trackId)
|
||||
|
||||
mf, err := s.mfRepo.Get(trackId)
|
||||
|
@ -86,7 +86,7 @@ func (s *scrobbler) Register(ctx context.Context, playerId int, trackId string,
|
|||
return mf, nil
|
||||
}
|
||||
|
||||
func (s *scrobbler) NowPlaying(ctx context.Context, playerId int, playerName, trackId, username string) (*domain.MediaFile, error) {
|
||||
func (s *scrobbler) NowPlaying(ctx context.Context, playerId int, playerName, trackId, username string) (*model.MediaFile, error) {
|
||||
mf, err := s.mfRepo.Get(trackId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -96,6 +96,6 @@ func (s *scrobbler) NowPlaying(ctx context.Context, playerId int, playerName, tr
|
|||
return nil, errors.New(fmt.Sprintf(`ID "%s" not found`, trackId))
|
||||
}
|
||||
|
||||
info := &domain.NowPlayingInfo{TrackID: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
|
||||
info := &model.NowPlayingInfo{TrackID: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
|
||||
return mf, s.npRepo.Enqueue(info)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/kennygrant/sanitize"
|
||||
)
|
||||
|
||||
|
@ -15,12 +15,12 @@ type Search interface {
|
|||
}
|
||||
|
||||
type search struct {
|
||||
artistRepo domain.ArtistRepository
|
||||
albumRepo domain.AlbumRepository
|
||||
mfileRepo domain.MediaFileRepository
|
||||
artistRepo model.ArtistRepository
|
||||
albumRepo model.AlbumRepository
|
||||
mfileRepo model.MediaFileRepository
|
||||
}
|
||||
|
||||
func NewSearch(ar domain.ArtistRepository, alr domain.AlbumRepository, mr domain.MediaFileRepository) Search {
|
||||
func NewSearch(ar model.ArtistRepository, alr model.AlbumRepository, mr model.MediaFileRepository) Search {
|
||||
s := &search{artistRepo: ar, albumRepo: alr, mfileRepo: mr}
|
||||
return s
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
type Artist struct {
|
||||
ID string
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
import "errors"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
type CheckSumRepository interface {
|
||||
Get(id string) (string, error)
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
import "github.com/cloudsonic/sonic-server/utils"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
import (
|
||||
"mime"
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
type MediaFolder struct {
|
||||
ID string
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
type Playlist struct {
|
||||
ID string
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
const (
|
||||
PropLastScan = "LastScan"
|
|
@ -1,4 +1,4 @@
|
|||
package domain
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type Album struct {
|
||||
|
@ -33,33 +33,33 @@ type albumRepository struct {
|
|||
searchableRepository
|
||||
}
|
||||
|
||||
func NewAlbumRepository() domain.AlbumRepository {
|
||||
func NewAlbumRepository() model.AlbumRepository {
|
||||
r := &albumRepository{}
|
||||
r.tableName = "album"
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *albumRepository) Put(a *domain.Album) error {
|
||||
func (r *albumRepository) Put(a *model.Album) error {
|
||||
ta := Album(*a)
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
return r.put(o, a.ID, a.Name, &ta)
|
||||
})
|
||||
}
|
||||
|
||||
func (r *albumRepository) Get(id string) (*domain.Album, error) {
|
||||
func (r *albumRepository) Get(id string) (*model.Album, error) {
|
||||
ta := Album{ID: id}
|
||||
err := Db().Read(&ta)
|
||||
if err == orm.ErrNoRows {
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a := domain.Album(ta)
|
||||
a := model.Album(ta)
|
||||
return &a, err
|
||||
}
|
||||
|
||||
func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
|
||||
func (r *albumRepository) FindByArtist(artistId string) (model.Albums, error) {
|
||||
var albums []Album
|
||||
_, err := r.newQuery(Db()).Filter("artist_id", artistId).OrderBy("year", "name").All(&albums)
|
||||
if err != nil {
|
||||
|
@ -68,7 +68,7 @@ func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
|
|||
return r.toAlbums(albums), nil
|
||||
}
|
||||
|
||||
func (r *albumRepository) GetAll(options ...domain.QueryOptions) (domain.Albums, error) {
|
||||
func (r *albumRepository) GetAll(options ...model.QueryOptions) (model.Albums, error) {
|
||||
var all []Album
|
||||
_, err := r.newQuery(Db(), options...).All(&all)
|
||||
if err != nil {
|
||||
|
@ -77,25 +77,25 @@ func (r *albumRepository) GetAll(options ...domain.QueryOptions) (domain.Albums,
|
|||
return r.toAlbums(all), nil
|
||||
}
|
||||
|
||||
func (r *albumRepository) toAlbums(all []Album) domain.Albums {
|
||||
result := make(domain.Albums, len(all))
|
||||
func (r *albumRepository) toAlbums(all []Album) model.Albums {
|
||||
result := make(model.Albums, len(all))
|
||||
for i, a := range all {
|
||||
result[i] = domain.Album(a)
|
||||
result[i] = model.Album(a)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// TODO Remove []string from return
|
||||
func (r *albumRepository) PurgeInactive(activeList domain.Albums) error {
|
||||
func (r *albumRepository) PurgeInactive(activeList model.Albums) error {
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
_, err := r.purgeInactive(o, activeList, func(item interface{}) string {
|
||||
return item.(domain.Album).ID
|
||||
return item.(model.Album).ID
|
||||
})
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (r *albumRepository) GetStarred(options ...domain.QueryOptions) (domain.Albums, error) {
|
||||
func (r *albumRepository) GetStarred(options ...model.QueryOptions) (model.Albums, error) {
|
||||
var starred []Album
|
||||
_, err := r.newQuery(Db(), options...).Filter("starred", true).All(&starred)
|
||||
if err != nil {
|
||||
|
@ -104,7 +104,7 @@ func (r *albumRepository) GetStarred(options ...domain.QueryOptions) (domain.Alb
|
|||
return r.toAlbums(starred), nil
|
||||
}
|
||||
|
||||
func (r *albumRepository) Search(q string, offset int, size int) (domain.Albums, error) {
|
||||
func (r *albumRepository) Search(q string, offset int, size int) (model.Albums, error) {
|
||||
if len(q) <= 2 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -117,5 +117,5 @@ func (r *albumRepository) Search(q string, offset int, size int) (domain.Albums,
|
|||
return r.toAlbums(results), nil
|
||||
}
|
||||
|
||||
var _ domain.AlbumRepository = (*albumRepository)(nil)
|
||||
var _ = domain.Album(Album{})
|
||||
var _ model.AlbumRepository = (*albumRepository)(nil)
|
||||
var _ = model.Album(Album{})
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("AlbumRepository", func() {
|
||||
var repo domain.AlbumRepository
|
||||
var repo model.AlbumRepository
|
||||
|
||||
BeforeEach(func() {
|
||||
repo = NewAlbumRepository()
|
||||
|
@ -19,7 +19,7 @@ var _ = Describe("AlbumRepository", func() {
|
|||
})
|
||||
|
||||
It("returns all records sorted", func() {
|
||||
Expect(repo.GetAll(domain.QueryOptions{SortBy: "Name"})).To(Equal(domain.Albums{
|
||||
Expect(repo.GetAll(model.QueryOptions{SortBy: "Name"})).To(Equal(model.Albums{
|
||||
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
|
||||
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
|
||||
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
|
||||
|
@ -27,7 +27,7 @@ var _ = Describe("AlbumRepository", func() {
|
|||
})
|
||||
|
||||
It("returns all records sorted desc", func() {
|
||||
Expect(repo.GetAll(domain.QueryOptions{SortBy: "Name", Desc: true})).To(Equal(domain.Albums{
|
||||
Expect(repo.GetAll(model.QueryOptions{SortBy: "Name", Desc: true})).To(Equal(model.Albums{
|
||||
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
|
||||
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
|
||||
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
|
||||
|
@ -35,7 +35,7 @@ var _ = Describe("AlbumRepository", func() {
|
|||
})
|
||||
|
||||
It("paginates the result", func() {
|
||||
Expect(repo.GetAll(domain.QueryOptions{Offset: 1, Size: 1})).To(Equal(domain.Albums{
|
||||
Expect(repo.GetAll(model.QueryOptions{Offset: 1, Size: 1})).To(Equal(model.Albums{
|
||||
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
|
||||
}))
|
||||
})
|
||||
|
@ -49,7 +49,7 @@ var _ = Describe("AlbumRepository", func() {
|
|||
|
||||
Describe("GetStarred", func() {
|
||||
It("returns all starred records", func() {
|
||||
Expect(repo.GetStarred(domain.QueryOptions{})).To(Equal(domain.Albums{
|
||||
Expect(repo.GetStarred(model.QueryOptions{})).To(Equal(model.Albums{
|
||||
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
|
||||
}))
|
||||
})
|
||||
|
@ -57,7 +57,7 @@ var _ = Describe("AlbumRepository", func() {
|
|||
|
||||
Describe("FindByArtist", func() {
|
||||
It("returns all records from a given ArtistID", func() {
|
||||
Expect(repo.FindByArtist("1")).To(Equal(domain.Albums{
|
||||
Expect(repo.FindByArtist("1")).To(Equal(model.Albums{
|
||||
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
|
||||
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
|
||||
}))
|
||||
|
|
|
@ -2,7 +2,7 @@ package persistence
|
|||
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
// This is used to isolate Storm's struct tags from the domain, to keep it agnostic of persistence details
|
||||
|
@ -16,42 +16,42 @@ type artistRepository struct {
|
|||
searchableRepository
|
||||
}
|
||||
|
||||
func NewArtistRepository() domain.ArtistRepository {
|
||||
func NewArtistRepository() model.ArtistRepository {
|
||||
r := &artistRepository{}
|
||||
r.tableName = "artist"
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *artistRepository) Put(a *domain.Artist) error {
|
||||
func (r *artistRepository) Put(a *model.Artist) error {
|
||||
ta := Artist(*a)
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
return r.put(o, a.ID, a.Name, &ta)
|
||||
})
|
||||
}
|
||||
|
||||
func (r *artistRepository) Get(id string) (*domain.Artist, error) {
|
||||
func (r *artistRepository) Get(id string) (*model.Artist, error) {
|
||||
ta := Artist{ID: id}
|
||||
err := Db().Read(&ta)
|
||||
if err == orm.ErrNoRows {
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a := domain.Artist(ta)
|
||||
a := model.Artist(ta)
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
func (r *artistRepository) PurgeInactive(activeList domain.Artists) error {
|
||||
func (r *artistRepository) PurgeInactive(activeList model.Artists) error {
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
_, err := r.purgeInactive(o, activeList, func(item interface{}) string {
|
||||
return item.(domain.Artist).ID
|
||||
return item.(model.Artist).ID
|
||||
})
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (r *artistRepository) Search(q string, offset int, size int) (domain.Artists, error) {
|
||||
func (r *artistRepository) Search(q string, offset int, size int) (model.Artists, error) {
|
||||
if len(q) <= 2 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -65,13 +65,13 @@ func (r *artistRepository) Search(q string, offset int, size int) (domain.Artist
|
|||
return r.toArtists(results), nil
|
||||
}
|
||||
|
||||
func (r *artistRepository) toArtists(all []Artist) domain.Artists {
|
||||
result := make(domain.Artists, len(all))
|
||||
func (r *artistRepository) toArtists(all []Artist) model.Artists {
|
||||
result := make(model.Artists, len(all))
|
||||
for i, a := range all {
|
||||
result[i] = domain.Artist(a)
|
||||
result[i] = model.Artist(a)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
var _ domain.ArtistRepository = (*artistRepository)(nil)
|
||||
var _ = domain.Artist(Artist{})
|
||||
var _ model.ArtistRepository = (*artistRepository)(nil)
|
||||
var _ = model.Artist(Artist{})
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("ArtistRepository", func() {
|
||||
var repo domain.ArtistRepository
|
||||
var repo model.ArtistRepository
|
||||
|
||||
BeforeEach(func() {
|
||||
repo = NewArtistRepository()
|
||||
})
|
||||
|
||||
It("saves and retrieves data", func() {
|
||||
Expect(repo.Get("1")).To(Equal(&domain.Artist{ID: "1", Name: "Saara Saara", AlbumCount: 2}))
|
||||
Expect(repo.Get("1")).To(Equal(&model.Artist{ID: "1", Name: "Saara Saara", AlbumCount: 2}))
|
||||
})
|
||||
|
||||
It("overrides data if ID already exists", func() {
|
||||
Expect(repo.Put(&domain.Artist{ID: "1", Name: "Saara Saara is The Best!", AlbumCount: 3})).To(BeNil())
|
||||
Expect(repo.Get("1")).To(Equal(&domain.Artist{ID: "1", Name: "Saara Saara is The Best!", AlbumCount: 3}))
|
||||
Expect(repo.Put(&model.Artist{ID: "1", Name: "Saara Saara is The Best!", AlbumCount: 3})).To(BeNil())
|
||||
Expect(repo.Get("1")).To(Equal(&model.Artist{ID: "1", Name: "Saara Saara is The Best!", AlbumCount: 3}))
|
||||
})
|
||||
|
||||
It("returns ErrNotFound when the ID does not exist", func() {
|
||||
_, err := repo.Get("999")
|
||||
Expect(err).To(MatchError(domain.ErrNotFound))
|
||||
Expect(err).To(MatchError(model.ErrNotFound))
|
||||
})
|
||||
|
||||
Describe("PurgeInactive", func() {
|
||||
|
@ -35,7 +35,7 @@ var _ = Describe("ArtistRepository", func() {
|
|||
})
|
||||
|
||||
It("purges inactive records", func() {
|
||||
active := domain.Artists{{ID: "1"}, {ID: "3"}}
|
||||
active := model.Artists{{ID: "1"}, {ID: "3"}}
|
||||
|
||||
Expect(repo.PurgeInactive(active)).To(BeNil())
|
||||
|
||||
|
@ -44,7 +44,7 @@ var _ = Describe("ArtistRepository", func() {
|
|||
})
|
||||
|
||||
It("doesn't delete anything if all is active", func() {
|
||||
active := domain.Artists{{ID: "1"}, {ID: "2"}, {ID: "3"}}
|
||||
active := model.Artists{{ID: "1"}, {ID: "2"}, {ID: "3"}}
|
||||
|
||||
Expect(repo.PurgeInactive(active)).To(BeNil())
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ package persistence
|
|||
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type checkSumRepository struct {
|
||||
|
@ -17,7 +17,7 @@ type Checksum struct {
|
|||
Sum string
|
||||
}
|
||||
|
||||
func NewCheckSumRepository() domain.CheckSumRepository {
|
||||
func NewCheckSumRepository() model.CheckSumRepository {
|
||||
r := &checkSumRepository{}
|
||||
return r
|
||||
}
|
||||
|
@ -76,4 +76,4 @@ func (r *checkSumRepository) SetData(newSums map[string]string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var _ domain.CheckSumRepository = (*checkSumRepository)(nil)
|
||||
var _ model.CheckSumRepository = (*checkSumRepository)(nil)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("ChecksumRepository", func() {
|
||||
var repo domain.CheckSumRepository
|
||||
var repo model.CheckSumRepository
|
||||
|
||||
BeforeEach(func() {
|
||||
Db().Delete(&Checksum{ID: checkSumId})
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"sort"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type ArtistInfo struct {
|
||||
|
@ -19,7 +19,7 @@ type artistIndexRepository struct {
|
|||
sqlRepository
|
||||
}
|
||||
|
||||
func NewArtistIndexRepository() domain.ArtistIndexRepository {
|
||||
func NewArtistIndexRepository() model.ArtistIndexRepository {
|
||||
r := &artistIndexRepository{}
|
||||
r.tableName = "artist_info"
|
||||
return r
|
||||
|
@ -34,7 +34,7 @@ func (r *artistIndexRepository) CountAll() (int64, error) {
|
|||
return count.Count, nil
|
||||
}
|
||||
|
||||
func (r *artistIndexRepository) Put(idx *domain.ArtistIndex) error {
|
||||
func (r *artistIndexRepository) Put(idx *model.ArtistIndex) error {
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
_, err := r.newQuery(o).Filter("idx", idx.ID).Delete()
|
||||
if err != nil {
|
||||
|
@ -56,17 +56,17 @@ func (r *artistIndexRepository) Put(idx *domain.ArtistIndex) error {
|
|||
})
|
||||
}
|
||||
|
||||
func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
|
||||
func (r *artistIndexRepository) Get(id string) (*model.ArtistIndex, error) {
|
||||
var ais []ArtistInfo
|
||||
_, err := r.newQuery(Db()).Filter("idx", id).All(&ais)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
idx := &domain.ArtistIndex{ID: id}
|
||||
idx.Artists = make([]domain.ArtistInfo, len(ais))
|
||||
idx := &model.ArtistIndex{ID: id}
|
||||
idx.Artists = make([]model.ArtistInfo, len(ais))
|
||||
for i, a := range ais {
|
||||
idx.Artists[i] = domain.ArtistInfo{
|
||||
idx.Artists[i] = model.ArtistInfo{
|
||||
ArtistID: a.ArtistID,
|
||||
Artist: a.Artist,
|
||||
AlbumCount: a.AlbumCount,
|
||||
|
@ -75,27 +75,27 @@ func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
|
|||
return idx, err
|
||||
}
|
||||
|
||||
func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
||||
func (r *artistIndexRepository) GetAll() (model.ArtistIndexes, error) {
|
||||
var all []ArtistInfo
|
||||
_, err := r.newQuery(Db()).OrderBy("idx", "artist").All(&all)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fullIdx := make(map[string]*domain.ArtistIndex)
|
||||
fullIdx := make(map[string]*model.ArtistIndex)
|
||||
for _, a := range all {
|
||||
idx, ok := fullIdx[a.Idx]
|
||||
if !ok {
|
||||
idx = &domain.ArtistIndex{ID: a.Idx}
|
||||
idx = &model.ArtistIndex{ID: a.Idx}
|
||||
fullIdx[a.Idx] = idx
|
||||
}
|
||||
idx.Artists = append(idx.Artists, domain.ArtistInfo{
|
||||
idx.Artists = append(idx.Artists, model.ArtistInfo{
|
||||
ArtistID: a.ArtistID,
|
||||
Artist: a.Artist,
|
||||
AlbumCount: a.AlbumCount,
|
||||
})
|
||||
}
|
||||
var result domain.ArtistIndexes
|
||||
var result model.ArtistIndexes
|
||||
for _, idx := range fullIdx {
|
||||
result = append(result, *idx)
|
||||
}
|
||||
|
@ -105,4 +105,4 @@ func (r *artistIndexRepository) GetAll() (domain.ArtistIndexes, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
var _ domain.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
||||
var _ model.ArtistIndexRepository = (*artistIndexRepository)(nil)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Artist Index", func() {
|
||||
var repo domain.ArtistIndexRepository
|
||||
var repo model.ArtistIndexRepository
|
||||
|
||||
BeforeEach(func() {
|
||||
repo = NewArtistIndexRepository()
|
||||
|
@ -18,16 +18,16 @@ var _ = Describe("Artist Index", func() {
|
|||
})
|
||||
|
||||
It("successfully persists data", func() {
|
||||
idx1 := domain.ArtistIndex{
|
||||
idx1 := model.ArtistIndex{
|
||||
ID: "D",
|
||||
Artists: domain.ArtistInfos{
|
||||
Artists: model.ArtistInfos{
|
||||
{ArtistID: "4", Artist: "Doobie Brothers", AlbumCount: 2},
|
||||
{ArtistID: "3", Artist: "The Doors", AlbumCount: 5},
|
||||
},
|
||||
}
|
||||
idx2 := domain.ArtistIndex{
|
||||
idx2 := model.ArtistIndex{
|
||||
ID: "S",
|
||||
Artists: domain.ArtistInfos{
|
||||
Artists: model.ArtistInfos{
|
||||
{ArtistID: "1", Artist: "Saara Saara", AlbumCount: 3},
|
||||
{ArtistID: "2", Artist: "Seu Jorge", AlbumCount: 1},
|
||||
},
|
||||
|
@ -37,7 +37,7 @@ var _ = Describe("Artist Index", func() {
|
|||
Expect(repo.Put(&idx2)).To(BeNil())
|
||||
Expect(repo.Get("D")).To(Equal(&idx1))
|
||||
Expect(repo.Get("S")).To(Equal(&idx2))
|
||||
Expect(repo.GetAll()).To(Equal(domain.ArtistIndexes{idx1, idx2}))
|
||||
Expect(repo.GetAll()).To(Equal(model.ArtistIndexes{idx1, idx2}))
|
||||
Expect(repo.CountAll()).To(Equal(int64(2)))
|
||||
Expect(repo.DeleteAll()).To(BeNil())
|
||||
Expect(repo.CountAll()).To(Equal(int64(0)))
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type MediaFile struct {
|
||||
|
@ -39,41 +39,41 @@ type mediaFileRepository struct {
|
|||
searchableRepository
|
||||
}
|
||||
|
||||
func NewMediaFileRepository() domain.MediaFileRepository {
|
||||
func NewMediaFileRepository() model.MediaFileRepository {
|
||||
r := &mediaFileRepository{}
|
||||
r.tableName = "media_file"
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) Put(m *domain.MediaFile) error {
|
||||
func (r *mediaFileRepository) Put(m *model.MediaFile) error {
|
||||
tm := MediaFile(*m)
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
return r.put(o, m.ID, m.Title, &tm)
|
||||
})
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
|
||||
func (r *mediaFileRepository) Get(id string) (*model.MediaFile, error) {
|
||||
tm := MediaFile{ID: id}
|
||||
err := Db().Read(&tm)
|
||||
if err == orm.ErrNoRows {
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a := domain.MediaFile(tm)
|
||||
a := model.MediaFile(tm)
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) toMediaFiles(all []MediaFile) domain.MediaFiles {
|
||||
result := make(domain.MediaFiles, len(all))
|
||||
func (r *mediaFileRepository) toMediaFiles(all []MediaFile) model.MediaFiles {
|
||||
result := make(model.MediaFiles, len(all))
|
||||
for i, m := range all {
|
||||
result[i] = domain.MediaFile(m)
|
||||
result[i] = model.MediaFile(m)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, error) {
|
||||
func (r *mediaFileRepository) FindByAlbum(albumId string) (model.MediaFiles, error) {
|
||||
var mfs []MediaFile
|
||||
_, err := r.newQuery(Db()).Filter("album_id", albumId).OrderBy("disc_number", "track_number").All(&mfs)
|
||||
if err != nil {
|
||||
|
@ -82,7 +82,7 @@ func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, er
|
|||
return r.toMediaFiles(mfs), nil
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) GetStarred(options ...domain.QueryOptions) (domain.MediaFiles, error) {
|
||||
func (r *mediaFileRepository) GetStarred(options ...model.QueryOptions) (model.MediaFiles, error) {
|
||||
var starred []MediaFile
|
||||
_, err := r.newQuery(Db(), options...).Filter("starred", true).All(&starred)
|
||||
if err != nil {
|
||||
|
@ -91,16 +91,16 @@ func (r *mediaFileRepository) GetStarred(options ...domain.QueryOptions) (domain
|
|||
return r.toMediaFiles(starred), nil
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) PurgeInactive(activeList domain.MediaFiles) error {
|
||||
func (r *mediaFileRepository) PurgeInactive(activeList model.MediaFiles) error {
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
_, err := r.purgeInactive(o, activeList, func(item interface{}) string {
|
||||
return item.(domain.MediaFile).ID
|
||||
return item.(model.MediaFile).ID
|
||||
})
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) Search(q string, offset int, size int) (domain.MediaFiles, error) {
|
||||
func (r *mediaFileRepository) Search(q string, offset int, size int) (model.MediaFiles, error) {
|
||||
if len(q) <= 2 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -113,5 +113,5 @@ func (r *mediaFileRepository) Search(q string, offset int, size int) (domain.Med
|
|||
return r.toMediaFiles(results), nil
|
||||
}
|
||||
|
||||
var _ domain.MediaFileRepository = (*mediaFileRepository)(nil)
|
||||
var _ = domain.MediaFile(MediaFile{})
|
||||
var _ model.MediaFileRepository = (*mediaFileRepository)(nil)
|
||||
var _ = model.MediaFile(MediaFile{})
|
||||
|
|
|
@ -2,22 +2,22 @@ package persistence
|
|||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type mediaFolderRepository struct {
|
||||
domain.MediaFolderRepository
|
||||
model.MediaFolderRepository
|
||||
}
|
||||
|
||||
func NewMediaFolderRepository() domain.MediaFolderRepository {
|
||||
func NewMediaFolderRepository() model.MediaFolderRepository {
|
||||
return &mediaFolderRepository{}
|
||||
}
|
||||
|
||||
func (*mediaFolderRepository) GetAll() (domain.MediaFolders, error) {
|
||||
mediaFolder := domain.MediaFolder{ID: "0", Name: "iTunes Library", Path: conf.Sonic.MusicFolder}
|
||||
result := make(domain.MediaFolders, 1)
|
||||
func (*mediaFolderRepository) GetAll() (model.MediaFolders, error) {
|
||||
mediaFolder := model.MediaFolder{ID: "0", Name: "iTunes Library", Path: conf.Sonic.MusicFolder}
|
||||
result := make(model.MediaFolders, 1)
|
||||
result[0] = mediaFolder
|
||||
return result, nil
|
||||
}
|
||||
|
||||
var _ domain.MediaFolderRepository = (*mediaFolderRepository)(nil)
|
||||
var _ model.MediaFolderRepository = (*mediaFolderRepository)(nil)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
func CreateMockAlbumRepo() *MockAlbum {
|
||||
|
@ -13,11 +13,11 @@ func CreateMockAlbumRepo() *MockAlbum {
|
|||
}
|
||||
|
||||
type MockAlbum struct {
|
||||
domain.AlbumRepository
|
||||
data map[string]*domain.Album
|
||||
all domain.Albums
|
||||
model.AlbumRepository
|
||||
data map[string]*model.Album
|
||||
all model.Albums
|
||||
err bool
|
||||
Options domain.QueryOptions
|
||||
Options model.QueryOptions
|
||||
}
|
||||
|
||||
func (m *MockAlbum) SetError(err bool) {
|
||||
|
@ -25,8 +25,8 @@ func (m *MockAlbum) SetError(err bool) {
|
|||
}
|
||||
|
||||
func (m *MockAlbum) SetData(j string, size int) {
|
||||
m.data = make(map[string]*domain.Album)
|
||||
m.all = make(domain.Albums, size)
|
||||
m.data = make(map[string]*model.Album)
|
||||
m.all = make(model.Albums, size)
|
||||
err := json.Unmarshal([]byte(j), &m.all)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ", err)
|
||||
|
@ -41,17 +41,17 @@ func (m *MockAlbum) Exists(id string) (bool, error) {
|
|||
return found, nil
|
||||
}
|
||||
|
||||
func (m *MockAlbum) Get(id string) (*domain.Album, error) {
|
||||
func (m *MockAlbum) Get(id string) (*model.Album, error) {
|
||||
if m.err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
return d, nil
|
||||
}
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *MockAlbum) GetAll(qo ...domain.QueryOptions) (domain.Albums, error) {
|
||||
func (m *MockAlbum) GetAll(qo ...model.QueryOptions) (model.Albums, error) {
|
||||
if len(qo) > 0 {
|
||||
m.Options = qo[0]
|
||||
}
|
||||
|
@ -61,11 +61,11 @@ func (m *MockAlbum) GetAll(qo ...domain.QueryOptions) (domain.Albums, error) {
|
|||
return m.all, nil
|
||||
}
|
||||
|
||||
func (m *MockAlbum) FindByArtist(artistId string) (domain.Albums, error) {
|
||||
func (m *MockAlbum) FindByArtist(artistId string) (model.Albums, error) {
|
||||
if m.err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
var res = make(domain.Albums, len(m.data))
|
||||
var res = make(model.Albums, len(m.data))
|
||||
i := 0
|
||||
for _, a := range m.data {
|
||||
if a.ArtistID == artistId {
|
||||
|
@ -77,4 +77,4 @@ func (m *MockAlbum) FindByArtist(artistId string) (domain.Albums, error) {
|
|||
return res, nil
|
||||
}
|
||||
|
||||
var _ domain.AlbumRepository = (*MockAlbum)(nil)
|
||||
var _ model.AlbumRepository = (*MockAlbum)(nil)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
func CreateMockArtistRepo() *MockArtist {
|
||||
|
@ -13,8 +13,8 @@ func CreateMockArtistRepo() *MockArtist {
|
|||
}
|
||||
|
||||
type MockArtist struct {
|
||||
domain.ArtistRepository
|
||||
data map[string]*domain.Artist
|
||||
model.ArtistRepository
|
||||
data map[string]*model.Artist
|
||||
err bool
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@ func (m *MockArtist) SetError(err bool) {
|
|||
}
|
||||
|
||||
func (m *MockArtist) SetData(j string, size int) {
|
||||
m.data = make(map[string]*domain.Artist)
|
||||
var l = make([]domain.Artist, size)
|
||||
m.data = make(map[string]*model.Artist)
|
||||
var l = make([]model.Artist, size)
|
||||
err := json.Unmarshal([]byte(j), &l)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ", err)
|
||||
|
@ -39,14 +39,14 @@ func (m *MockArtist) Exists(id string) (bool, error) {
|
|||
return found, nil
|
||||
}
|
||||
|
||||
func (m *MockArtist) Get(id string) (*domain.Artist, error) {
|
||||
func (m *MockArtist) Get(id string) (*model.Artist, error) {
|
||||
if m.err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
return d, nil
|
||||
}
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
|
||||
var _ domain.ArtistRepository = (*MockArtist)(nil)
|
||||
var _ model.ArtistRepository = (*MockArtist)(nil)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
func CreateMockArtistIndexRepo() *MockArtistIndex {
|
||||
|
@ -13,8 +13,8 @@ func CreateMockArtistIndexRepo() *MockArtistIndex {
|
|||
}
|
||||
|
||||
type MockArtistIndex struct {
|
||||
domain.ArtistIndexRepository
|
||||
data domain.ArtistIndexes
|
||||
model.ArtistIndexRepository
|
||||
data model.ArtistIndexes
|
||||
err bool
|
||||
}
|
||||
|
||||
|
@ -23,18 +23,18 @@ func (m *MockArtistIndex) SetError(err bool) {
|
|||
}
|
||||
|
||||
func (m *MockArtistIndex) SetData(j string, length int) {
|
||||
m.data = make(domain.ArtistIndexes, length)
|
||||
m.data = make(model.ArtistIndexes, length)
|
||||
err := json.Unmarshal([]byte(j), &m.data)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockArtistIndex) GetAll() (domain.ArtistIndexes, error) {
|
||||
func (m *MockArtistIndex) GetAll() (model.ArtistIndexes, error) {
|
||||
if m.err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
return m.data, nil
|
||||
}
|
||||
|
||||
var _ domain.ArtistIndexRepository = (*MockArtistIndex)(nil)
|
||||
var _ model.ArtistIndexRepository = (*MockArtistIndex)(nil)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
func CreateMockMediaFileRepo() *MockMediaFile {
|
||||
|
@ -13,8 +13,8 @@ func CreateMockMediaFileRepo() *MockMediaFile {
|
|||
}
|
||||
|
||||
type MockMediaFile struct {
|
||||
domain.MediaFileRepository
|
||||
data map[string]domain.MediaFile
|
||||
model.MediaFileRepository
|
||||
data map[string]model.MediaFile
|
||||
err bool
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@ func (m *MockMediaFile) SetError(err bool) {
|
|||
}
|
||||
|
||||
func (m *MockMediaFile) SetData(j string, size int) {
|
||||
m.data = make(map[string]domain.MediaFile)
|
||||
var l = make(domain.MediaFiles, size)
|
||||
m.data = make(map[string]model.MediaFile)
|
||||
var l = make(model.MediaFiles, size)
|
||||
err := json.Unmarshal([]byte(j), &l)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ", err)
|
||||
|
@ -42,21 +42,21 @@ func (m *MockMediaFile) Exists(id string) (bool, error) {
|
|||
return found, nil
|
||||
}
|
||||
|
||||
func (m *MockMediaFile) Get(id string) (*domain.MediaFile, error) {
|
||||
func (m *MockMediaFile) Get(id string) (*model.MediaFile, error) {
|
||||
if m.err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
return &d, nil
|
||||
}
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *MockMediaFile) FindByAlbum(artistId string) (domain.MediaFiles, error) {
|
||||
func (m *MockMediaFile) FindByAlbum(artistId string) (model.MediaFiles, error) {
|
||||
if m.err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
var res = make(domain.MediaFiles, len(m.data))
|
||||
var res = make(model.MediaFiles, len(m.data))
|
||||
i := 0
|
||||
for _, a := range m.data {
|
||||
if a.AlbumID == artistId {
|
||||
|
@ -68,4 +68,4 @@ func (m *MockMediaFile) FindByAlbum(artistId string) (domain.MediaFiles, error)
|
|||
return res, nil
|
||||
}
|
||||
|
||||
var _ domain.MediaFileRepository = (*MockMediaFile)(nil)
|
||||
var _ model.MediaFileRepository = (*MockMediaFile)(nil)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"container/list"
|
||||
"sync"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
var playerMap = sync.Map{}
|
||||
|
@ -12,7 +12,7 @@ var playerMap = sync.Map{}
|
|||
type nowPlayingRepository struct{}
|
||||
|
||||
// TODO Make it persistent
|
||||
func NewNowPlayingRepository() domain.NowPlayingRepository {
|
||||
func NewNowPlayingRepository() model.NowPlayingRepository {
|
||||
r := &nowPlayingRepository{}
|
||||
return r
|
||||
}
|
||||
|
@ -22,38 +22,38 @@ func (r *nowPlayingRepository) getList(id int) *list.List {
|
|||
return l.(*list.List)
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Enqueue(info *domain.NowPlayingInfo) error {
|
||||
func (r *nowPlayingRepository) Enqueue(info *model.NowPlayingInfo) error {
|
||||
l := r.getList(info.PlayerId)
|
||||
l.PushFront(info)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Dequeue(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (r *nowPlayingRepository) Dequeue(playerId int) (*model.NowPlayingInfo, error) {
|
||||
l := r.getList(playerId)
|
||||
e := l.Back()
|
||||
if e == nil {
|
||||
return nil, nil
|
||||
}
|
||||
l.Remove(e)
|
||||
return e.Value.(*domain.NowPlayingInfo), nil
|
||||
return e.Value.(*model.NowPlayingInfo), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Head(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (r *nowPlayingRepository) Head(playerId int) (*model.NowPlayingInfo, error) {
|
||||
l := r.getList(playerId)
|
||||
e := l.Front()
|
||||
if e == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return e.Value.(*domain.NowPlayingInfo), nil
|
||||
return e.Value.(*model.NowPlayingInfo), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Tail(playerId int) (*domain.NowPlayingInfo, error) {
|
||||
func (r *nowPlayingRepository) Tail(playerId int) (*model.NowPlayingInfo, error) {
|
||||
l := r.getList(playerId)
|
||||
e := l.Back()
|
||||
if e == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return e.Value.(*domain.NowPlayingInfo), nil
|
||||
return e.Value.(*model.NowPlayingInfo), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) Count(playerId int) (int64, error) {
|
||||
|
@ -61,15 +61,15 @@ func (r *nowPlayingRepository) Count(playerId int) (int64, error) {
|
|||
return int64(l.Len()), nil
|
||||
}
|
||||
|
||||
func (r *nowPlayingRepository) GetAll() ([]*domain.NowPlayingInfo, error) {
|
||||
var all []*domain.NowPlayingInfo
|
||||
func (r *nowPlayingRepository) GetAll() ([]*model.NowPlayingInfo, error) {
|
||||
var all []*model.NowPlayingInfo
|
||||
playerMap.Range(func(playerId, l interface{}) bool {
|
||||
ll := l.(*list.List)
|
||||
e := ll.Front()
|
||||
all = append(all, e.Value.(*domain.NowPlayingInfo))
|
||||
all = append(all, e.Value.(*model.NowPlayingInfo))
|
||||
return true
|
||||
})
|
||||
return all, nil
|
||||
}
|
||||
|
||||
var _ domain.NowPlayingRepository = (*nowPlayingRepository)(nil)
|
||||
var _ model.NowPlayingRepository = (*nowPlayingRepository)(nil)
|
||||
|
|
|
@ -3,13 +3,13 @@ package persistence
|
|||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("NowPlayingRepository", func() {
|
||||
var repo domain.NowPlayingRepository
|
||||
var repo model.NowPlayingRepository
|
||||
|
||||
BeforeEach(func() {
|
||||
playerMap = sync.Map{}
|
||||
|
@ -17,26 +17,26 @@ var _ = Describe("NowPlayingRepository", func() {
|
|||
})
|
||||
|
||||
It("enqueues and dequeues records", func() {
|
||||
Expect(repo.Enqueue(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "BBB"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&model.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&model.NowPlayingInfo{PlayerId: 1, TrackID: "BBB"})).To(BeNil())
|
||||
|
||||
Expect(repo.Tail(1)).To(Equal(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
|
||||
Expect(repo.Head(1)).To(Equal(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "BBB"}))
|
||||
Expect(repo.Tail(1)).To(Equal(&model.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
|
||||
Expect(repo.Head(1)).To(Equal(&model.NowPlayingInfo{PlayerId: 1, TrackID: "BBB"}))
|
||||
|
||||
Expect(repo.Count(1)).To(Equal(int64(2)))
|
||||
|
||||
Expect(repo.Dequeue(1)).To(Equal(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
|
||||
Expect(repo.Dequeue(1)).To(Equal(&model.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
|
||||
Expect(repo.Count(1)).To(Equal(int64(1)))
|
||||
})
|
||||
|
||||
It("handles multiple players", func() {
|
||||
Expect(repo.Enqueue(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "BBB"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&model.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&model.NowPlayingInfo{PlayerId: 1, TrackID: "BBB"})).To(BeNil())
|
||||
|
||||
Expect(repo.Enqueue(&domain.NowPlayingInfo{PlayerId: 2, TrackID: "CCC"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&domain.NowPlayingInfo{PlayerId: 2, TrackID: "DDD"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&model.NowPlayingInfo{PlayerId: 2, TrackID: "CCC"})).To(BeNil())
|
||||
Expect(repo.Enqueue(&model.NowPlayingInfo{PlayerId: 2, TrackID: "DDD"})).To(BeNil())
|
||||
|
||||
Expect(repo.GetAll()).To(ConsistOf([]*domain.NowPlayingInfo{
|
||||
Expect(repo.GetAll()).To(ConsistOf([]*model.NowPlayingInfo{
|
||||
{PlayerId: 1, TrackID: "BBB"},
|
||||
{PlayerId: 2, TrackID: "DDD"},
|
||||
}))
|
||||
|
@ -44,7 +44,7 @@ var _ = Describe("NowPlayingRepository", func() {
|
|||
Expect(repo.Count(2)).To(Equal(int64(2)))
|
||||
Expect(repo.Count(2)).To(Equal(int64(2)))
|
||||
|
||||
Expect(repo.Tail(1)).To(Equal(&domain.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
|
||||
Expect(repo.Head(2)).To(Equal(&domain.NowPlayingInfo{PlayerId: 2, TrackID: "DDD"}))
|
||||
Expect(repo.Tail(1)).To(Equal(&model.NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
|
||||
Expect(repo.Head(2)).To(Equal(&model.NowPlayingInfo{PlayerId: 2, TrackID: "DDD"}))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -16,12 +16,12 @@ func TestPersistence(t *testing.T) {
|
|||
RunSpecs(t, "Persistence Suite")
|
||||
}
|
||||
|
||||
var testAlbums = domain.Albums{
|
||||
var testAlbums = model.Albums{
|
||||
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
|
||||
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
|
||||
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
|
||||
}
|
||||
var testArtists = domain.Artists{
|
||||
var testArtists = model.Artists{
|
||||
{ID: "1", Name: "Saara Saara", AlbumCount: 2},
|
||||
{ID: "2", Name: "Kraftwerk"},
|
||||
{ID: "3", Name: "The Beatles"},
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type Playlist struct {
|
||||
|
@ -22,24 +22,24 @@ type playlistRepository struct {
|
|||
sqlRepository
|
||||
}
|
||||
|
||||
func NewPlaylistRepository() domain.PlaylistRepository {
|
||||
func NewPlaylistRepository() model.PlaylistRepository {
|
||||
r := &playlistRepository{}
|
||||
r.tableName = "playlist"
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *playlistRepository) Put(p *domain.Playlist) error {
|
||||
func (r *playlistRepository) Put(p *model.Playlist) error {
|
||||
tp := r.fromDomain(p)
|
||||
return withTx(func(o orm.Ormer) error {
|
||||
return r.put(o, p.ID, &tp)
|
||||
})
|
||||
}
|
||||
|
||||
func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
|
||||
func (r *playlistRepository) Get(id string) (*model.Playlist, error) {
|
||||
tp := &Playlist{ID: id}
|
||||
err := Db().Read(tp)
|
||||
if err == orm.ErrNoRows {
|
||||
return nil, domain.ErrNotFound
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -48,7 +48,7 @@ func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
|
|||
return &a, err
|
||||
}
|
||||
|
||||
func (r *playlistRepository) GetAll(options ...domain.QueryOptions) (domain.Playlists, error) {
|
||||
func (r *playlistRepository) GetAll(options ...model.QueryOptions) (model.Playlists, error) {
|
||||
var all []Playlist
|
||||
_, err := r.newQuery(Db(), options...).All(&all)
|
||||
if err != nil {
|
||||
|
@ -57,25 +57,25 @@ func (r *playlistRepository) GetAll(options ...domain.QueryOptions) (domain.Play
|
|||
return r.toPlaylists(all)
|
||||
}
|
||||
|
||||
func (r *playlistRepository) toPlaylists(all []Playlist) (domain.Playlists, error) {
|
||||
result := make(domain.Playlists, len(all))
|
||||
func (r *playlistRepository) toPlaylists(all []Playlist) (model.Playlists, error) {
|
||||
result := make(model.Playlists, len(all))
|
||||
for i, p := range all {
|
||||
result[i] = r.toDomain(&p)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *playlistRepository) PurgeInactive(activeList domain.Playlists) ([]string, error) {
|
||||
func (r *playlistRepository) PurgeInactive(activeList model.Playlists) ([]string, error) {
|
||||
return nil, withTx(func(o orm.Ormer) error {
|
||||
_, err := r.purgeInactive(o, activeList, func(item interface{}) string {
|
||||
return item.(domain.Playlist).ID
|
||||
return item.(model.Playlist).ID
|
||||
})
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (r *playlistRepository) toDomain(p *Playlist) domain.Playlist {
|
||||
return domain.Playlist{
|
||||
func (r *playlistRepository) toDomain(p *Playlist) model.Playlist {
|
||||
return model.Playlist{
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
Comment: p.Comment,
|
||||
|
@ -87,7 +87,7 @@ func (r *playlistRepository) toDomain(p *Playlist) domain.Playlist {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *playlistRepository) fromDomain(p *domain.Playlist) Playlist {
|
||||
func (r *playlistRepository) fromDomain(p *model.Playlist) Playlist {
|
||||
return Playlist{
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
|
@ -100,4 +100,4 @@ func (r *playlistRepository) fromDomain(p *domain.Playlist) Playlist {
|
|||
}
|
||||
}
|
||||
|
||||
var _ domain.PlaylistRepository = (*playlistRepository)(nil)
|
||||
var _ model.PlaylistRepository = (*playlistRepository)(nil)
|
||||
|
|
|
@ -2,7 +2,7 @@ package persistence
|
|||
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type Property struct {
|
||||
|
@ -14,7 +14,7 @@ type propertyRepository struct {
|
|||
sqlRepository
|
||||
}
|
||||
|
||||
func NewPropertyRepository() domain.PropertyRepository {
|
||||
func NewPropertyRepository() model.PropertyRepository {
|
||||
r := &propertyRepository{}
|
||||
r.tableName = "property"
|
||||
return r
|
||||
|
@ -36,14 +36,14 @@ func (r *propertyRepository) Get(id string) (string, error) {
|
|||
p := &Property{ID: id}
|
||||
err := Db().Read(p)
|
||||
if err == orm.ErrNoRows {
|
||||
return "", domain.ErrNotFound
|
||||
return "", model.ErrNotFound
|
||||
}
|
||||
return p.Value, err
|
||||
}
|
||||
|
||||
func (r *propertyRepository) DefaultGet(id string, defaultValue string) (string, error) {
|
||||
value, err := r.Get(id)
|
||||
if err == domain.ErrNotFound {
|
||||
if err == model.ErrNotFound {
|
||||
return defaultValue, nil
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -52,4 +52,4 @@ func (r *propertyRepository) DefaultGet(id string, defaultValue string) (string,
|
|||
return value, nil
|
||||
}
|
||||
|
||||
var _ domain.PropertyRepository = (*propertyRepository)(nil)
|
||||
var _ model.PropertyRepository = (*propertyRepository)(nil)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package persistence
|
||||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("PropertyRepository", func() {
|
||||
var repo domain.PropertyRepository
|
||||
var repo model.PropertyRepository
|
||||
|
||||
BeforeEach(func() {
|
||||
repo = NewPropertyRepository()
|
||||
|
|
|
@ -2,15 +2,15 @@ package persistence
|
|||
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
)
|
||||
|
||||
type sqlRepository struct {
|
||||
tableName string
|
||||
}
|
||||
|
||||
func (r *sqlRepository) newQuery(o orm.Ormer, options ...domain.QueryOptions) orm.QuerySeter {
|
||||
func (r *sqlRepository) newQuery(o orm.Ormer, options ...model.QueryOptions) orm.QuerySeter {
|
||||
q := o.QueryTable(r.tableName)
|
||||
if len(options) > 0 {
|
||||
opts := options[0]
|
||||
|
|
|
@ -8,35 +8,35 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
)
|
||||
|
||||
type Scanner interface {
|
||||
ScanLibrary(lastModifiedSince time.Time, path string) (int, error)
|
||||
MediaFiles() map[string]*domain.MediaFile
|
||||
Albums() map[string]*domain.Album
|
||||
Artists() map[string]*domain.Artist
|
||||
Playlists() map[string]*domain.Playlist
|
||||
MediaFiles() map[string]*model.MediaFile
|
||||
Albums() map[string]*model.Album
|
||||
Artists() map[string]*model.Artist
|
||||
Playlists() map[string]*model.Playlist
|
||||
}
|
||||
|
||||
type tempIndex map[string]domain.ArtistInfo
|
||||
type tempIndex map[string]model.ArtistInfo
|
||||
|
||||
type Importer struct {
|
||||
scanner Scanner
|
||||
mediaFolder string
|
||||
mfRepo domain.MediaFileRepository
|
||||
albumRepo domain.AlbumRepository
|
||||
artistRepo domain.ArtistRepository
|
||||
idxRepo domain.ArtistIndexRepository
|
||||
plsRepo domain.PlaylistRepository
|
||||
propertyRepo domain.PropertyRepository
|
||||
mfRepo model.MediaFileRepository
|
||||
albumRepo model.AlbumRepository
|
||||
artistRepo model.ArtistRepository
|
||||
idxRepo model.ArtistIndexRepository
|
||||
plsRepo model.PlaylistRepository
|
||||
propertyRepo model.PropertyRepository
|
||||
lastScan time.Time
|
||||
lastCheck time.Time
|
||||
}
|
||||
|
||||
func NewImporter(mediaFolder string, scanner Scanner, mfRepo domain.MediaFileRepository, albumRepo domain.AlbumRepository, artistRepo domain.ArtistRepository, idxRepo domain.ArtistIndexRepository, plsRepo domain.PlaylistRepository, propertyRepo domain.PropertyRepository) *Importer {
|
||||
func NewImporter(mediaFolder string, scanner Scanner, mfRepo model.MediaFileRepository, albumRepo model.AlbumRepository, artistRepo model.ArtistRepository, idxRepo model.ArtistIndexRepository, plsRepo model.PlaylistRepository, propertyRepo model.PropertyRepository) *Importer {
|
||||
return &Importer{
|
||||
scanner: scanner,
|
||||
mediaFolder: mediaFolder,
|
||||
|
@ -103,7 +103,7 @@ func (i *Importer) scan() {
|
|||
}
|
||||
|
||||
func (i *Importer) lastModifiedSince() time.Time {
|
||||
ms, err := i.propertyRepo.Get(domain.PropLastScan)
|
||||
ms, err := i.propertyRepo.Get(model.PropLastScan)
|
||||
if err != nil {
|
||||
log.Warn("Couldn't read LastScan", err)
|
||||
return time.Time{}
|
||||
|
@ -161,15 +161,15 @@ func (i *Importer) importLibrary() (err error) {
|
|||
|
||||
if err == nil {
|
||||
millis := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
i.propertyRepo.Put(domain.PropLastScan, fmt.Sprint(millis))
|
||||
i.propertyRepo.Put(model.PropLastScan, fmt.Sprint(millis))
|
||||
log.Debug("LastScan", "timestamp", millis)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *Importer) importMediaFiles() (domain.MediaFiles, int) {
|
||||
mfs := make(domain.MediaFiles, len(i.scanner.MediaFiles()))
|
||||
func (i *Importer) importMediaFiles() (model.MediaFiles, int) {
|
||||
mfs := make(model.MediaFiles, len(i.scanner.MediaFiles()))
|
||||
updates := 0
|
||||
j := 0
|
||||
for _, mf := range i.scanner.MediaFiles() {
|
||||
|
@ -197,8 +197,8 @@ func (i *Importer) importMediaFiles() (domain.MediaFiles, int) {
|
|||
return mfs, updates
|
||||
}
|
||||
|
||||
func (i *Importer) importAlbums() (domain.Albums, int) {
|
||||
als := make(domain.Albums, len(i.scanner.Albums()))
|
||||
func (i *Importer) importAlbums() (model.Albums, int) {
|
||||
als := make(model.Albums, len(i.scanner.Albums()))
|
||||
updates := 0
|
||||
j := 0
|
||||
for _, al := range i.scanner.Albums() {
|
||||
|
@ -226,8 +226,8 @@ func (i *Importer) importAlbums() (domain.Albums, int) {
|
|||
return als, updates
|
||||
}
|
||||
|
||||
func (i *Importer) importArtists() domain.Artists {
|
||||
ars := make(domain.Artists, len(i.scanner.Artists()))
|
||||
func (i *Importer) importArtists() model.Artists {
|
||||
ars := make(model.Artists, len(i.scanner.Artists()))
|
||||
j := 0
|
||||
for _, ar := range i.scanner.Artists() {
|
||||
ars[j] = *ar
|
||||
|
@ -252,8 +252,8 @@ func (i *Importer) importArtistIndex() {
|
|||
}
|
||||
}
|
||||
|
||||
func (i *Importer) importPlaylists() domain.Playlists {
|
||||
pls := make(domain.Playlists, len(i.scanner.Playlists()))
|
||||
func (i *Importer) importPlaylists() model.Playlists {
|
||||
pls := make(model.Playlists, len(i.scanner.Playlists()))
|
||||
j := 0
|
||||
for _, pl := range i.scanner.Playlists() {
|
||||
pl.Public = true
|
||||
|
@ -268,7 +268,7 @@ func (i *Importer) importPlaylists() domain.Playlists {
|
|||
return pls
|
||||
}
|
||||
|
||||
func (i *Importer) collectIndex(ig utils.IndexGroups, a *domain.Artist, artistIndex map[string]tempIndex) {
|
||||
func (i *Importer) collectIndex(ig utils.IndexGroups, a *model.Artist, artistIndex map[string]tempIndex) {
|
||||
name := a.Name
|
||||
indexName := strings.ToLower(utils.NoArticle(name))
|
||||
if indexName == "" {
|
||||
|
@ -280,7 +280,7 @@ func (i *Importer) collectIndex(ig utils.IndexGroups, a *domain.Artist, artistIn
|
|||
artists = make(tempIndex)
|
||||
artistIndex[group] = artists
|
||||
}
|
||||
artists[indexName] = domain.ArtistInfo{ArtistID: a.ID, Artist: a.Name, AlbumCount: a.AlbumCount}
|
||||
artists[indexName] = model.ArtistInfo{ArtistID: a.ID, Artist: a.Name, AlbumCount: a.AlbumCount}
|
||||
}
|
||||
|
||||
func (i *Importer) findGroup(ig utils.IndexGroups, name string) string {
|
||||
|
@ -296,7 +296,7 @@ func (i *Importer) findGroup(ig utils.IndexGroups, name string) string {
|
|||
func (i *Importer) saveIndex(artistIndex map[string]tempIndex) error {
|
||||
i.idxRepo.DeleteAll()
|
||||
for k, temp := range artistIndex {
|
||||
idx := &domain.ArtistIndex{ID: k}
|
||||
idx := &model.ArtistIndex{ID: k}
|
||||
for _, v := range temp {
|
||||
idx.Artists = append(idx.Artists, v)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package scanner_legacy
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/tests"
|
||||
"github.com/cloudsonic/sonic-server/utils"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
@ -17,7 +17,7 @@ func TestCollectIndex(t *testing.T) {
|
|||
importer := &Importer{}
|
||||
|
||||
Convey("Simple Name", t, func() {
|
||||
a := &domain.Artist{Name: "Björk"}
|
||||
a := &model.Artist{Name: "Björk"}
|
||||
artistIndex := make(map[string]tempIndex)
|
||||
|
||||
importer.collectIndex(ig, a, artistIndex)
|
||||
|
@ -31,7 +31,7 @@ func TestCollectIndex(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Name not in the index", t, func() {
|
||||
a := &domain.Artist{Name: "Kraftwerk"}
|
||||
a := &model.Artist{Name: "Kraftwerk"}
|
||||
artistIndex := make(map[string]tempIndex)
|
||||
|
||||
importer.collectIndex(ig, a, artistIndex)
|
||||
|
@ -45,7 +45,7 @@ func TestCollectIndex(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Name starts with an article", t, func() {
|
||||
a := &domain.Artist{Name: "The The"}
|
||||
a := &model.Artist{Name: "The The"}
|
||||
artistIndex := make(map[string]tempIndex)
|
||||
|
||||
importer.collectIndex(ig, a, artistIndex)
|
||||
|
@ -59,7 +59,7 @@ func TestCollectIndex(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Name match a multichar entry", t, func() {
|
||||
a := &domain.Artist{Name: "Tom Waits"}
|
||||
a := &model.Artist{Name: "Tom Waits"}
|
||||
artistIndex := make(map[string]tempIndex)
|
||||
|
||||
importer.collectIndex(ig, a, artistIndex)
|
||||
|
|
|
@ -14,25 +14,25 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cloudsonic/sonic-server/conf"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/log"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/dhowden/itl"
|
||||
"github.com/dhowden/tag"
|
||||
)
|
||||
|
||||
type ItunesScanner struct {
|
||||
mediaFiles map[string]*domain.MediaFile
|
||||
albums map[string]*domain.Album
|
||||
artists map[string]*domain.Artist
|
||||
playlists map[string]*domain.Playlist
|
||||
mediaFiles map[string]*model.MediaFile
|
||||
albums map[string]*model.Album
|
||||
artists map[string]*model.Artist
|
||||
playlists map[string]*model.Playlist
|
||||
pplaylists map[string]plsRelation
|
||||
pmediaFiles map[int]*domain.MediaFile
|
||||
pmediaFiles map[int]*model.MediaFile
|
||||
lastModifiedSince time.Time
|
||||
checksumRepo domain.CheckSumRepository
|
||||
checksumRepo model.CheckSumRepository
|
||||
newSums map[string]string
|
||||
}
|
||||
|
||||
func NewItunesScanner(checksumRepo domain.CheckSumRepository) *ItunesScanner {
|
||||
func NewItunesScanner(checksumRepo model.CheckSumRepository) *ItunesScanner {
|
||||
return &ItunesScanner{checksumRepo: checksumRepo}
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,12 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
|||
log.Debug("Loaded tracks", "total", len(l.Tracks))
|
||||
|
||||
s.lastModifiedSince = lastModifiedSince
|
||||
s.mediaFiles = make(map[string]*domain.MediaFile)
|
||||
s.albums = make(map[string]*domain.Album)
|
||||
s.artists = make(map[string]*domain.Artist)
|
||||
s.playlists = make(map[string]*domain.Playlist)
|
||||
s.mediaFiles = make(map[string]*model.MediaFile)
|
||||
s.albums = make(map[string]*model.Album)
|
||||
s.artists = make(map[string]*model.Artist)
|
||||
s.playlists = make(map[string]*model.Playlist)
|
||||
s.pplaylists = make(map[string]plsRelation)
|
||||
s.pmediaFiles = make(map[int]*domain.MediaFile)
|
||||
s.pmediaFiles = make(map[int]*model.MediaFile)
|
||||
s.newSums = make(map[string]string)
|
||||
songsPerAlbum := make(map[string]int)
|
||||
albumsPerArtist := make(map[string]map[string]bool)
|
||||
|
@ -117,16 +117,16 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
|||
return len(l.Tracks), nil
|
||||
}
|
||||
|
||||
func (s *ItunesScanner) MediaFiles() map[string]*domain.MediaFile {
|
||||
func (s *ItunesScanner) MediaFiles() map[string]*model.MediaFile {
|
||||
return s.mediaFiles
|
||||
}
|
||||
func (s *ItunesScanner) Albums() map[string]*domain.Album {
|
||||
func (s *ItunesScanner) Albums() map[string]*model.Album {
|
||||
return s.albums
|
||||
}
|
||||
func (s *ItunesScanner) Artists() map[string]*domain.Artist {
|
||||
func (s *ItunesScanner) Artists() map[string]*model.Artist {
|
||||
return s.artists
|
||||
}
|
||||
func (s *ItunesScanner) Playlists() map[string]*domain.Playlist {
|
||||
func (s *ItunesScanner) Playlists() map[string]*model.Playlist {
|
||||
return s.playlists
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ func (s *ItunesScanner) skipPlaylist(p *itl.Playlist, ignFolders bool, ignPatter
|
|||
}
|
||||
|
||||
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist, fullPath string) {
|
||||
pl := &domain.Playlist{}
|
||||
pl := &model.Playlist{}
|
||||
pl.ID = p.PlaylistPersistentID
|
||||
pl.Name = unescape(p.Name)
|
||||
pl.FullPath = fullPath
|
||||
|
@ -227,8 +227,8 @@ func (s *ItunesScanner) calcCheckSum(t *itl.Track) string {
|
|||
return sum
|
||||
}
|
||||
|
||||
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
||||
mf := &domain.MediaFile{}
|
||||
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *model.MediaFile {
|
||||
mf := &model.MediaFile{}
|
||||
mf.ID = t.PersistentID
|
||||
mf.Album = unescape(t.Album)
|
||||
mf.AlbumID = albumId(t)
|
||||
|
@ -276,11 +276,11 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
|||
return mf
|
||||
}
|
||||
|
||||
func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *domain.Artist) *domain.Album {
|
||||
func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *model.MediaFile, ar *model.Artist) *model.Album {
|
||||
id := albumId(t)
|
||||
_, found := s.albums[id]
|
||||
if !found {
|
||||
s.albums[id] = &domain.Album{}
|
||||
s.albums[id] = &model.Album{}
|
||||
}
|
||||
|
||||
al := s.albums[id]
|
||||
|
@ -322,11 +322,11 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
|
|||
return al
|
||||
}
|
||||
|
||||
func (s *ItunesScanner) collectArtists(t *itl.Track) *domain.Artist {
|
||||
func (s *ItunesScanner) collectArtists(t *itl.Track) *model.Artist {
|
||||
id := artistId(t)
|
||||
_, found := s.artists[id]
|
||||
if !found {
|
||||
s.artists[id] = &domain.Artist{}
|
||||
s.artists[id] = &model.Artist{}
|
||||
}
|
||||
ar := s.artists[id]
|
||||
ar.ID = id
|
||||
|
|
64
wire_gen.go
64
wire_gen.go
|
@ -7,9 +7,9 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/api"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/itunesbridge"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/persistence"
|
||||
"github.com/cloudsonic/sonic-server/scanner_legacy"
|
||||
"github.com/cloudsonic/sonic-server/server"
|
||||
|
@ -19,34 +19,34 @@ import (
|
|||
// Injectors from wire_injectors.go:
|
||||
|
||||
func CreateApp(musicFolder string) *server.Server {
|
||||
provider := createPersistenceProvider()
|
||||
checkSumRepository := provider.CheckSumRepository
|
||||
repositories := createPersistenceProvider()
|
||||
checkSumRepository := repositories.CheckSumRepository
|
||||
itunesScanner := scanner_legacy.NewItunesScanner(checkSumRepository)
|
||||
mediaFileRepository := provider.MediaFileRepository
|
||||
albumRepository := provider.AlbumRepository
|
||||
artistRepository := provider.ArtistRepository
|
||||
artistIndexRepository := provider.ArtistIndexRepository
|
||||
playlistRepository := provider.PlaylistRepository
|
||||
propertyRepository := provider.PropertyRepository
|
||||
mediaFileRepository := repositories.MediaFileRepository
|
||||
albumRepository := repositories.AlbumRepository
|
||||
artistRepository := repositories.ArtistRepository
|
||||
artistIndexRepository := repositories.ArtistIndexRepository
|
||||
playlistRepository := repositories.PlaylistRepository
|
||||
propertyRepository := repositories.PropertyRepository
|
||||
importer := scanner_legacy.NewImporter(musicFolder, itunesScanner, mediaFileRepository, albumRepository, artistRepository, artistIndexRepository, playlistRepository, propertyRepository)
|
||||
serverServer := server.New(importer)
|
||||
return serverServer
|
||||
}
|
||||
|
||||
func CreateSubsonicAPIRouter() *api.Router {
|
||||
provider := createPersistenceProvider()
|
||||
propertyRepository := provider.PropertyRepository
|
||||
mediaFolderRepository := provider.MediaFolderRepository
|
||||
artistIndexRepository := provider.ArtistIndexRepository
|
||||
artistRepository := provider.ArtistRepository
|
||||
albumRepository := provider.AlbumRepository
|
||||
mediaFileRepository := provider.MediaFileRepository
|
||||
repositories := createPersistenceProvider()
|
||||
propertyRepository := repositories.PropertyRepository
|
||||
mediaFolderRepository := repositories.MediaFolderRepository
|
||||
artistIndexRepository := repositories.ArtistIndexRepository
|
||||
artistRepository := repositories.ArtistRepository
|
||||
albumRepository := repositories.AlbumRepository
|
||||
mediaFileRepository := repositories.MediaFileRepository
|
||||
browser := engine.NewBrowser(propertyRepository, mediaFolderRepository, artistIndexRepository, artistRepository, albumRepository, mediaFileRepository)
|
||||
cover := engine.NewCover(mediaFileRepository, albumRepository)
|
||||
nowPlayingRepository := provider.NowPlayingRepository
|
||||
nowPlayingRepository := repositories.NowPlayingRepository
|
||||
listGenerator := engine.NewListGenerator(albumRepository, mediaFileRepository, nowPlayingRepository)
|
||||
itunesControl := itunesbridge.NewItunesControl()
|
||||
playlistRepository := provider.PlaylistRepository
|
||||
playlistRepository := repositories.PlaylistRepository
|
||||
playlists := engine.NewPlaylists(itunesControl, playlistRepository, mediaFileRepository)
|
||||
ratings := engine.NewRatings(itunesControl, mediaFileRepository, albumRepository, artistRepository)
|
||||
scrobbler := engine.NewScrobbler(itunesControl, mediaFileRepository, nowPlayingRepository)
|
||||
|
@ -55,7 +55,7 @@ func CreateSubsonicAPIRouter() *api.Router {
|
|||
return router
|
||||
}
|
||||
|
||||
func createPersistenceProvider() *Provider {
|
||||
func createPersistenceProvider() *Repositories {
|
||||
albumRepository := persistence.NewAlbumRepository()
|
||||
artistRepository := persistence.NewArtistRepository()
|
||||
checkSumRepository := persistence.NewCheckSumRepository()
|
||||
|
@ -65,7 +65,7 @@ func createPersistenceProvider() *Provider {
|
|||
nowPlayingRepository := persistence.NewNowPlayingRepository()
|
||||
playlistRepository := persistence.NewPlaylistRepository()
|
||||
propertyRepository := persistence.NewPropertyRepository()
|
||||
provider := &Provider{
|
||||
repositories := &Repositories{
|
||||
AlbumRepository: albumRepository,
|
||||
ArtistRepository: artistRepository,
|
||||
CheckSumRepository: checkSumRepository,
|
||||
|
@ -76,24 +76,24 @@ func createPersistenceProvider() *Provider {
|
|||
PlaylistRepository: playlistRepository,
|
||||
PropertyRepository: propertyRepository,
|
||||
}
|
||||
return provider
|
||||
return repositories
|
||||
}
|
||||
|
||||
// wire_injectors.go:
|
||||
|
||||
type Provider struct {
|
||||
AlbumRepository domain.AlbumRepository
|
||||
ArtistRepository domain.ArtistRepository
|
||||
CheckSumRepository domain.CheckSumRepository
|
||||
ArtistIndexRepository domain.ArtistIndexRepository
|
||||
MediaFileRepository domain.MediaFileRepository
|
||||
MediaFolderRepository domain.MediaFolderRepository
|
||||
NowPlayingRepository domain.NowPlayingRepository
|
||||
PlaylistRepository domain.PlaylistRepository
|
||||
PropertyRepository domain.PropertyRepository
|
||||
type Repositories struct {
|
||||
AlbumRepository model.AlbumRepository
|
||||
ArtistRepository model.ArtistRepository
|
||||
CheckSumRepository model.CheckSumRepository
|
||||
ArtistIndexRepository model.ArtistIndexRepository
|
||||
MediaFileRepository model.MediaFileRepository
|
||||
MediaFolderRepository model.MediaFolderRepository
|
||||
NowPlayingRepository model.NowPlayingRepository
|
||||
PlaylistRepository model.PlaylistRepository
|
||||
PropertyRepository model.PropertyRepository
|
||||
}
|
||||
|
||||
var allProviders = wire.NewSet(itunesbridge.NewItunesControl, engine.Set, scanner_legacy.Set, api.NewRouter, wire.FieldsOf(new(*Provider), "AlbumRepository", "ArtistRepository", "CheckSumRepository",
|
||||
var allProviders = wire.NewSet(itunesbridge.NewItunesControl, engine.Set, scanner_legacy.Set, api.NewRouter, wire.FieldsOf(new(*Repositories), "AlbumRepository", "ArtistRepository", "CheckSumRepository",
|
||||
"ArtistIndexRepository", "MediaFileRepository", "MediaFolderRepository", "NowPlayingRepository",
|
||||
"PlaylistRepository", "PropertyRepository"), createPersistenceProvider,
|
||||
)
|
||||
|
|
|
@ -4,25 +4,25 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/cloudsonic/sonic-server/api"
|
||||
"github.com/cloudsonic/sonic-server/domain"
|
||||
"github.com/cloudsonic/sonic-server/engine"
|
||||
"github.com/cloudsonic/sonic-server/itunesbridge"
|
||||
"github.com/cloudsonic/sonic-server/model"
|
||||
"github.com/cloudsonic/sonic-server/persistence"
|
||||
"github.com/cloudsonic/sonic-server/scanner_legacy"
|
||||
"github.com/cloudsonic/sonic-server/server"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
AlbumRepository domain.AlbumRepository
|
||||
ArtistRepository domain.ArtistRepository
|
||||
CheckSumRepository domain.CheckSumRepository
|
||||
ArtistIndexRepository domain.ArtistIndexRepository
|
||||
MediaFileRepository domain.MediaFileRepository
|
||||
MediaFolderRepository domain.MediaFolderRepository
|
||||
NowPlayingRepository domain.NowPlayingRepository
|
||||
PlaylistRepository domain.PlaylistRepository
|
||||
PropertyRepository domain.PropertyRepository
|
||||
type Repositories struct {
|
||||
AlbumRepository model.AlbumRepository
|
||||
ArtistRepository model.ArtistRepository
|
||||
CheckSumRepository model.CheckSumRepository
|
||||
ArtistIndexRepository model.ArtistIndexRepository
|
||||
MediaFileRepository model.MediaFileRepository
|
||||
MediaFolderRepository model.MediaFolderRepository
|
||||
NowPlayingRepository model.NowPlayingRepository
|
||||
PlaylistRepository model.PlaylistRepository
|
||||
PropertyRepository model.PropertyRepository
|
||||
}
|
||||
|
||||
var allProviders = wire.NewSet(
|
||||
|
@ -30,7 +30,7 @@ var allProviders = wire.NewSet(
|
|||
engine.Set,
|
||||
scanner_legacy.Set,
|
||||
api.NewRouter,
|
||||
wire.FieldsOf(new(*Provider), "AlbumRepository", "ArtistRepository", "CheckSumRepository",
|
||||
wire.FieldsOf(new(*Repositories), "AlbumRepository", "ArtistRepository", "CheckSumRepository",
|
||||
"ArtistIndexRepository", "MediaFileRepository", "MediaFolderRepository", "NowPlayingRepository",
|
||||
"PlaylistRepository", "PropertyRepository"),
|
||||
createPersistenceProvider,
|
||||
|
@ -49,9 +49,9 @@ func CreateSubsonicAPIRouter() *api.Router {
|
|||
|
||||
// When implementing a different persistence layer, duplicate this function (in separated files) and use build tags
|
||||
// to conditionally select which function to use
|
||||
func createPersistenceProvider() *Provider {
|
||||
func createPersistenceProvider() *Repositories {
|
||||
panic(wire.Build(
|
||||
persistence.Set,
|
||||
wire.Struct(new(Provider), "*"),
|
||||
wire.Struct(new(Repositories), "*"),
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue