From eff876fab9d6b52bad45fa67f97fb48ee1d60378 Mon Sep 17 00:00:00 2001 From: lenforiee Date: Thu, 28 Dec 2023 03:14:52 +0100 Subject: [PATCH] feat: include badge colour in badge query (#39) --- app/v1/badge.go | 7 ++++--- app/v1/user.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/v1/badge.go b/app/v1/badge.go index 19b7f36..c33d8ae 100644 --- a/app/v1/badge.go +++ b/app/v1/badge.go @@ -10,6 +10,7 @@ type singleBadge struct { ID int `json:"id,omitempty"` Name string `json:"name"` Icon string `json:"icon"` + Colour string `json:"colour"` } type multiBadgeData struct { @@ -25,9 +26,9 @@ func BadgesGET(md common.MethodData) common.CodeMessager { err error ) if md.Query("id") != "" { - rows, err = md.DB.Query("SELECT id, name, icon FROM badges WHERE id = ? LIMIT 1", md.Query("id")) + rows, err = md.DB.Query("SELECT id, name, icon, colour FROM badges WHERE id = ? LIMIT 1", md.Query("id")) } else { - rows, err = md.DB.Query("SELECT id, name, icon FROM badges " + common.Paginate(md.Query("p"), md.Query("l"), 50)) + rows, err = md.DB.Query("SELECT id, name, icon, colour FROM badges " + common.Paginate(md.Query("p"), md.Query("l"), 50)) } if err != nil { md.Err(err) @@ -36,7 +37,7 @@ func BadgesGET(md common.MethodData) common.CodeMessager { defer rows.Close() for rows.Next() { nb := singleBadge{} - err = rows.Scan(&nb.ID, &nb.Name, &nb.Icon) + err = rows.Scan(&nb.ID, &nb.Name, &nb.Icon, &nb.Colour) if err != nil { md.Err(err) } diff --git a/app/v1/user.go b/app/v1/user.go index 4a7c634..b372c9e 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -402,7 +402,7 @@ LIMIT 1 } r.Followers = follower - rows, err = md.DB.Query("SELECT b.id, b.name, b.icon FROM user_badges ub "+ + rows, err = md.DB.Query("SELECT b.id, b.name, b.icon, b.colour FROM user_badges ub "+ "LEFT JOIN badges b ON ub.badge = b.id WHERE user = ?", r.ID) if err != nil { md.Err(err) @@ -410,7 +410,7 @@ LIMIT 1 for rows.Next() { var badge singleBadge - err := rows.Scan(&badge.ID, &badge.Name, &badge.Icon) + err := rows.Scan(&badge.ID, &badge.Name, &badge.Icon, &badge.Colour) if err != nil { md.Err(err) continue