Add more where clauses because I forgot 'em

This commit is contained in:
Howl 2016-08-15 20:07:40 +02:00
parent a6ca8de13e
commit b9d35ac46d
3 changed files with 28 additions and 26 deletions

1
app/peppy/score.go Normal file
View File

@ -0,0 +1 @@
package peppy

View File

@ -2,6 +2,8 @@ package v1
import ( import (
"database/sql" "database/sql"
"fmt"
"strconv"
"git.zxq.co/ripple/rippleapi/common" "git.zxq.co/ripple/rippleapi/common"
) )
@ -81,7 +83,7 @@ SELECT
FROM scores FROM scores
INNER JOIN users ON users.id = scores.userid INNER JOIN users ON users.id = scores.userid
INNER JOIN users_stats ON users_stats.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) `+sort+common.Paginate(md.Query("p"), md.Query("l"), 100), beatmapMD5)
if err != nil { if err != nil {
md.Err(err) md.Err(err)
@ -113,3 +115,27 @@ WHERE scores.beatmap_md5 = ? AND scores.completed = '3'
r.Code = 200 r.Code = 200
return r 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
}

View File

@ -2,7 +2,6 @@ package v1
import ( import (
"fmt" "fmt"
"strconv"
"git.zxq.co/ripple/rippleapi/common" "git.zxq.co/ripple/rippleapi/common"
) )
@ -75,30 +74,6 @@ func UserScoresRecentGET(md common.MethodData) common.CodeMessager {
), param) ), 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 { 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 {