2016-05-28 18:24:39 +00:00
|
|
|
package peppy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"git.zxq.co/ripple/rippleapi/common"
|
|
|
|
"git.zxq.co/x/getrank"
|
|
|
|
"github.com/gin-gonic/gin"
|
2016-08-15 11:45:42 +00:00
|
|
|
"github.com/jmoiron/sqlx"
|
2016-05-28 18:24:39 +00:00
|
|
|
"gopkg.in/thehowl/go-osuapi.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetUserRecent retrieves an user's recent scores.
|
2016-08-15 11:45:42 +00:00
|
|
|
func GetUserRecent(c *gin.Context, db *sqlx.DB) {
|
2016-05-28 18:24:39 +00:00
|
|
|
getUserX(c, db, "ORDER BY scores.time DESC", common.InString(1, c.Query("limit"), 50, 10))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetUserBest retrieves an user's best scores.
|
2016-08-15 11:45:42 +00:00
|
|
|
func GetUserBest(c *gin.Context, db *sqlx.DB) {
|
2016-05-28 18:24:39 +00:00
|
|
|
var sb string
|
2016-08-15 19:13:40 +00:00
|
|
|
if rankable(c.Query("m")) {
|
2016-05-28 18:24:39 +00:00
|
|
|
sb = "scores.pp"
|
|
|
|
} else {
|
|
|
|
sb = "scores.score"
|
|
|
|
}
|
2016-05-28 18:31:46 +00:00
|
|
|
getUserX(c, db, "AND completed = '3' ORDER BY "+sb+" DESC", common.InString(1, c.Query("limit"), 100, 10))
|
2016-05-28 18:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:45:42 +00:00
|
|
|
func getUserX(c *gin.Context, db *sqlx.DB, orderBy string, limit int) {
|
2016-05-28 18:24:39 +00:00
|
|
|
whereClause, p := genUser(c, db)
|
|
|
|
query := fmt.Sprintf(
|
2016-07-03 19:55:03 +00:00
|
|
|
`SELECT
|
2016-05-28 18:24:39 +00:00
|
|
|
beatmaps.beatmap_id, scores.score, scores.max_combo,
|
|
|
|
scores.300_count, scores.100_count, scores.50_count,
|
|
|
|
scores.gekis_count, scores.katus_count, scores.misses_count,
|
|
|
|
scores.full_combo, scores.mods, users.id, scores.time,
|
|
|
|
scores.pp, scores.accuracy
|
|
|
|
FROM scores
|
|
|
|
LEFT JOIN beatmaps ON beatmaps.beatmap_md5 = scores.beatmap_md5
|
2016-05-28 21:48:29 +00:00
|
|
|
LEFT JOIN users ON scores.userid = users.id
|
2016-07-03 19:55:03 +00:00
|
|
|
WHERE %s AND scores.play_mode = ? AND users.privileges & 1 > 0
|
2016-05-28 18:24:39 +00:00
|
|
|
%s
|
|
|
|
LIMIT %d`, whereClause, orderBy, limit,
|
|
|
|
)
|
|
|
|
scores := make([]osuapi.GUSScore, 0, limit)
|
|
|
|
m := genmodei(c.Query("m"))
|
|
|
|
rows, err := db.Query(query, p, m)
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(200, defaultResponse)
|
|
|
|
c.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for rows.Next() {
|
|
|
|
var (
|
|
|
|
curscore osuapi.GUSScore
|
2016-08-19 15:02:51 +00:00
|
|
|
rawTime common.UnixTimestamp
|
2016-05-28 18:24:39 +00:00
|
|
|
acc float64
|
|
|
|
fc bool
|
|
|
|
mods int
|
2016-05-28 18:31:46 +00:00
|
|
|
bid *int
|
2016-05-28 18:24:39 +00:00
|
|
|
)
|
|
|
|
err := rows.Scan(
|
2016-05-28 18:31:46 +00:00
|
|
|
&bid, &curscore.Score.Score, &curscore.MaxCombo,
|
2016-05-28 18:24:39 +00:00
|
|
|
&curscore.Count300, &curscore.Count100, &curscore.Count50,
|
|
|
|
&curscore.CountGeki, &curscore.CountKatu, &curscore.CountMiss,
|
|
|
|
&fc, &mods, &curscore.UserID, &rawTime,
|
|
|
|
&curscore.PP, &acc,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(200, defaultResponse)
|
|
|
|
c.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2016-05-28 18:31:46 +00:00
|
|
|
if bid == nil {
|
|
|
|
curscore.BeatmapID = 0
|
|
|
|
} else {
|
|
|
|
curscore.BeatmapID = *bid
|
|
|
|
}
|
2016-05-28 18:24:39 +00:00
|
|
|
curscore.FullCombo = osuapi.OsuBool(fc)
|
|
|
|
curscore.Mods = osuapi.Mods(mods)
|
2016-08-19 15:02:51 +00:00
|
|
|
curscore.Date = osuapi.MySQLDate(rawTime)
|
2016-05-28 18:24:39 +00:00
|
|
|
curscore.Rank = strings.ToUpper(getrank.GetRank(
|
|
|
|
osuapi.Mode(m),
|
|
|
|
curscore.Mods,
|
|
|
|
acc,
|
|
|
|
curscore.Count300,
|
|
|
|
curscore.Count100,
|
|
|
|
curscore.Count50,
|
|
|
|
curscore.CountMiss,
|
|
|
|
))
|
|
|
|
scores = append(scores, curscore)
|
|
|
|
}
|
|
|
|
c.JSON(200, scores)
|
|
|
|
}
|