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/userpage", Method(v1.UserUserpageGET, common.PrivilegeRead))
|
||||||
gv1.GET("/users/lookup", Method(v1.UserLookupGET, 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/best", Method(v1.UserScoresBestGET, common.PrivilegeRead))
|
||||||
|
gv1.GET("/users/scores/recent", Method(v1.UserScoresRecentGET, common.PrivilegeRead))
|
||||||
gv1.GET("/badges", Method(v1.BadgesGET, common.PrivilegeRead))
|
gv1.GET("/badges", Method(v1.BadgesGET, common.PrivilegeRead))
|
||||||
|
|
||||||
// ReadConfidential privilege required
|
// ReadConfidential privilege required
|
||||||
|
|
|
@ -61,13 +61,6 @@ func UserScoresBestGET(md common.MethodData) common.CodeMessager {
|
||||||
if cm != nil {
|
if cm != nil {
|
||||||
return *cm
|
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(
|
return scoresPuts(md, fmt.Sprintf(
|
||||||
`WHERE
|
`WHERE
|
||||||
scores.completed = '3'
|
scores.completed = '3'
|
||||||
|
@ -75,7 +68,23 @@ func UserScoresBestGET(md common.MethodData) common.CodeMessager {
|
||||||
%s
|
%s
|
||||||
AND users.allowed = '1'
|
AND users.allowed = '1'
|
||||||
ORDER BY scores.pp DESC, scores.score DESC %s`,
|
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)
|
), 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 {
|
func scoresPuts(md common.MethodData, whereClause string, params ...interface{}) common.CodeMessager {
|
||||||
rows, err := md.DB.Query(userScoreSelectBase+whereClause, params...)
|
rows, err := md.DB.Query(userScoreSelectBase+whereClause, params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user