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