Umgeschrieben auf gorilla

This commit is contained in:
2022-01-17 11:04:04 +01:00
parent 5102099a8b
commit 318442cfaf
7 changed files with 117 additions and 282 deletions

View File

@@ -1,51 +0,0 @@
package handlers
import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"git.cosysda.de/HuskyTeufel/Hochzeit/planner"
"github.com/gin-gonic/gin"
)
func GetBesucherListHandler(c *gin.Context) {
c.JSON(http.StatusOK, planner.Get())
}
func AddBesucherHandler(c *gin.Context) {
besucherItem, statusCode, err := convertHTTPBodyToBesucher(c.Request.Body)
if err != nil {
c.JSON(statusCode, err)
return
}
c.JSON(statusCode, gin.H{"id": planner.Add(besucherItem)})
}
func DeleteBesucherHandler(c *gin.Context) {
}
func ComeBesucherHandler(c *gin.Context) {
}
func convertHTTPBodyToBesucher(httpBody io.ReadCloser) (planner.Besucher, int, error) {
body, err := ioutil.ReadAll(httpBody)
if err != nil {
return planner.Besucher{}, http.StatusInternalServerError, err
}
defer httpBody.Close()
return convertJSONBodyToBesucher(body)
}
func convertJSONBodyToBesucher(jsonBody []byte) (planner.Besucher, int, error) {
var besucherItem planner.Besucher
err := json.Unmarshal(jsonBody, &besucherItem)
if err != nil {
return planner.Besucher{}, http.StatusBadRequest, err
}
return besucherItem, http.StatusOK, nil
}