Started the implementation of getMusicDirectory. Probably will need to introduce a new 'service' layer...
This commit is contained in:
@@ -39,6 +39,11 @@ func (r *baseRepository) CountAll() (int, error) {
|
||||
return len(ids), err
|
||||
}
|
||||
|
||||
func (r *baseRepository) Exists(id string) (bool, error) {
|
||||
res, err := db().SIsMember([]byte(r.table + "s:all"), []byte(id))
|
||||
return res != 0, err
|
||||
}
|
||||
|
||||
func (r *baseRepository) saveOrUpdate(id string, entity interface{}) error {
|
||||
recordPrefix := fmt.Sprintf("%s:%s:", r.table, id)
|
||||
allKey := r.table + "s:all"
|
||||
|
||||
@@ -7,17 +7,17 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
type artistIndex struct {
|
||||
type artistIndexRepository struct {
|
||||
baseRepository
|
||||
}
|
||||
|
||||
func NewArtistIndexRepository() domain.ArtistIndexRepository {
|
||||
r := &artistIndex{}
|
||||
r := &artistIndexRepository{}
|
||||
r.init("index", &domain.ArtistIndex{})
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *artistIndex) Put(m *domain.ArtistIndex) error {
|
||||
func (r *artistIndexRepository) Put(m *domain.ArtistIndex) error {
|
||||
if m.Id == "" {
|
||||
return errors.New("Id is not set")
|
||||
}
|
||||
@@ -25,13 +25,13 @@ func (r *artistIndex) Put(m *domain.ArtistIndex) error {
|
||||
return r.saveOrUpdate(m.Id, m)
|
||||
}
|
||||
|
||||
func (r *artistIndex) Get(id string) (*domain.ArtistIndex, error) {
|
||||
func (r *artistIndexRepository) Get(id string) (*domain.ArtistIndex, error) {
|
||||
var rec interface{}
|
||||
rec, err := r.readEntity(id)
|
||||
return rec.(*domain.ArtistIndex), err
|
||||
}
|
||||
|
||||
func (r *artistIndex) GetAll() ([]domain.ArtistIndex, error) {
|
||||
func (r *artistIndexRepository) GetAll() ([]domain.ArtistIndex, error) {
|
||||
var indices = make([]domain.ArtistIndex, 0)
|
||||
err := r.loadAll(&indices, "")
|
||||
return indices, err
|
||||
|
||||
@@ -23,6 +23,17 @@ func TestIndexRepository(t *testing.T) {
|
||||
|
||||
So(s, shouldBeEqual, i)
|
||||
})
|
||||
Convey("It should be able to check for existance of an Id", func() {
|
||||
i := &domain.ArtistIndex{Id: "123"}
|
||||
|
||||
repo.Put(i)
|
||||
|
||||
s, _ := repo.Exists("123")
|
||||
So(s, ShouldBeTrue)
|
||||
|
||||
s, _ = repo.Exists("NOT_FOUND")
|
||||
So(s, ShouldBeFalse)
|
||||
})
|
||||
Convey("Method Put() should return error if Id is not set", func() {
|
||||
i := &domain.ArtistIndex{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user