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-08 10:18:17 -09:00
|
|
|
|
2016-03-02 05:07:24 -09:00
|
|
|
"github.com/deluan/gosonic/domain"
|
2016-02-28 09:50:05 -09:00
|
|
|
)
|
|
|
|
|
|
2016-03-02 05:33:49 -09:00
|
|
|
type artistRepository struct {
|
2016-03-03 16:16:09 -09:00
|
|
|
ledisRepository
|
2016-02-28 09:50:05 -09:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 05:33:49 -09:00
|
|
|
func NewArtistRepository() domain.ArtistRepository {
|
|
|
|
|
r := &artistRepository{}
|
2016-03-02 05:07:24 -09:00
|
|
|
r.init("artist", &domain.Artist{})
|
2016-02-28 09:50:05 -09:00
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 05:33:49 -09:00
|
|
|
func (r *artistRepository) Put(m *domain.Artist) error {
|
2016-02-28 09:50:05 -09:00
|
|
|
if m.Id == "" {
|
2016-03-23 12:30:38 -08:00
|
|
|
return errors.New("artist 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
|
|
|
}
|
|
|
|
|
|
2016-03-02 05:33:49 -09:00
|
|
|
func (r *artistRepository) Get(id string) (*domain.Artist, error) {
|
2016-02-29 18:17:54 -09:00
|
|
|
var rec interface{}
|
|
|
|
|
rec, err := r.readEntity(id)
|
2016-03-02 05:07:24 -09:00
|
|
|
return rec.(*domain.Artist), err
|
2016-02-28 09:50:05 -09:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 15:50:21 -08:00
|
|
|
func (r *artistRepository) PurgeInactive(active domain.Artists) ([]string, error) {
|
2016-03-18 15:32:49 -08:00
|
|
|
return r.purgeInactive(active, func(e interface{}) string {
|
|
|
|
|
return e.(domain.Artist).Id
|
|
|
|
|
})
|
2016-03-08 10:18:17 -09:00
|
|
|
}
|
|
|
|
|
|
2016-03-04 12:42:09 -09:00
|
|
|
var _ domain.ArtistRepository = (*artistRepository)(nil)
|