From b9d35ac46df1bae04a2b7dd8dbdd79c490457c0d Mon Sep 17 00:00:00 2001 From: Howl Date: Mon, 15 Aug 2016 20:07:40 +0200 Subject: [PATCH] Add more where clauses because I forgot 'em --- app/peppy/score.go | 1 + app/v1/score.go | 28 +++++++++++++++++++++++++++- app/v1/user_scores.go | 25 ------------------------- 3 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 app/peppy/score.go diff --git a/app/peppy/score.go b/app/peppy/score.go new file mode 100644 index 0000000..3fdbc4b --- /dev/null +++ b/app/peppy/score.go @@ -0,0 +1 @@ +package peppy diff --git a/app/v1/score.go b/app/v1/score.go index 0512b44..9f6c162 100644 --- a/app/v1/score.go +++ b/app/v1/score.go @@ -2,6 +2,8 @@ package v1 import ( "database/sql" + "fmt" + "strconv" "git.zxq.co/ripple/rippleapi/common" ) @@ -81,7 +83,7 @@ SELECT FROM scores INNER JOIN users ON users.id = scores.userid INNER JOIN users_stats ON users_stats.id = scores.userid -WHERE scores.beatmap_md5 = ? AND scores.completed = '3' +WHERE scores.beatmap_md5 = ? AND scores.completed = '3' AND users.privileges & 1 > 0 `+genModeClause(md)+` `+sort+common.Paginate(md.Query("p"), md.Query("l"), 100), beatmapMD5) if err != nil { md.Err(err) @@ -113,3 +115,27 @@ WHERE scores.beatmap_md5 = ? AND scores.completed = '3' r.Code = 200 return r } + +func getMode(m string) string { + switch m { + case "1": + return "taiko" + case "2": + return "ctb" + case "3": + return "mania" + default: + return "std" + } +} + +func genModeClause(md common.MethodData) string { + var modeClause string + if md.Query("mode") != "" { + m, err := strconv.Atoi(md.Query("mode")) + if err == nil && m >= 0 && m <= 3 { + modeClause = fmt.Sprintf("AND scores.play_mode = '%d'", m) + } + } + return modeClause +} diff --git a/app/v1/user_scores.go b/app/v1/user_scores.go index a94bd73..1236d9b 100644 --- a/app/v1/user_scores.go +++ b/app/v1/user_scores.go @@ -2,7 +2,6 @@ package v1 import ( "fmt" - "strconv" "git.zxq.co/ripple/rippleapi/common" ) @@ -75,30 +74,6 @@ func UserScoresRecentGET(md common.MethodData) common.CodeMessager { ), param) } -func getMode(m string) string { - switch m { - case "1": - return "taiko" - case "2": - return "ctb" - case "3": - return "mania" - default: - return "std" - } -} - -func genModeClause(md common.MethodData) string { - var modeClause string - if md.Query("mode") != "" { - m, err := strconv.Atoi(md.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 {