parent
a2fb389b7e
commit
c93b2f433c
|
@ -9,7 +9,10 @@ import (
|
|||
// AuthorsList is the handler to list authors
|
||||
func AuthorsList(c echo.Context) error {
|
||||
|
||||
list, err := models.ListAuthors("")
|
||||
// Prepare the searchterm
|
||||
search := c.QueryParam("s")
|
||||
|
||||
list, err := models.ListAuthors(search)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"})
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
)
|
||||
|
||||
// AuthorSearch is the handler to search for authors
|
||||
func AuthorSearch(c echo.Context) error {
|
||||
|
||||
// Prepare the searchterm
|
||||
search := c.QueryParam("s")
|
||||
|
||||
if search == "" {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"Search cannot be empty."})
|
||||
}
|
||||
|
||||
// Get the Authors
|
||||
list, err := models.ListAuthors(search)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"})
|
||||
}
|
||||
|
||||
// Check if we have any results
|
||||
if len(list) == 0 {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any authors matching your search term"})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, list)
|
||||
}
|
|
@ -10,7 +10,10 @@ import (
|
|||
// BookList is the handler to list books
|
||||
func BookList(c echo.Context) error {
|
||||
|
||||
list, err := models.ListBooks("")
|
||||
// Prepare the searchterm
|
||||
search := c.QueryParam("s")
|
||||
|
||||
list, err := models.ListBooks(search)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
)
|
||||
|
||||
// BookSearch is the handler to search for books
|
||||
func BookSearch(c echo.Context) error {
|
||||
|
||||
// Prepare the searchterm
|
||||
search := c.QueryParam("s")
|
||||
|
||||
if search == "" {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"Search cannot be empty."})
|
||||
}
|
||||
|
||||
// Get the Books
|
||||
list, err := models.ListBooks(search)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
|
||||
}
|
||||
|
||||
// Check if we have any results
|
||||
if len(list) == 0 {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any books matching your search term"})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, list)
|
||||
}
|
|
@ -9,7 +9,10 @@ import (
|
|||
// PublishersList is the handler to list publishers
|
||||
func PublishersList(c echo.Context) error {
|
||||
|
||||
list, err := models.ListPublishers("")
|
||||
// Prepare the searchterm
|
||||
search := c.QueryParam("s")
|
||||
|
||||
list, err := models.ListPublishers(search)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publishers"})
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
)
|
||||
|
||||
// PublisherSearch is the handler to search for a publisher
|
||||
func PublisherSearch(c echo.Context) error {
|
||||
|
||||
// Prepare the searchterm
|
||||
search := c.QueryParam("s")
|
||||
|
||||
if search == "" {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"Search cannot be empty."})
|
||||
}
|
||||
|
||||
// Get the Publishers
|
||||
list, err := models.ListPublishers(search)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publisher"})
|
||||
}
|
||||
|
||||
// Check if we have any results
|
||||
if len(list) == 0 {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any publisher matching your search term"})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, list)
|
||||
}
|
|
@ -64,17 +64,14 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
// Lookup Books
|
||||
a.GET("/books", apiv1.BookList)
|
||||
a.GET("/books/:id", apiv1.BookShow)
|
||||
a.GET("/books/search", apiv1.BookSearch)
|
||||
|
||||
// Lookup Authors
|
||||
a.GET("/authors", apiv1.AuthorsList)
|
||||
a.GET("/authors/:id", apiv1.AuthorShow)
|
||||
a.GET("/authors/search", apiv1.AuthorSearch)
|
||||
|
||||
// Lookup Publishers
|
||||
a.GET("/publishers", apiv1.PublishersList)
|
||||
a.GET("/publishers/:id", apiv1.PublisherShow)
|
||||
a.GET("/publishers/search", apiv1.PublisherSearch)
|
||||
|
||||
// Lookup Items
|
||||
a.GET("/items", apiv1.ItemsList)
|
||||
|
|
Loading…
Reference in New Issue
Block a user