quintodrome/persistence/album_repository.go

44 lines
1,002 B
Go
Raw Normal View History

2016-03-02 05:07:24 -09:00
package persistence
2016-02-28 09:50:05 -09:00
import (
2016-03-04 12:42:09 -09:00
"errors"
2016-03-02 05:07:24 -09:00
"github.com/deluan/gosonic/domain"
2016-02-28 09:50:05 -09:00
)
type albumRepository struct {
ledisRepository
2016-02-28 09:50:05 -09:00
}
func NewAlbumRepository() domain.AlbumRepository {
r := &albumRepository{}
2016-03-02 05:07:24 -09:00
r.init("album", &domain.Album{})
2016-02-28 09:50:05 -09:00
return r
}
func (r *albumRepository) Put(m *domain.Album) error {
2016-02-28 09:50:05 -09:00
if m.Id == "" {
2016-03-04 12:42:09 -09:00
return errors.New("Album Id is not set")
2016-02-28 09:50:05 -09:00
}
2016-02-28 18:56:24 -09:00
return r.saveOrUpdate(m.Id, m)
2016-02-28 09:50:05 -09:00
}
func (r *albumRepository) Get(id string) (*domain.Album, error) {
var rec interface{}
rec, err := r.readEntity(id)
2016-03-02 05:07:24 -09:00
return rec.(*domain.Album), err
2016-03-02 09:18:39 -09:00
}
2016-03-03 17:01:55 -09:00
func (r *albumRepository) FindByArtist(artistId string) (domain.Albums, error) {
var as = make(domain.Albums, 0)
err := r.loadChildren("artist", artistId, &as, domain.QueryOptions{SortBy: "Year"})
return as, err
}
func (r *albumRepository) GetAll(options domain.QueryOptions) (domain.Albums, error) {
var as = make(domain.Albums, 0)
err := r.loadAll(&as, options)
return as, err
}
var _ domain.AlbumRepository = (*albumRepository)(nil)