2018-07-11 01:45:11 +02:00
|
|
|
package crud
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.kolaente.de/konrad/list/models"
|
2018-07-11 02:13:53 +02:00
|
|
|
"github.com/labstack/echo"
|
2018-07-11 01:45:11 +02:00
|
|
|
"net/http"
|
2018-07-12 11:54:55 +02:00
|
|
|
"fmt"
|
2018-07-11 01:45:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2018-07-11 14:27:16 +02:00
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID.")
|
2018-07-11 01:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO check rights
|
2018-07-12 11:54:55 +02:00
|
|
|
//c.CObject.CanRead(doer)
|
2018-07-11 01:45:11 +02:00
|
|
|
|
|
|
|
// Get our object
|
|
|
|
err = c.CObject.ReadOne(id)
|
|
|
|
if err != nil {
|
|
|
|
if models.IsErrListDoesNotExist(err) {
|
2018-07-11 14:27:16 +02:00
|
|
|
return echo.NewHTTPError(http.StatusNotFound)
|
2018-07-11 01:45:11 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 11:54:55 +02:00
|
|
|
if models.IsErrNamespaceDoesNotExist(err) {
|
|
|
|
return echo.NewHTTPError(http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
2018-07-11 14:27:16 +02:00
|
|
|
return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.")
|
2018-07-11 01:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.JSON(http.StatusOK, c.CObject)
|
|
|
|
}
|