Skip to content

Commit

Permalink
feat: include badge colour in badge query (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenforiee authored Dec 28, 2023
1 parent 47bf0ea commit eff876f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions app/v1/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions app/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ 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)
}

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
Expand Down

0 comments on commit eff876f

Please sign in to comment.