added new functions

This commit is contained in:
Tyrel Souza 2024-06-18 22:59:35 -04:00
parent fec67b0e33
commit d9d38c3df4
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
6 changed files with 37 additions and 22 deletions

View File

@ -31,12 +31,9 @@ func CreateAuthor(c *gin.Context) {
return return
} }
Author := models.Author{ author := models.NewAuthor(input.ID, input.FullName)
ID: input.ID, models.DB.Create(&author)
FullName: input.FullName, c.JSON(http.StatusOK, gin.H{"data": author})
}
models.DB.Create(&Author)
c.JSON(http.StatusOK, gin.H{"data": Author})
} }
func UpdateAuthor(c *gin.Context) { func UpdateAuthor(c *gin.Context) {

View File

@ -31,12 +31,9 @@ func CreateFormat(c *gin.Context) {
return return
} }
Format := models.Format{ format := models.NewFormat(input.ID, input.Format)
ID: input.ID, models.DB.Create(&format)
Format: input.Format, c.JSON(http.StatusOK, gin.H{"data": format})
}
models.DB.Create(&Format)
c.JSON(http.StatusOK, gin.H{"data": Format})
} }
func UpdateFormat(c *gin.Context) { func UpdateFormat(c *gin.Context) {

View File

@ -31,16 +31,9 @@ func CreateOrder(c *gin.Context) {
return return
} }
Order := models.Order{ order := models.NewOrder(input.ID, input.Title, input.Author, input.Format, input.ISBN13, input.ReleaseDate)
ID: input.ID, models.DB.Create(&order)
Title: input.Title, c.JSON(http.StatusOK, gin.H{"data": order})
AuthorID: input.Author,
FormatID: input.Format,
ISBN13: input.ISBN13,
ReleaseDate: input.ReleaseDate,
}
models.DB.Create(&Order)
c.JSON(http.StatusOK, gin.H{"data": Order})
} }
func UpdateOrder(c *gin.Context) { func UpdateOrder(c *gin.Context) {

View File

@ -13,3 +13,11 @@ type CreateAuthorInput struct {
type UpdateAuthorInput struct { type UpdateAuthorInput struct {
FullName string `json:"full_name"` FullName string `json:"full_name"`
} }
func NewAuthor(id uint, full_name string) Author {
author := Author{
ID: id,
FullName: full_name,
}
return author
}

View File

@ -13,3 +13,11 @@ type CreateFormatInput struct {
type UpdateFormatInput struct { type UpdateFormatInput struct {
Format string `json:"format"` Format string `json:"format"`
} }
func NewFormat(id uint, format_name string) Format {
format := Format{
ID: id,
Format: format_name,
}
return format
}

View File

@ -25,3 +25,15 @@ type CreateOrderInput struct {
type UpdateOrderInput struct { type UpdateOrderInput struct {
Title string `json:"title"` Title string `json:"title"`
} }
func NewOrder(id uint, title string, author uint, format uint, isbn_13 uint, release_date time.Time) Order {
order := Order{
ID: id,
Title: title,
AuthorID: author,
FormatID: format,
ISBN13: isbn_13,
ReleaseDate: release_date,
}
return order
}