Added dynamically get books status
This commit is contained in:
parent
a76f20610a
commit
f48de8e75f
|
@ -28,6 +28,8 @@ func AddBook(book Book) (newBook Book, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Check for empty values, should have at least a title. If no publisher is given (aka ID=0 & Name=""), don't insert an empty one.
|
||||
|
||||
_, exists, err = GetPublisherByID(publisherid)
|
||||
if err != nil {
|
||||
return Book{}, err
|
||||
|
|
|
@ -31,6 +31,7 @@ func SetEngine() (err error) {
|
|||
x.Sync(&Publisher{})
|
||||
x.Sync(&Author{})
|
||||
x.Sync(&AuthorBook{})
|
||||
x.Sync(&Status{})
|
||||
|
||||
x.ShowSQL(true)
|
||||
return nil
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package models
|
||||
|
||||
// Status holds a status
|
||||
type Status struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk"`
|
||||
Name string `xorm:"varchar(250)"`
|
||||
}
|
||||
|
||||
func GetStatusList() (status []Status, err error){
|
||||
err = x.Find(&status)
|
||||
return status, err
|
||||
}
|
||||
|
||||
func GetStatusByID(id int64) (status Status, err error) {
|
||||
_, err = x.Where("id = ?", id).Get(&status)
|
||||
return status, err
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"net/http"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func StatusListShow(c echo.Context) error {
|
||||
status, err := models.GetStatusList()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, status)
|
||||
}
|
||||
|
||||
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 {
|
||||
fmt.Println(err)
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, status)
|
||||
}
|
|
@ -72,6 +72,10 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
a.GET("/publishers/:id", apiv1.PublisherShow)
|
||||
a.GET("/publishers/search", apiv1.PublisherSearch)
|
||||
|
||||
// Lookup Status
|
||||
a.GET("/status", apiv1.StatusListShow)
|
||||
a.GET("/status/:id", apiv1.StatusByIDShow)
|
||||
|
||||
// ===== Routes with Authetification =====
|
||||
// Authetification
|
||||
a.Use(middleware.JWT(models.Config.JWTLoginSecret))
|
||||
|
|
Loading…
Reference in New Issue