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
}
Author := models.Author{
ID: input.ID,
FullName: input.FullName,
}
models.DB.Create(&Author)
c.JSON(http.StatusOK, gin.H{"data": Author})
author := models.NewAuthor(input.ID, input.FullName)
models.DB.Create(&author)
c.JSON(http.StatusOK, gin.H{"data": author})
}
func UpdateAuthor(c *gin.Context) {

View File

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

View File

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

View File

@ -13,3 +13,11 @@ type CreateAuthorInput struct {
type UpdateAuthorInput struct {
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 {
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 {
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
}