Umgeschrieben auf gorilla
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user