diff --git a/persistence/album_repository.go b/persistence/album_repository.go index 49078d67..797d1203 100644 --- a/persistence/album_repository.go +++ b/persistence/album_repository.go @@ -10,7 +10,7 @@ import ( "github.com/cloudsonic/sonic-server/model" ) -type Album struct { +type album struct { ID string `orm:"pk;column(id)"` Name string `orm:"index"` ArtistID string `orm:"column(artist_id);index"` @@ -43,14 +43,14 @@ func NewAlbumRepository() model.AlbumRepository { } func (r *albumRepository) Put(a *model.Album) error { - ta := Album(*a) + ta := album(*a) return withTx(func(o orm.Ormer) error { return r.put(o, a.ID, a.Name, &ta) }) } func (r *albumRepository) Get(id string) (*model.Album, error) { - ta := Album{ID: id} + ta := album{ID: id} err := Db().Read(&ta) if err == orm.ErrNoRows { return nil, model.ErrNotFound @@ -63,7 +63,7 @@ func (r *albumRepository) Get(id string) (*model.Album, 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) if err != nil { return nil, err @@ -72,7 +72,7 @@ func (r *albumRepository) FindByArtist(artistId string) (model.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) if err != nil { return nil, err @@ -80,7 +80,7 @@ func (r *albumRepository) GetAll(options ...model.QueryOptions) (model.Albums, e return r.toAlbums(all), nil } -func (r *albumRepository) toAlbums(all []Album) model.Albums { +func (r *albumRepository) toAlbums(all []album) model.Albums { result := make(model.Albums, len(all)) for i, a := range all { result[i] = model.Album(a) @@ -90,7 +90,7 @@ func (r *albumRepository) toAlbums(all []Album) model.Albums { func (r *albumRepository) Refresh(ids ...string) error { type refreshAlbum struct { - Album + album CurrentId string HasCoverArt bool } @@ -109,8 +109,8 @@ group by album_id order by f.id`, strings.Join(ids, "','")) return err } - var toInsert []Album - var toUpdate []Album + var toInsert []album + var toUpdate []album for _, al := range albums { if !al.HasCoverArt { al.CoverArtId = "" @@ -119,9 +119,9 @@ group by album_id order by f.id`, strings.Join(ids, "','")) al.AlbumArtist = "Various Artists" } if al.CurrentId != "" { - toUpdate = append(toUpdate, al.Album) + toUpdate = append(toUpdate, al.album) } else { - toInsert = append(toInsert, al.Album) + toInsert = append(toInsert, al.album) } } if len(toInsert) > 0 { @@ -154,7 +154,7 @@ func (r *albumRepository) PurgeInactive(activeList model.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) if err != nil { return nil, err @@ -167,7 +167,7 @@ func (r *albumRepository) Search(q string, offset int, size int) (model.Albums, return nil, nil } - var results []Album + var results []album err := r.doSearch(r.tableName, q, offset, size, &results, "rating desc", "starred desc", "play_count desc", "name") if err != nil { return nil, err @@ -176,4 +176,4 @@ func (r *albumRepository) Search(q string, offset int, size int) (model.Albums, } var _ model.AlbumRepository = (*albumRepository)(nil) -var _ = model.Album(Album{}) +var _ = model.Album(album{}) diff --git a/persistence/artist_repository.go b/persistence/artist_repository.go index fe5143e7..f237ec4e 100644 --- a/persistence/artist_repository.go +++ b/persistence/artist_repository.go @@ -12,7 +12,7 @@ import ( "github.com/cloudsonic/sonic-server/utils" ) -type Artist struct { +type artist struct { ID string `orm:"pk;column(id)"` Name string `orm:"index"` AlbumCount int `orm:"column(album_count)"` @@ -30,7 +30,7 @@ func NewArtistRepository() model.ArtistRepository { return r } -func (r *artistRepository) getIndexKey(a *Artist) string { +func (r *artistRepository) getIndexKey(a *artist) string { name := strings.ToLower(utils.NoArticle(a.Name)) for k, v := range r.indexGroups { key := strings.ToLower(k) @@ -42,14 +42,14 @@ func (r *artistRepository) getIndexKey(a *Artist) string { } func (r *artistRepository) Put(a *model.Artist) error { - ta := Artist(*a) + ta := artist(*a) return withTx(func(o orm.Ormer) error { return r.put(o, a.ID, a.Name, &ta) }) } func (r *artistRepository) Get(id string) (*model.Artist, error) { - ta := Artist{ID: id} + ta := artist{ID: id} err := Db().Read(&ta) if err == orm.ErrNoRows { return nil, model.ErrNotFound @@ -63,7 +63,7 @@ func (r *artistRepository) Get(id string) (*model.Artist, error) { // TODO Cache the index (recalculate when there are changes to the DB) func (r *artistRepository) GetIndex() (model.ArtistIndexes, error) { - var all []Artist + var all []artist _, err := r.newQuery(Db()).OrderBy("name").All(&all) if err != nil { return nil, err @@ -91,7 +91,7 @@ func (r *artistRepository) GetIndex() (model.ArtistIndexes, error) { func (r *artistRepository) Refresh(ids ...string) error { type refreshArtist struct { - Artist + artist CurrentId string AlbumArtist string Compilation bool @@ -113,8 +113,8 @@ where f.artist_id in ('%s') group by f.artist_id order by f.id`, strings.Join(id return err } - var toInsert []Artist - var toUpdate []Artist + var toInsert []artist + var toUpdate []artist for _, ar := range artists { if ar.Compilation { ar.AlbumArtist = "Various Artists" @@ -123,9 +123,9 @@ where f.artist_id in ('%s') group by f.artist_id order by f.id`, strings.Join(id ar.Name = ar.AlbumArtist } if ar.CurrentId != "" { - toUpdate = append(toUpdate, ar.Artist) + toUpdate = append(toUpdate, ar.artist) } else { - toInsert = append(toInsert, ar.Artist) + toInsert = append(toInsert, ar.artist) } } if len(toInsert) > 0 { @@ -161,7 +161,7 @@ func (r *artistRepository) Search(q string, offset int, size int) (model.Artists return nil, nil } - var results []Artist + var results []artist err := r.doSearch(r.tableName, q, offset, size, &results, "name") if err != nil { return nil, err @@ -170,7 +170,7 @@ func (r *artistRepository) Search(q string, offset int, size int) (model.Artists return r.toArtists(results), nil } -func (r *artistRepository) toArtists(all []Artist) model.Artists { +func (r *artistRepository) toArtists(all []artist) model.Artists { result := make(model.Artists, len(all)) for i, a := range all { result[i] = model.Artist(a) @@ -179,4 +179,4 @@ func (r *artistRepository) toArtists(all []Artist) model.Artists { } var _ model.ArtistRepository = (*artistRepository)(nil) -var _ = model.Artist(Artist{}) +var _ = model.Artist(artist{}) diff --git a/persistence/checksum_repository.go b/persistence/checksum_repository.go index 1e64dc03..a9be175d 100644 --- a/persistence/checksum_repository.go +++ b/persistence/checksum_repository.go @@ -10,7 +10,7 @@ type checkSumRepository struct { const checkSumId = "1" -type Checksum struct { +type checksum struct { ID string `orm:"pk;column(id)"` Sum string } @@ -23,8 +23,8 @@ func NewCheckSumRepository() model.ChecksumRepository { func (r *checkSumRepository) GetData() (model.ChecksumMap, error) { loadedData := make(map[string]string) - var all []Checksum - _, err := Db().QueryTable(&Checksum{}).Limit(-1).All(&all) + var all []checksum + _, err := Db().QueryTable(&checksum{}).Limit(-1).All(&all) if err != nil { return nil, err } @@ -43,9 +43,9 @@ func (r *checkSumRepository) SetData(newSums model.ChecksumMap) error { return err } - var checksums []Checksum + var checksums []checksum for k, v := range newSums { - cks := Checksum{ID: k, Sum: v} + cks := checksum{ID: k, Sum: v} checksums = append(checksums, cks) } _, err = Db().InsertMulti(batchSize, &checksums) diff --git a/persistence/checksum_repository_test.go b/persistence/checksum_repository_test.go index 20fef836..2bb32ea8 100644 --- a/persistence/checksum_repository_test.go +++ b/persistence/checksum_repository_test.go @@ -10,7 +10,7 @@ var _ = Describe("ChecksumRepository", func() { var repo model.ChecksumRepository BeforeEach(func() { - Db().Delete(&Checksum{ID: checkSumId}) + Db().Delete(&checksum{ID: checkSumId}) repo = NewCheckSumRepository() err := repo.SetData(map[string]string{ "a": "AAA", "b": "BBB", diff --git a/persistence/mediafile_repository.go b/persistence/mediafile_repository.go index 92d6c715..99f3e9ae 100644 --- a/persistence/mediafile_repository.go +++ b/persistence/mediafile_repository.go @@ -9,7 +9,7 @@ import ( "github.com/cloudsonic/sonic-server/model" ) -type MediaFile struct { +type mediaFile struct { ID string `orm:"pk;column(id)"` Path string `orm:"index"` Title string `orm:"index"` @@ -48,14 +48,14 @@ func NewMediaFileRepository() model.MediaFileRepository { } func (r *mediaFileRepository) Put(m *model.MediaFile) error { - tm := MediaFile(*m) + tm := mediaFile(*m) return withTx(func(o orm.Ormer) error { return r.put(o, m.ID, m.Title, &tm) }) } func (r *mediaFileRepository) Get(id string) (*model.MediaFile, error) { - tm := MediaFile{ID: id} + tm := mediaFile{ID: id} err := Db().Read(&tm) if err == orm.ErrNoRows { return nil, model.ErrNotFound @@ -67,7 +67,7 @@ func (r *mediaFileRepository) Get(id string) (*model.MediaFile, error) { return &a, nil } -func (r *mediaFileRepository) toMediaFiles(all []MediaFile) model.MediaFiles { +func (r *mediaFileRepository) toMediaFiles(all []mediaFile) model.MediaFiles { result := make(model.MediaFiles, len(all)) for i, m := range all { result[i] = model.MediaFile(m) @@ -76,7 +76,7 @@ func (r *mediaFileRepository) toMediaFiles(all []MediaFile) model.MediaFiles { } 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) if err != nil { return nil, err @@ -85,12 +85,12 @@ func (r *mediaFileRepository) FindByAlbum(albumId string) (model.MediaFiles, err } func (r *mediaFileRepository) FindByPath(path string) (model.MediaFiles, error) { - var mfs []MediaFile + var mfs []mediaFile _, err := r.newQuery(Db()).Filter("path__istartswith", path).OrderBy("disc_number", "track_number").All(&mfs) if err != nil { return nil, err } - var filtered []MediaFile + var filtered []mediaFile path = strings.ToLower(path) + string(os.PathSeparator) for _, mf := range mfs { filename := strings.TrimPrefix(strings.ToLower(mf.Path), path) @@ -104,7 +104,7 @@ func (r *mediaFileRepository) FindByPath(path string) (model.MediaFiles, error) func (r *mediaFileRepository) DeleteByPath(path string) error { o := Db() - var mfs []MediaFile + var mfs []mediaFile _, err := r.newQuery(o).Filter("path__istartswith", path).OrderBy("disc_number", "track_number").All(&mfs) if err != nil { return err @@ -123,7 +123,7 @@ func (r *mediaFileRepository) DeleteByPath(path string) 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) if err != nil { return nil, err @@ -145,7 +145,7 @@ func (r *mediaFileRepository) Search(q string, offset int, size int) (model.Medi return nil, nil } - var results []MediaFile + var results []mediaFile err := r.doSearch(r.tableName, q, offset, size, &results, "rating desc", "starred desc", "play_count desc", "title") if err != nil { return nil, err @@ -154,4 +154,4 @@ func (r *mediaFileRepository) Search(q string, offset int, size int) (model.Medi } var _ model.MediaFileRepository = (*mediaFileRepository)(nil) -var _ = model.MediaFile(MediaFile{}) +var _ = model.MediaFile(mediaFile{}) diff --git a/persistence/persistence.go b/persistence/persistence.go index d196839c..d269476a 100644 --- a/persistence/persistence.go +++ b/persistence/persistence.go @@ -71,12 +71,12 @@ func collectField(collection interface{}, getValue func(item interface{}) string func initORM(dbPath string) error { verbose := conf.Sonic.LogLevel == "trace" orm.Debug = verbose - orm.RegisterModel(new(Artist)) - orm.RegisterModel(new(Album)) - orm.RegisterModel(new(MediaFile)) - orm.RegisterModel(new(Checksum)) - orm.RegisterModel(new(Property)) - orm.RegisterModel(new(Playlist)) + orm.RegisterModel(new(artist)) + orm.RegisterModel(new(album)) + orm.RegisterModel(new(mediaFile)) + orm.RegisterModel(new(checksum)) + orm.RegisterModel(new(property)) + orm.RegisterModel(new(playlist)) orm.RegisterModel(new(Search)) if strings.Contains(dbPath, "postgres") { driver = "postgres" diff --git a/persistence/playlist_repository.go b/persistence/playlist_repository.go index 8696dd13..59b74b8b 100644 --- a/persistence/playlist_repository.go +++ b/persistence/playlist_repository.go @@ -7,7 +7,7 @@ import ( "github.com/cloudsonic/sonic-server/model" ) -type Playlist struct { +type playlist struct { ID string `orm:"pk;column(id)"` Name string `orm:"index"` Comment string @@ -36,7 +36,7 @@ func (r *playlistRepository) Put(p *model.Playlist) error { } func (r *playlistRepository) Get(id string) (*model.Playlist, error) { - tp := &Playlist{ID: id} + tp := &playlist{ID: id} err := Db().Read(tp) if err == orm.ErrNoRows { return nil, model.ErrNotFound @@ -49,7 +49,7 @@ func (r *playlistRepository) Get(id string) (*model.Playlist, error) { } func (r *playlistRepository) GetAll(options ...model.QueryOptions) (model.Playlists, error) { - var all []Playlist + var all []playlist _, err := r.newQuery(Db(), options...).All(&all) if err != nil { return nil, err @@ -57,7 +57,7 @@ func (r *playlistRepository) GetAll(options ...model.QueryOptions) (model.Playli return r.toPlaylists(all) } -func (r *playlistRepository) toPlaylists(all []Playlist) (model.Playlists, error) { +func (r *playlistRepository) toPlaylists(all []playlist) (model.Playlists, error) { result := make(model.Playlists, len(all)) for i, p := range all { result[i] = r.toDomain(&p) @@ -74,7 +74,7 @@ func (r *playlistRepository) PurgeInactive(activeList model.Playlists) ([]string }) } -func (r *playlistRepository) toDomain(p *Playlist) model.Playlist { +func (r *playlistRepository) toDomain(p *playlist) model.Playlist { return model.Playlist{ ID: p.ID, Name: p.Name, @@ -87,8 +87,8 @@ func (r *playlistRepository) toDomain(p *Playlist) model.Playlist { } } -func (r *playlistRepository) fromDomain(p *model.Playlist) Playlist { - return Playlist{ +func (r *playlistRepository) fromDomain(p *model.Playlist) playlist { + return playlist{ ID: p.ID, Name: p.Name, Comment: p.Comment, diff --git a/persistence/property_repository.go b/persistence/property_repository.go index af8f0917..96046f61 100644 --- a/persistence/property_repository.go +++ b/persistence/property_repository.go @@ -5,7 +5,7 @@ import ( "github.com/cloudsonic/sonic-server/model" ) -type Property struct { +type property struct { ID string `orm:"pk;column(id)"` Value string } @@ -21,7 +21,7 @@ func NewPropertyRepository() model.PropertyRepository { } func (r *propertyRepository) Put(id string, value string) error { - p := &Property{ID: id, Value: value} + p := &property{ID: id, Value: value} num, err := Db().Update(p) if err != nil { return nil @@ -33,7 +33,7 @@ func (r *propertyRepository) Put(id string, value string) error { } func (r *propertyRepository) Get(id string) (string, error) { - p := &Property{ID: id} + p := &property{ID: id} err := Db().Read(p) if err == orm.ErrNoRows { return "", model.ErrNotFound