mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Pass userId explicitly to UserPropsRepository methods
This commit is contained in:
parent
a1551074bb
commit
ee21f3957e
8 changed files with 42 additions and 60 deletions
|
@ -4,9 +4,8 @@ import "github.com/navidrome/navidrome/model"
|
|||
|
||||
type MockedUserPropsRepo struct {
|
||||
model.UserPropsRepository
|
||||
UserID string
|
||||
data map[string]string
|
||||
err error
|
||||
data map[string]string
|
||||
err error
|
||||
}
|
||||
|
||||
func (p *MockedUserPropsRepo) init() {
|
||||
|
@ -15,44 +14,44 @@ func (p *MockedUserPropsRepo) init() {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *MockedUserPropsRepo) Put(key string, value string) error {
|
||||
func (p *MockedUserPropsRepo) Put(userId, key string, value string) error {
|
||||
if p.err != nil {
|
||||
return p.err
|
||||
}
|
||||
p.init()
|
||||
p.data[p.UserID+"_"+key] = value
|
||||
p.data[userId+key] = value
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MockedUserPropsRepo) Get(key string) (string, error) {
|
||||
func (p *MockedUserPropsRepo) Get(userId, key string) (string, error) {
|
||||
if p.err != nil {
|
||||
return "", p.err
|
||||
}
|
||||
p.init()
|
||||
if v, ok := p.data[p.UserID+"_"+key]; ok {
|
||||
if v, ok := p.data[userId+key]; ok {
|
||||
return v, nil
|
||||
}
|
||||
return "", model.ErrNotFound
|
||||
}
|
||||
|
||||
func (p *MockedUserPropsRepo) Delete(key string) error {
|
||||
func (p *MockedUserPropsRepo) Delete(userId, key string) error {
|
||||
if p.err != nil {
|
||||
return p.err
|
||||
}
|
||||
p.init()
|
||||
if _, ok := p.data[p.UserID+"_"+key]; ok {
|
||||
delete(p.data, p.UserID+"_"+key)
|
||||
if _, ok := p.data[userId+key]; ok {
|
||||
delete(p.data, userId+key)
|
||||
return nil
|
||||
}
|
||||
return model.ErrNotFound
|
||||
}
|
||||
|
||||
func (p *MockedUserPropsRepo) DefaultGet(key string, defaultValue string) (string, error) {
|
||||
func (p *MockedUserPropsRepo) DefaultGet(userId, key string, defaultValue string) (string, error) {
|
||||
if p.err != nil {
|
||||
return "", p.err
|
||||
}
|
||||
p.init()
|
||||
v, err := p.Get(p.UserID + "_" + key)
|
||||
v, err := p.Get(userId, key)
|
||||
if err != nil {
|
||||
return defaultValue, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue