From 1ed4859ced5f112e858da76ef7e3a7c506c3a1c6 Mon Sep 17 00:00:00 2001 From: Redume Date: Sat, 17 Dec 2022 16:23:24 +0300 Subject: [PATCH] add to db who author image --- api/controllers/favorite.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/api/controllers/favorite.go b/api/controllers/favorite.go index c34dde9..8105554 100644 --- a/api/controllers/favorite.go +++ b/api/controllers/favorite.go @@ -13,13 +13,14 @@ var GetFavorites = func(c *fiber.Ctx) error { type Favorite struct { Title string `json:"title"` Explanation string `json:"explanation"` + Copyright string `json:"copyright"` Date string `json:"date"` URL string `json:"url"` HDURL string `json:"hdurl"` MediaType string `json:"media_type"` } - var title, explanation, date, url, hdurl, media_type string + var title, explanation, copyright, date, url, hdurl, media_type string db := functions.GetDatabase() if FavoriteTitle != "" { @@ -36,7 +37,7 @@ var GetFavorites = func(c *fiber.Ctx) error { }(queryFavorites) for queryFavorites.Next() { - err := queryFavorites.Scan(&title, &explanation, &date, &url, &hdurl, &media_type) + err := queryFavorites.Scan(&title, &explanation, ©right, &date, &url, &hdurl, &media_type) if err != nil { functions.Logger(err.Error()) } @@ -44,6 +45,7 @@ var GetFavorites = func(c *fiber.Ctx) error { return c.JSON(fiber.Map{ "title": title, "explanation": explanation, + "copyright": copyright, "date": date, "url": url, "hdurl": hdurl, @@ -65,7 +67,7 @@ var GetFavorites = func(c *fiber.Ctx) error { var favorites []Favorite for queryFavorite.Next() { - err := queryFavorite.Scan(&title, &explanation, &date, &url, &hdurl, &media_type) + err := queryFavorite.Scan(&title, &explanation, ©right, &date, &url, &hdurl, &media_type) if err != nil { functions.Logger(err.Error()) } @@ -73,6 +75,7 @@ var GetFavorites = func(c *fiber.Ctx) error { favorites = append(favorites, Favorite{ Title: title, Explanation: explanation, + Copyright: copyright, Date: date, URL: url, HDURL: hdurl, @@ -88,6 +91,7 @@ var GetFavorites = func(c *fiber.Ctx) error { var AddFavorite = func(c *fiber.Ctx) error { title := c.FormValue("title") explanation := c.FormValue("explanation") + copyright := c.FormValue("copyright") date := c.FormValue("date") url := c.FormValue("url") hdurl := c.FormValue("hdurl") @@ -100,9 +104,10 @@ var AddFavorite = func(c *fiber.Ctx) error { db := functions.GetDatabase() - _, err := db.Exec("INSERT INTO favorite (title, explanation, date, url, hdurl, media_type) VALUES (?, ?, ?, ?, ?, ?)", + _, err := db.Exec("INSERT INTO favorite (title, explanation, copyright, date, url, hdurl, media_type) VALUES (?, ?, ?, ?, ?, ?, ?)", title, explanation, + copyright, date, url, hdurl,