vikunja-api/routes/crud/read_one.go
2018-07-11 14:27:16 +02:00

31 lines
671 B
Go

package crud
import (
"git.kolaente.de/konrad/list/models"
"github.com/labstack/echo"
"net/http"
)
// ReadOneWeb is the webhandler to get one object
func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
// Get the ID
id, err := models.GetIntURLParam("id", ctx)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID.")
}
// TODO check rights
// Get our object
err = c.CObject.ReadOne(id)
if err != nil {
if models.IsErrListDoesNotExist(err) {
return echo.NewHTTPError(http.StatusNotFound)
}
return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.")
}
return ctx.JSON(http.StatusOK, c.CObject)
}