Started implementing getIndex, now with TDD (brought to you by DI)!

This commit is contained in:
Deluan
2016-03-01 12:35:30 -05:00
parent b2cdf8cadb
commit 2bb4c74ba6
7 changed files with 129 additions and 21 deletions
+5 -5
View File
@@ -11,30 +11,30 @@ type ArtistIndex interface {
GetAll() ([]models.ArtistIndex, error)
}
type artistIndex struct {
type ArtistIndexImpl struct {
BaseRepository
}
func NewArtistIndexRepository() ArtistIndex {
r := &artistIndex{}
r := &ArtistIndexImpl{}
r.init("index", &models.ArtistIndex{})
return r
}
func (r *artistIndex) Put(m *models.ArtistIndex) error {
func (r *ArtistIndexImpl) Put(m *models.ArtistIndex) error {
if m.Id == "" {
return errors.New("Id is not set")
}
return r.saveOrUpdate(m.Id, m)
}
func (r *artistIndex) Get(id string) (*models.ArtistIndex, error) {
func (r *ArtistIndexImpl) Get(id string) (*models.ArtistIndex, error) {
var rec interface{}
rec, err := r.readEntity(id)
return rec.(*models.ArtistIndex), err
}
func (r *artistIndex) GetAll() ([]models.ArtistIndex, error) {
func (r *ArtistIndexImpl) GetAll() ([]models.ArtistIndex, error) {
var indices = make([]models.ArtistIndex, 0)
err := r.loadAll(&indices)
return indices, err