Getting JSON Objects improvements
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
f41a197cc5
commit
78fe10094e
|
@ -9,22 +9,16 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type authorPayload struct {
|
||||
Author models.Author `json:"author" form:"author"`
|
||||
}
|
||||
|
||||
// AuthorAddOrUpdate is the handler to add or update an author
|
||||
func AuthorAddOrUpdate(c echo.Context) error {
|
||||
// Check for Request Content
|
||||
authorFromString := c.FormValue("author")
|
||||
var datAuthor models.Author
|
||||
var datAuthor *models.Author
|
||||
|
||||
if authorFromString == "" {
|
||||
b := new(authorPayload)
|
||||
if err := c.Bind(b); err != nil {
|
||||
if err := c.Bind(&datAuthor); err != nil {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"No author model provided"})
|
||||
}
|
||||
datAuthor = b.Author
|
||||
} else {
|
||||
// Decode the JSON
|
||||
dec := json.NewDecoder(strings.NewReader(authorFromString))
|
||||
|
@ -53,7 +47,7 @@ func AuthorAddOrUpdate(c echo.Context) error {
|
|||
}
|
||||
|
||||
// Insert or update the author
|
||||
newAuthor, err := models.AddOrUpdateAuthor(datAuthor)
|
||||
newAuthor, err := models.AddOrUpdateAuthor(*datAuthor)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error"})
|
||||
|
|
|
@ -9,22 +9,16 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type bookPayload struct {
|
||||
Book models.Book `json:"book" form:"book"`
|
||||
}
|
||||
|
||||
// BookAddOrUpdate is the handler to add a book
|
||||
func BookAddOrUpdate(c echo.Context) error {
|
||||
// Check for Request Content
|
||||
bookFromString := c.FormValue("book")
|
||||
var datBook models.Book
|
||||
var datBook *models.Book
|
||||
|
||||
if bookFromString == "" {
|
||||
b := new(bookPayload)
|
||||
if err := c.Bind(b); err != nil {
|
||||
if err := c.Bind(&datBook); err != nil {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"No book model provided"})
|
||||
}
|
||||
datBook = b.Book
|
||||
} else {
|
||||
// Decode the JSON
|
||||
dec := json.NewDecoder(strings.NewReader(bookFromString))
|
||||
|
@ -53,7 +47,7 @@ func BookAddOrUpdate(c echo.Context) error {
|
|||
}
|
||||
|
||||
// Insert or update the book
|
||||
newBook, err := models.AddOrUpdateBook(datBook)
|
||||
newBook, err := models.AddOrUpdateBook(*datBook)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error"})
|
||||
|
|
|
@ -9,22 +9,16 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type itemPayload struct {
|
||||
Item models.Item `json:"item" form:"item"`
|
||||
}
|
||||
|
||||
// ItemAddOrUpdate is the handler to add a item
|
||||
func ItemAddOrUpdate(c echo.Context) error {
|
||||
// Check for Request Content
|
||||
itemFromString := c.FormValue("item")
|
||||
var datItem models.Item
|
||||
var datItem *models.Item
|
||||
|
||||
if itemFromString == "" {
|
||||
b := new(itemPayload)
|
||||
if err := c.Bind(b); err != nil {
|
||||
if err := c.Bind(&datItem); err != nil {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"No item model provided"})
|
||||
}
|
||||
datItem = b.Item
|
||||
} else {
|
||||
// Decode the JSON
|
||||
dec := json.NewDecoder(strings.NewReader(itemFromString))
|
||||
|
@ -48,7 +42,7 @@ func ItemAddOrUpdate(c echo.Context) error {
|
|||
}
|
||||
|
||||
// Insert or update the item
|
||||
newItem, err := models.AddOrUpdateItem(datItem)
|
||||
newItem, err := models.AddOrUpdateItem(*datItem)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error"})
|
||||
|
|
|
@ -9,22 +9,17 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type publisherPayload struct {
|
||||
Publisher models.Publisher `json:"publisher" form:"publisher"`
|
||||
}
|
||||
|
||||
// PublisherAddOrUpdate is the handler to add a publisher
|
||||
func PublisherAddOrUpdate(c echo.Context) error {
|
||||
// Check for Request Content
|
||||
publisherFromString := c.FormValue("publisher")
|
||||
var datPublisher models.Publisher
|
||||
var datPublisher *models.Publisher
|
||||
|
||||
if publisherFromString == "" {
|
||||
b := new(publisherPayload)
|
||||
if err := c.Bind(b); err != nil {
|
||||
// b := new(models.Publisher)
|
||||
if err := c.Bind(&datPublisher); err != nil {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"No publisher model provided"})
|
||||
}
|
||||
datPublisher = b.Publisher
|
||||
} else {
|
||||
// Decode the JSON
|
||||
dec := json.NewDecoder(strings.NewReader(publisherFromString))
|
||||
|
@ -48,7 +43,7 @@ func PublisherAddOrUpdate(c echo.Context) error {
|
|||
}
|
||||
|
||||
// Insert or update the publisher
|
||||
newPublisher, err := models.AddOrUpdatePublisher(datPublisher)
|
||||
newPublisher, err := models.AddOrUpdatePublisher(*datPublisher)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error"})
|
||||
|
|
Loading…
Reference in New Issue