Introduced interfaces for all repositories, completely isolating the persistence layer from the repositories usage and specification

This commit is contained in:
Deluan
2016-03-02 09:33:49 -05:00
parent 272a499c7e
commit 300ed0d9a4
15 changed files with 83 additions and 48 deletions
+7 -7
View File
@@ -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)
}