Implement updateShare and deleteShare Subsonic endpoints
This commit is contained in:
@@ -129,6 +129,8 @@ func (api *Router) routes() http.Handler {
|
||||
r.Group(func(r chi.Router) {
|
||||
h(r, "getShares", api.GetShares)
|
||||
h(r, "createShare", api.CreateShare)
|
||||
h(r, "updateShare", api.UpdateShare)
|
||||
h(r, "deleteShare", api.DeleteShare)
|
||||
})
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(getPlayer(api.players))
|
||||
@@ -170,7 +172,6 @@ func (api *Router) routes() http.Handler {
|
||||
|
||||
// Not Implemented (yet?)
|
||||
h501(r, "jukeboxControl")
|
||||
h501(r, "updateShare", "deleteShare")
|
||||
h501(r, "getPodcasts", "getNewestPodcasts", "refreshPodcasts", "createPodcastChannel", "deletePodcastChannel",
|
||||
"deletePodcastEpisode", "downloadPodcastEpisode")
|
||||
h501(r, "createUser", "updateUser", "deleteUser", "changePassword")
|
||||
|
||||
@@ -73,3 +73,42 @@ func (api *Router) CreateShare(r *http.Request) (*responses.Subsonic, error) {
|
||||
response.Shares = &responses.Shares{Share: []responses.Share{api.buildShare(r, *share)}}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
description := utils.ParamString(r, "description")
|
||||
expires := utils.ParamTime(r, "expires", time.Time{})
|
||||
|
||||
repo := api.share.NewRepository(r.Context())
|
||||
share := &model.Share{
|
||||
ID: id,
|
||||
Description: description,
|
||||
ExpiresAt: expires,
|
||||
}
|
||||
|
||||
err := repo.(rest.Persistable).Update(id, share)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newResponse(), nil
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
repo := api.share.NewRepository(r.Context())
|
||||
err := repo.(rest.Persistable).Delete(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newResponse(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user