diff --git a/models/books_list.go b/models/books_list.go index 803ac66..2a2ca43 100644 --- a/models/books_list.go +++ b/models/books_list.go @@ -16,12 +16,12 @@ func (Book) TableName() string{ return "books" } -func ListBooks() (books []*Book) { +func ListBooks() (books []*Book, err error) { - err := x.Find(&books) + err = x.Find(&books) if err != nil { fmt.Println("Error getting Books", err) } - return books + return books, err } diff --git a/models/message.go b/models/message.go new file mode 100644 index 0000000..978258f --- /dev/null +++ b/models/message.go @@ -0,0 +1,5 @@ +package models + +type Message struct{ + Message string +} \ No newline at end of file diff --git a/routes/api/v1/books_list.go b/routes/api/v1/books_list.go index 4111d9e..5fc93e5 100644 --- a/routes/api/v1/books_list.go +++ b/routes/api/v1/books_list.go @@ -9,7 +9,11 @@ import ( func List(c echo.Context) error { - list := models.ListBooks() + list, err := models.ListBooks() + + if err != nil{ + return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"}) + } return c.JSON(http.StatusOK, list) } \ No newline at end of file