Files
tueem 633859cabe
build / Go-Build (push) Successful in 3m1s
build / Go-Build (pull_request) Successful in 1m27s
feat(template): add name to the template definition
2026-05-26 14:47:03 +02:00

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
}
}