quintodrome/persistence/property_repository.go

41 lines
729 B
Go
Raw Normal View History

2016-03-02 05:07:24 -09:00
package persistence
import (
2016-03-02 05:07:24 -09:00
"github.com/deluan/gosonic/domain"
"errors"
)
2016-03-01 15:17:30 -09:00
type property struct {
BaseRepository
}
2016-03-01 15:17:30 -09:00
func NewPropertyRepository() *property {
r := &property{}
2016-03-02 05:07:24 -09:00
r.init("property", &domain.Property{})
return r
}
2016-03-01 15:17:30 -09:00
func (r *property) Put(id string, value string) error {
2016-03-02 05:07:24 -09:00
m := &domain.Property{Id: id, Value: value}
if m.Id == "" {
return errors.New("Id is required")
}
return r.saveOrUpdate(m.Id, m)
}
2016-03-01 15:17:30 -09:00
func (r *property) Get(id string) (string, error) {
var rec interface{}
rec, err := r.readEntity(id)
2016-03-02 05:07:24 -09:00
return rec.(*domain.Property).Value, err
}
2016-03-01 12:05:49 -09:00
2016-03-01 15:17:30 -09:00
func (r*property) DefaultGet(id string, defaultValue string) (string, error) {
2016-03-01 12:05:49 -09:00
v, err := r.Get(id)
if v == "" {
v = defaultValue
}
return v, err
}