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