Files
navidrome/repositories/property_repository.go
T
2016-03-01 16:05:49 -05:00

47 lines
912 B
Go

package repositories
import (
"github.com/deluan/gosonic/models"
"errors"
)
type Property interface {
Put(id string, value string) error
Get(id string) (string, error)
DefaultGet(id string, defaultValue string) (string, error)
}
type PropertyImpl struct {
BaseRepository
}
func NewPropertyRepository() *PropertyImpl {
r := &PropertyImpl{}
r.init("property", &models.Property{})
return r
}
func (r *PropertyImpl) Put(id string, value string) error {
m := &models.Property{Id: id, Value: value}
if m.Id == "" {
return errors.New("Id is required")
}
return r.saveOrUpdate(m.Id, m)
}
func (r *PropertyImpl) Get(id string) (string, error) {
var rec interface{}
rec, err := r.readEntity(id)
return rec.(*models.Property).Value, err
}
func (r* PropertyImpl) DefaultGet(id string, defaultValue string) (string, error) {
v, err := r.Get(id)
if v == "" {
v = defaultValue
}
return v, err
}