1
0

Added validation for structs (#19)

This commit is contained in:
konrad
2018-11-16 23:17:37 +00:00
committed by Gitea
parent 373bbd2202
commit 0c544fe355
299 changed files with 135 additions and 64237 deletions

View File

@ -17,6 +17,11 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
}
// Validate the struct
if err := ctx.Validate(currentStruct); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
// Get the user to pass for later checks
currentUser, err := models.GetCurrentUser(ctx)
if err != nil {

View File

@ -18,6 +18,11 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
}
// Validate the struct
if err := ctx.Validate(currentStruct); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
// Check if the user has the right to do that
currentUser, err := models.GetCurrentUser(ctx)
if err != nil {