Implement users/scores/recent
This commit is contained in:
parent
da2a36537e
commit
ce739a8ae5
|
@ -38,6 +38,7 @@ func Start(conf common.Conf, dbO *sql.DB) *gin.Engine {
|
|||
gv1.GET("/users/userpage", Method(v1.UserUserpageGET, common.PrivilegeRead))
|
||||
gv1.GET("/users/lookup", Method(v1.UserLookupGET, common.PrivilegeRead))
|
||||
gv1.GET("/users/scores/best", Method(v1.UserScoresBestGET, common.PrivilegeRead))
|
||||
gv1.GET("/users/scores/recent", Method(v1.UserScoresRecentGET, common.PrivilegeRead))
|
||||
gv1.GET("/badges", Method(v1.BadgesGET, common.PrivilegeRead))
|
||||
|
||||
// ReadConfidential privilege required
|
||||
|
|
|
@ -61,13 +61,6 @@ func UserScoresBestGET(md common.MethodData) common.CodeMessager {
|
|||
if cm != nil {
|
||||
return *cm
|
||||
}
|
||||
var modeClause string
|
||||
if md.C.Query("mode") != "" {
|
||||
m, err := strconv.Atoi(md.C.Query("mode"))
|
||||
if err == nil && m >= 0 && m <= 3 {
|
||||
modeClause = fmt.Sprintf("AND scores.play_mode = '%d'", m)
|
||||
}
|
||||
}
|
||||
return scoresPuts(md, fmt.Sprintf(
|
||||
`WHERE
|
||||
scores.completed = '3'
|
||||
|
@ -75,7 +68,23 @@ func UserScoresBestGET(md common.MethodData) common.CodeMessager {
|
|||
%s
|
||||
AND users.allowed = '1'
|
||||
ORDER BY scores.pp DESC, scores.score DESC %s`,
|
||||
wc, modeClause, common.Paginate(md.C.Query("p"), md.C.Query("l"), 100),
|
||||
wc, genModeClause(md), common.Paginate(md.C.Query("p"), md.C.Query("l"), 100),
|
||||
), param)
|
||||
}
|
||||
|
||||
// UserScoresRecentGET retrieves an user's latest scores.
|
||||
func UserScoresRecentGET(md common.MethodData) common.CodeMessager {
|
||||
cm, wc, param := whereClauseUser(md, "users")
|
||||
if cm != nil {
|
||||
return *cm
|
||||
}
|
||||
return scoresPuts(md, fmt.Sprintf(
|
||||
`WHERE
|
||||
%s
|
||||
%s
|
||||
AND users.allowed = '1'
|
||||
ORDER BY scores.time DESC %s`,
|
||||
wc, genModeClause(md), common.Paginate(md.C.Query("p"), md.C.Query("l"), 100),
|
||||
), param)
|
||||
}
|
||||
|
||||
|
@ -92,6 +101,17 @@ func getMode(m string) string {
|
|||
}
|
||||
}
|
||||
|
||||
func genModeClause(md common.MethodData) string {
|
||||
var modeClause string
|
||||
if md.C.Query("mode") != "" {
|
||||
m, err := strconv.Atoi(md.C.Query("mode"))
|
||||
if err == nil && m >= 0 && m <= 3 {
|
||||
modeClause = fmt.Sprintf("AND scores.play_mode = '%d'", m)
|
||||
}
|
||||
}
|
||||
return modeClause
|
||||
}
|
||||
|
||||
func scoresPuts(md common.MethodData, whereClause string, params ...interface{}) common.CodeMessager {
|
||||
rows, err := md.DB.Query(userScoreSelectBase+whereClause, params...)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user