Replaced CObject with a function returning an object
This commit is contained in:
@ -8,14 +8,16 @@ import (
|
||||
|
||||
// ReadOneWeb is the webhandler to get one object
|
||||
func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
||||
// Get our model
|
||||
currentStruct := c.EmptyStruct()
|
||||
|
||||
// Get the object & bind params to struct
|
||||
if err := ParamBinder(c.CObject, ctx); err != nil {
|
||||
if err := ParamBinder(currentStruct, ctx); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
|
||||
}
|
||||
|
||||
// Get our object
|
||||
err := c.CObject.ReadOne()
|
||||
err := currentStruct.ReadOne()
|
||||
if err != nil {
|
||||
return HandleHTTPError(err)
|
||||
}
|
||||
@ -26,10 +28,10 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
if !c.CObject.CanRead(¤tUser) {
|
||||
if !currentStruct.CanRead(¤tUser) {
|
||||
models.Log.Noticef("%s [ID: %d] tried to read while not having the rights for it", currentUser.Username, currentUser.ID)
|
||||
return echo.NewHTTPError(http.StatusForbidden, "You don't have the right to see this")
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusOK, c.CObject)
|
||||
return ctx.JSON(http.StatusOK, currentStruct)
|
||||
}
|
||||
|
Reference in New Issue
Block a user