Cleanup
the build failed
Details
the build failed
Details
This commit is contained in:
parent
634e696369
commit
e485218688
|
@ -1,9 +1,5 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Book holds a book
|
||||
type Book struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
|
@ -36,19 +32,19 @@ func GetBookByID(ID int64) (book Book, exists bool, err error) {
|
|||
// Get the books quantity. We can't join it because xorm ignores the Quantity option in struct
|
||||
book.Quantity, err = book.getQuantity()
|
||||
if err != nil {
|
||||
fmt.Println("Error getting quantity:", err)
|
||||
return Book{}, false, err
|
||||
}
|
||||
|
||||
// Get publisher. We can't join it because xorm ignores the PublisherID option in struct
|
||||
book.Publisher, _, err = GetPublisherByID(book.PublisherID)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting publisher:", err)
|
||||
return Book{}, false, err
|
||||
}
|
||||
|
||||
// Get all authors
|
||||
book.Authors, err = GetAuthorsByBook(book)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting authors:", err)
|
||||
return Book{}, false, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ sie in die Datenbank eingetragen und mit dem Buch verknüpft.
|
|||
func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
||||
|
||||
// Check if we have at least a booktitle when we're inserting a new book
|
||||
if book.Title == "" && book.ID == 0{
|
||||
if book.Title == "" && book.ID == 0 {
|
||||
return Book{}, fmt.Errorf("the book should at least have a title")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package models
|
||||
|
||||
import "fmt"
|
||||
|
||||
// BookPublisher struct to join books with publishers
|
||||
type BookPublisher struct {
|
||||
Book `xorm:"extends"`
|
||||
|
@ -13,15 +11,14 @@ func ListBooks(searchterm string) (books []*Book, err error) {
|
|||
|
||||
if searchterm == "" {
|
||||
err = x.Table("books").
|
||||
//Join("INNER", "publishers", "books.publisher = publishers.id").
|
||||
Find(&books)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting Books", err)
|
||||
return []*Book{}, err
|
||||
}
|
||||
} else {
|
||||
err = x.Where("title LIKE ?", "%"+searchterm+"%").Find(&books)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting Books", err)
|
||||
return []*Book{}, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,19 +28,19 @@ func ListBooks(searchterm string) (books []*Book, err error) {
|
|||
// Get quantities
|
||||
books[i].Quantity, err = book.getQuantity()
|
||||
if err != nil {
|
||||
fmt.Println("Error getting quantity:", err)
|
||||
return []*Book{}, err
|
||||
}
|
||||
|
||||
// Get publisher
|
||||
books[i].Publisher, _, err = GetPublisherByID(book.PublisherID)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting publisher:", err)
|
||||
return []*Book{}, err
|
||||
}
|
||||
|
||||
// Get all authors
|
||||
books[i].Authors, err = GetAuthorsByBook(*book)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting authors:", err)
|
||||
return []*Book{}, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ func (Publisher) TableName() string {
|
|||
|
||||
// GetPublisherByID returns a publisher by its ID
|
||||
func GetPublisherByID(id int64) (publisher Publisher, exists bool, err error) {
|
||||
has, err := x.Id(id).Get(&publisher)
|
||||
|
||||
return publisher, has, err
|
||||
exists, err = x.Id(id).Get(&publisher)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ func DeletePublisherByID(id int64) error {
|
|||
|
||||
// Set all publisher to 0 on all book with this publisher
|
||||
_, err = x.Table("books").
|
||||
Where("publisher_id = ?", id).
|
||||
Update(map[string]interface{}{"publisher_id": 0})
|
||||
Where("publisher_id = ?", id).
|
||||
Update(map[string]interface{}{"publisher_id": 0})
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -109,10 +109,10 @@ func (item Item) setQuantity(quantity int64) (err error) {
|
|||
func (book Book) getQuantity() (quantity int64, err error) {
|
||||
qty := Quantity{}
|
||||
_, err = x.Table("quantities").
|
||||
Select("quantities.id, quantity_relations.item_id, quantities.quantity, quantities.created").
|
||||
Join("INNER", "quantity_relations", "quantities.item_id = quantity_relations.id").
|
||||
Where("quantity_relations.book_id = ?", book.ID).
|
||||
Desc("quantities.created").Get(&qty)
|
||||
Select("quantities.id, quantity_relations.item_id, quantities.quantity, quantities.created").
|
||||
Join("INNER", "quantity_relations", "quantities.item_id = quantity_relations.id").
|
||||
Where("quantity_relations.book_id = ?", book.ID).
|
||||
Desc("quantities.created").Get(&qty)
|
||||
|
||||
return qty.Quantity, err
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ type Status struct {
|
|||
// GetStatusList returns an array with all status
|
||||
func GetStatusList() (status []Status, err error) {
|
||||
err = x.Find(&status)
|
||||
return status, err
|
||||
return
|
||||
}
|
||||
|
||||
// GetStatusByID returns a status object with all its infos
|
||||
func GetStatusByID(id int64) (status Status, err error) {
|
||||
_, err = x.Where("id = ?", id).Get(&status)
|
||||
return status, err
|
||||
return
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ func (User) TableName() string {
|
|||
|
||||
// GetUserByID gets informations about a user by its ID
|
||||
func GetUserByID(id int64) (user User, exists bool, err error) {
|
||||
/*exists, err = x.Id(id).Get(&user)
|
||||
return user, exists, err*/
|
||||
return GetUser(User{ID: id})
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package v1
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
|
@ -23,7 +22,6 @@ func AuthorAddOrUpdate(c echo.Context) error {
|
|||
if authorFromString == "" {
|
||||
b := new(authorPayload)
|
||||
if err := c.Bind(b); err != nil {
|
||||
fmt.Println(err)
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"No author model provided"})
|
||||
}
|
||||
datAuthor = b.Author
|
||||
|
|
|
@ -2,7 +2,6 @@ package v1
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
|
@ -23,7 +22,6 @@ func BookAddOrUpdate(c echo.Context) error {
|
|||
if bookFromString == "" {
|
||||
b := new(bookPayload)
|
||||
if err := c.Bind(b); err != nil {
|
||||
fmt.Println(err)
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"No book model provided"})
|
||||
}
|
||||
datBook = b.Book
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type itemPayload struct {
|
||||
|
@ -23,7 +22,6 @@ func ItemAddOrUpdate(c echo.Context) error {
|
|||
if itemFromString == "" {
|
||||
b := new(itemPayload)
|
||||
if err := c.Bind(b); err != nil {
|
||||
fmt.Println(err)
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"No item model provided"})
|
||||
}
|
||||
datItem = b.Item
|
||||
|
|
Loading…
Reference in New Issue