From 6924c9ddbf6bb76c045a54319da04f1e90df851a Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 10 Aug 2021 12:34:16 +0200 Subject: [PATCH] Added getPictures and getPicturesByUserId func --- routers/api/v1/picture/picture.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/picture/picture.go b/routers/api/v1/picture/picture.go index e3a5a8a..07508e9 100644 --- a/routers/api/v1/picture/picture.go +++ b/routers/api/v1/picture/picture.go @@ -73,11 +73,21 @@ func Save(c *fiber.Ctx) error { func GetPictures(c *fiber.Ctx) error { db := database.DB - log.Info("here") + pictures := []map[string]interface{}{} - pictures := &[]structs.Picture{} - - db.Find(pictures) + db.Model(structs.Picture{}).Select("user_id", "picture_id", "likes", "description").Find(&pictures) + + return c.JSON(pictures) +} + +func GetPicturesByUserId(c *fiber.Ctx) error { + db := database.DB + + log.Infoln("") + + pictures := []structs.APIPicture{} + + db.Model(structs.Picture{}).Where("user_id", c.Params("id")).Find(&pictures) return c.JSON(pictures) }