Add: update foldername

This commit is contained in:
2021-12-13 03:43:09 +08:00
parent a2cb098330
commit e87b4823d9
5 changed files with 98 additions and 2 deletions

35
pkg/api/handle_folder.go Normal file
View File

@@ -0,0 +1,35 @@
package api
import (
"encoding/json"
"net/http"
)
type UpdateFoldernameRequest struct {
ID int64 `json:"id"`
Foldername string `json:"foldername"`
}
func (api *API) HandleUpdateFoldername(w http.ResponseWriter, r *http.Request) {
req := &UpdateFoldernameRequest{}
err := json.NewDecoder(r.Body).Decode(req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// check is admin
err = api.CheckAdmin(w, r)
if err != nil {
api.HandleError(w, r, err)
return
}
err = api.Db.UpdateFoldername(req.ID, req.Foldername)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
api.HandleOK(w, r)
}