1
0

implemented creation of thing via parambinder

This commit is contained in:
konrad
2018-07-18 08:56:19 +02:00
committed by kolaente
parent ebb5b332b6
commit de95ff40bf
21 changed files with 39 additions and 40 deletions

View File

@ -14,8 +14,9 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
p := reflect.ValueOf(c.CObject).Elem()
p.Set(reflect.Zero(p.Type()))
// Get the object
if err := ctx.Bind(&c.CObject); err != nil {
// Get the object & bind params to struct
if err := ParamBinder(c.CObject, ctx); err != nil {
fmt.Println(err)
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
}
@ -26,21 +27,21 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
}
// Get an ID if we have one
var id int64
/*var id int64
if ctx.Param("id") != "" {
id, err = models.GetIntURLParam("id", ctx)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Bad id.")
}
}
}*/
// Check rights
if !c.CObject.CanCreate(&currentUser, id) {
if !c.CObject.CanCreate(&currentUser) {
return echo.NewHTTPError(http.StatusForbidden)
}
// Create
err = c.CObject.Create(&currentUser, id)
err = c.CObject.Create(&currentUser)
if err != nil {
if models.IsErrListDoesNotExist(err) {
return echo.NewHTTPError(http.StatusBadRequest, "The list does not exist.")

View File

@ -9,11 +9,6 @@ import (
// DeleteWeb is the web handler to delete something
func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
// Get the ID
/*id, err := models.GetIntURLParam("id", ctx)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID.")
}*/
// Bind params to struct
if err := ParamBinder(c.CObject, ctx); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid URL param.")