2017-10-11 15:20:56 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2017-11-07 15:35:10 +00:00
|
|
|
"git.mowie.cc/konrad/Library/models"
|
2017-10-11 15:20:56 +00:00
|
|
|
"github.com/labstack/echo"
|
|
|
|
"net/http"
|
2017-11-07 15:35:10 +00:00
|
|
|
"strconv"
|
2017-10-11 15:20:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func AuthorDelete(c echo.Context) error {
|
|
|
|
|
|
|
|
id := c.Param("id")
|
|
|
|
|
|
|
|
// Make int
|
|
|
|
authorID, err := strconv.ParseInt(id, 10, 64)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get author infos"})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the author exists
|
|
|
|
_, exists, err := models.GetAuthorByID(authorID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could get author"})
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
return c.JSON(http.StatusBadRequest, models.Message{"The author does not exist."})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete it
|
|
|
|
err = models.DeleteAuthorByID(authorID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return c.JSON(http.StatusInternalServerError, models.Message{"Could not delete author"})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, models.Message{"success"})
|
2017-11-07 15:35:10 +00:00
|
|
|
}
|