how do we not have querying by score id???
This commit is contained in:
parent
4470ca2e63
commit
21e3939b36
|
@ -49,14 +49,16 @@ type scoresResponse struct {
|
|||
// ScoresGET retrieves the top scores for a certain beatmap.
|
||||
func ScoresGET(md common.MethodData) common.CodeMessager {
|
||||
var (
|
||||
beatmapMD5 string
|
||||
r scoresResponse
|
||||
where = new(common.WhereClause)
|
||||
r scoresResponse
|
||||
)
|
||||
pm := md.Ctx.Request.URI().QueryArgs().PeekMulti
|
||||
switch {
|
||||
case md.Query("md5") != "":
|
||||
beatmapMD5 = md.Query("md5")
|
||||
where.In("beatmap_md5", pm("md5")...)
|
||||
case md.Query("b") != "":
|
||||
err := md.DB.Get(&beatmapMD5, "SELECT beatmap_md5 FROM beatmaps WHERE beatmap_id = ? LIMIT 1", md.Query("b"))
|
||||
var md5 string
|
||||
err := md.DB.Get(&md5, "SELECT beatmap_md5 FROM beatmaps WHERE beatmap_id = ? LIMIT 1", md.Query("b"))
|
||||
switch {
|
||||
case err == sql.ErrNoRows:
|
||||
r.Code = 200
|
||||
|
@ -65,9 +67,9 @@ func ScoresGET(md common.MethodData) common.CodeMessager {
|
|||
md.Err(err)
|
||||
return Err500
|
||||
}
|
||||
default:
|
||||
return ErrMissingField("md5|b")
|
||||
where.Where("beatmap_md5 = ?", md5)
|
||||
}
|
||||
where.In("scores.id", pm("id")...)
|
||||
|
||||
sort := common.Sort(md, common.SortConfiguration{
|
||||
Default: "scores.pp DESC, scores.score DESC",
|
||||
|
@ -75,6 +77,10 @@ func ScoresGET(md common.MethodData) common.CodeMessager {
|
|||
Allowed: []string{"pp", "score", "accuracy", "id"},
|
||||
})
|
||||
|
||||
where.Where(` scores.completed = '3' AND `+md.User.OnlyUserPublic(false)+` `+
|
||||
genModeClause(md)+` `+sort+common.Paginate(md.Query("p"), md.Query("l"), 100), "")
|
||||
where.Params = where.Params[:len(where.Params)-1]
|
||||
|
||||
rows, err := md.DB.Query(`
|
||||
SELECT
|
||||
scores.id, scores.beatmap_md5, scores.score,
|
||||
|
@ -89,9 +95,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' AND `+md.User.OnlyUserPublic(false)+
|
||||
` `+genModeClause(md)+`
|
||||
`+sort+common.Paginate(md.Query("p"), md.Query("l"), 100), beatmapMD5)
|
||||
`+where.Clause, where.Params...)
|
||||
if err != nil {
|
||||
md.Err(err)
|
||||
return Err500
|
||||
|
|
Loading…
Reference in New Issue
Block a user