Library/routes/api/v1/publishers_show.go

39 lines
927 B
Go
Raw Normal View History

package v1
import (
2018-03-05 11:53:12 +00:00
"git.kolaente.de/konrad/Library/models"
"github.com/labstack/echo"
"net/http"
"strconv"
)
2017-11-08 09:55:17 +00:00
// PublisherShow is the handler to show informations about a publisher
func PublisherShow(c echo.Context) error {
publisher := c.Param("id")
if publisher == "" {
return c.JSON(http.StatusBadRequest, models.Message{"Publisher ID cannot be empty."})
}
// Make int
publisherID, err := strconv.ParseInt(publisher, 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Publisher ID is invalid."})
}
// Get Publisher Infos
publisherInfos, exists, err := models.GetPublisherByID(publisherID)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publisher infos."})
}
// Check if it exists
if !exists {
return c.JSON(http.StatusNotFound, models.Message{"Publisher not found."})
}
return c.JSON(http.StatusOK, publisherInfos)
}