Introduced interfaces for all repositories, completely isolating the persistence layer from the repositories usage and specification
This commit is contained in:
@@ -4,30 +4,30 @@ import (
|
||||
"github.com/deluan/gosonic/domain"
|
||||
)
|
||||
|
||||
type Artist struct {
|
||||
BaseRepository
|
||||
type artistRepository struct {
|
||||
baseRepository
|
||||
}
|
||||
|
||||
func NewArtistRepository() *Artist {
|
||||
r := &Artist{}
|
||||
func NewArtistRepository() domain.ArtistRepository {
|
||||
r := &artistRepository{}
|
||||
r.init("artist", &domain.Artist{})
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Artist) Put(m *domain.Artist) error {
|
||||
func (r *artistRepository) Put(m *domain.Artist) error {
|
||||
if m.Id == "" {
|
||||
m.Id = r.NewId(m.Name)
|
||||
}
|
||||
return r.saveOrUpdate(m.Id, m)
|
||||
}
|
||||
|
||||
func (r *Artist) Get(id string) (*domain.Artist, error) {
|
||||
func (r *artistRepository) Get(id string) (*domain.Artist, error) {
|
||||
var rec interface{}
|
||||
rec, err := r.readEntity(id)
|
||||
return rec.(*domain.Artist), err
|
||||
}
|
||||
|
||||
func (r *Artist) GetByName(name string) (*domain.Artist, error) {
|
||||
func (r *artistRepository) GetByName(name string) (*domain.Artist, error) {
|
||||
id := r.NewId(name)
|
||||
return r.Get(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user