feat(template): add name to the template definition
build / Go-Build (push) Successful in 3m1s
build / Go-Build (pull_request) Successful in 1m27s

This commit is contained in:
2026-05-26 14:47:03 +02:00
parent 20cb740eb6
commit 633859cabe
8 changed files with 102 additions and 12 deletions
+37
View File
@@ -0,0 +1,37 @@
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
}
}