2016-02-28 19:50:05 +01:00
|
|
|
package repositories
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/deluan/gosonic/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Album struct {
|
|
|
|
BaseRepository
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAlbumRepository() *Album {
|
|
|
|
r := &Album{}
|
2016-02-29 04:56:24 +01:00
|
|
|
r.table = "album"
|
2016-02-28 19:50:05 +01:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2016-02-29 04:56:24 +01:00
|
|
|
func (r *Album) Put(m *models.Album) error {
|
2016-02-28 19:50:05 +01:00
|
|
|
if m.Id == "" {
|
|
|
|
m.Id = r.NewId(m.Name)
|
|
|
|
}
|
2016-02-29 04:56:24 +01:00
|
|
|
return r.saveOrUpdate(m.Id, m)
|
2016-02-28 19:50:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Album) Get(id string) (*models.Album, error) {
|
|
|
|
rec := &models.Album{}
|
2016-02-29 04:56:24 +01:00
|
|
|
err := r.loadEntity(id, rec)
|
2016-02-28 19:50:05 +01:00
|
|
|
return rec, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Album) GetByName(name string) (*models.Album, error) {
|
|
|
|
id := r.NewId(name)
|
|
|
|
return r.Get(id)
|
|
|
|
}
|
|
|
|
|