Replace all utils.Param* with req.Params

This commit is contained in:
Deluan
2023-12-21 17:41:09 -05:00
parent 00597e01e9
commit dfcc189cff
27 changed files with 269 additions and 513 deletions
+19 -16
View File
@@ -9,7 +9,7 @@ import (
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/server/public"
"github.com/navidrome/navidrome/server/subsonic/responses"
"github.com/navidrome/navidrome/utils"
"github.com/navidrome/navidrome/utils/req"
)
func (api *Router) GetShares(r *http.Request) (*responses.Subsonic, error) {
@@ -50,13 +50,14 @@ func (api *Router) buildShare(r *http.Request, share model.Share) responses.Shar
}
func (api *Router) CreateShare(r *http.Request) (*responses.Subsonic, error) {
ids := utils.ParamStrings(r, "id")
if len(ids) == 0 {
return nil, newError(responses.ErrorMissingParameter, "Required id parameter is missing")
p := req.Params(r)
ids, err := p.Strings("id")
if err != nil {
return nil, err
}
description := utils.ParamString(r, "description")
expires := utils.ParamTime(r, "expires", time.Time{})
description, _ := p.String("description")
expires := p.TimeOr("expires", time.Time{})
repo := api.share.NewRepository(r.Context())
share := &model.Share{
@@ -81,13 +82,14 @@ func (api *Router) CreateShare(r *http.Request) (*responses.Subsonic, error) {
}
func (api *Router) UpdateShare(r *http.Request) (*responses.Subsonic, error) {
id := utils.ParamString(r, "id")
if id == "" {
return nil, newError(responses.ErrorMissingParameter, "Required id parameter is missing")
p := req.Params(r)
id, err := p.String("id")
if err != nil {
return nil, err
}
description := utils.ParamString(r, "description")
expires := utils.ParamTime(r, "expires", time.Time{})
description, _ := p.String("description")
expires := p.TimeOr("expires", time.Time{})
repo := api.share.NewRepository(r.Context())
share := &model.Share{
@@ -96,7 +98,7 @@ func (api *Router) UpdateShare(r *http.Request) (*responses.Subsonic, error) {
ExpiresAt: expires,
}
err := repo.(rest.Persistable).Update(id, share)
err = repo.(rest.Persistable).Update(id, share)
if err != nil {
return nil, err
}
@@ -105,13 +107,14 @@ func (api *Router) UpdateShare(r *http.Request) (*responses.Subsonic, error) {
}
func (api *Router) DeleteShare(r *http.Request) (*responses.Subsonic, error) {
id := utils.ParamString(r, "id")
if id == "" {
return nil, newError(responses.ErrorMissingParameter, "Required id parameter is missing")
p := req.Params(r)
id, err := p.String("id")
if err != nil {
return nil, err
}
repo := api.share.NewRepository(r.Context())
err := repo.(rest.Persistable).Delete(id)
err = repo.(rest.Persistable).Delete(id)
if err != nil {
return nil, err
}