From e80e557f10763f1c4a88500a72dc31b25c4d9159 Mon Sep 17 00:00:00 2001 From: Howl Date: Fri, 2 Sep 2016 17:00:36 +0200 Subject: [PATCH] Add custom badge in users/full --- app/v1/badge.go | 2 +- app/v1/user.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/v1/badge.go b/app/v1/badge.go index 04aaa5c..f01c365 100644 --- a/app/v1/badge.go +++ b/app/v1/badge.go @@ -7,7 +7,7 @@ import ( ) type singleBadge struct { - ID int `json:"id"` + ID int `json:"id,omitempty"` Name string `json:"name"` Icon string `json:"icon"` } diff --git a/app/v1/user.go b/app/v1/user.go index 8f31c57..bc6a731 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -110,6 +110,7 @@ type userFullResponse struct { PlayStyle int `json:"play_style"` FavouriteMode int `json:"favourite_mode"` Badges []singleBadge `json:"badges"` + CustomBadge *singleBadge `json:"custom_badge"` } // UserFullGET gets all of an user's information, with one exception: their userpage. @@ -126,6 +127,9 @@ SELECT users_stats.username_aka, users_stats.country, users_stats.play_style, users_stats.favourite_mode, + users_stats.custom_badge_icon, users_stats.custom_badge_name, users_stats.can_custom_badge, + users_stats.show_custom_badge, + users_stats.ranked_score_std, users_stats.total_score_std, users_stats.playcount_std, users_stats.replays_watched_std, users_stats.total_hits_std, users_stats.avg_accuracy_std, users_stats.pp_std, leaderboard_std.position as std_position, @@ -158,12 +162,19 @@ LIMIT 1 ` // Fuck. r := userFullResponse{} + var ( + b singleBadge + can bool + show bool + ) err := md.DB.QueryRow(query, param).Scan( &r.ID, &r.Username, &r.RegisteredOn, &r.Privileges, &r.LatestActivity, &r.UsernameAKA, &r.Country, &r.PlayStyle, &r.FavouriteMode, + &b.Icon, &b.Name, &can, &show, + &r.STD.RankedScore, &r.STD.TotalScore, &r.STD.PlayCount, &r.STD.ReplaysWatched, &r.STD.TotalHits, &r.STD.Accuracy, &r.STD.PP, &r.STD.GlobalLeaderboardRank, @@ -188,6 +199,10 @@ LIMIT 1 return Err500 } + if can && show && (b.Name != "" || b.Icon != "") { + r.CustomBadge = &b + } + for _, m := range []*modeData{&r.STD, &r.Taiko, &r.CTB, &r.Mania} { m.Level = ocl.GetLevelPrecise(int64(m.TotalScore)) }