Add endpoint to retrieve people who have a certain badge
This commit is contained in:
parent
ace4c6bee0
commit
8a3dae0592
|
@ -97,6 +97,7 @@ func Start(conf common.Conf, dbO *sqlx.DB) *fhr.Router {
|
|||
r.Method("/api/v1/users/scores/best", v1.UserScoresBestGET)
|
||||
r.Method("/api/v1/users/scores/recent", v1.UserScoresRecentGET)
|
||||
r.Method("/api/v1/badges", v1.BadgesGET)
|
||||
r.Method("/api/v1/badges/members", v1.BadgeMembersGET)
|
||||
r.Method("/api/v1/beatmaps", v1.BeatmapGET)
|
||||
r.Method("/api/v1/leaderboard", v1.LeaderboardGET)
|
||||
r.Method("/api/v1/tokens", v1.TokenGET)
|
||||
|
|
|
@ -48,3 +48,35 @@ func BadgesGET(md common.MethodData) common.CodeMessager {
|
|||
r.ResponseBase.Code = 200
|
||||
return r
|
||||
}
|
||||
|
||||
type badgeMembersData struct {
|
||||
common.ResponseBase
|
||||
Members []userData `json:"members"`
|
||||
}
|
||||
|
||||
// BadgeMembersGET retrieves the people who have a certain badge.
|
||||
func BadgeMembersGET(md common.MethodData) common.CodeMessager {
|
||||
i := common.Int(md.Query("id"))
|
||||
if i == 0 {
|
||||
return ErrMissingField("id")
|
||||
}
|
||||
|
||||
var members badgeMembersData
|
||||
|
||||
err := md.DB.Select(&members.Members, `SELECT users.id, users.username, register_datetime, users.privileges,
|
||||
latest_activity, users_stats.username_aka,
|
||||
users_stats.country
|
||||
FROM user_badges ub
|
||||
INNER JOIN users ON users.id = ub.user
|
||||
INNER JOIN users_stats ON users_stats.id = ub.user
|
||||
WHERE badge = ?
|
||||
ORDER BY id ASC `+common.Paginate(md.Query("p"), md.Query("l"), 50), i)
|
||||
|
||||
if err != nil {
|
||||
md.Err(err)
|
||||
return Err500
|
||||
}
|
||||
|
||||
members.Code = 200
|
||||
return members
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user