feat(template): add name to the template definition
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,9 @@ func CreateSVG(writer http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := actions.Create(readsvg)
|
||||
name := r.URL.Query().Get("name")
|
||||
|
||||
data, err := actions.Create(readsvg, name)
|
||||
|
||||
if err != nil {
|
||||
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user