Library/routes/api/v1/status.go

43 lines
1.0 KiB
Go
Raw Normal View History

2017-11-15 15:13:47 +00:00
package v1
import (
2018-03-05 11:53:12 +00:00
"git.kolaente.de/konrad/Library/models"
2017-11-15 15:16:44 +00:00
"github.com/labstack/echo"
2017-11-15 15:13:47 +00:00
"net/http"
"strconv"
)
2017-11-15 15:16:44 +00:00
// StatusListShow is the requesthandler to get a list with all status
2017-11-15 15:13:47 +00:00
func StatusListShow(c echo.Context) error {
status, err := models.GetStatusList()
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
return c.JSON(http.StatusOK, status)
}
2017-11-15 15:16:44 +00:00
// StatusByIDShow is the requesthandler to get a status by its ID
2017-11-15 15:13:47 +00:00
func StatusByIDShow(c echo.Context) error {
statusIn := c.Param("id")
if statusIn == "" {
return c.JSON(http.StatusBadRequest, models.Message{"Status ID cannot be empty."})
}
// Make int
statusID, err := strconv.ParseInt(statusIn, 10, 64)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting status infos."})
}
status, err := models.GetStatusByID(statusID)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
return c.JSON(http.StatusOK, status)
}