38 lines
750 B
Go
38 lines
750 B
Go
package routes
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"tomatentum.net/svg-templater/pkg/svg/actions"
|
|
)
|
|
|
|
type renameRequest struct {
|
|
Name string
|
|
}
|
|
|
|
func RenameSvg(w http.ResponseWriter, r *http.Request) {
|
|
contentType := r.Header.Get("Content-Type")
|
|
if contentType != "application/json" {
|
|
http.Error(w, "Incorrect Content-Type. Needs application/json.", http.StatusUnsupportedMediaType)
|
|
return
|
|
}
|
|
|
|
var request renameRequest
|
|
err := json.NewDecoder(r.Body).Decode(&request)
|
|
|
|
if err != nil {
|
|
http.Error(w, "Could not decode body.", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
id := r.PathValue("id")
|
|
|
|
err = actions.RenameSvg(id, request.Name)
|
|
|
|
if err != nil {
|
|
http.Error(w, "Error while renaming", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|