Fix get_users returning no results if user doesn't have a leaderboard position

This commit is contained in:
Howl 2016-09-09 18:55:26 +02:00
parent 7249d9136b
commit 4be5948d97
2 changed files with 8 additions and 4 deletions

View File

@ -23,6 +23,7 @@ func GetUser(c *gin.Context, db *sqlx.DB) {
mode := genmode(c.Query("m")) mode := genmode(c.Query("m"))
var lbpos *int
err := db.QueryRow(fmt.Sprintf( err := db.QueryRow(fmt.Sprintf(
`SELECT `SELECT
users.id, users.username, users.id, users.username,
@ -38,7 +39,7 @@ func GetUser(c *gin.Context, db *sqlx.DB) {
), p).Scan( ), p).Scan(
&user.UserID, &user.Username, &user.UserID, &user.Username,
&user.Playcount, &user.RankedScore, &user.TotalScore, &user.Playcount, &user.RankedScore, &user.TotalScore,
&user.Rank, &user.PP, &user.Accuracy, &lbpos, &user.PP, &user.Accuracy,
&user.Country, &user.Country,
) )
if err != nil { if err != nil {
@ -48,6 +49,9 @@ func GetUser(c *gin.Context, db *sqlx.DB) {
} }
return return
} }
if lbpos != nil {
user.Rank = *lbpos
}
user.Level = ocl.GetLevelPrecise(user.TotalScore) user.Level = ocl.GetLevelPrecise(user.TotalScore)
c.JSON(200, []osuapi.User{user}) c.JSON(200, []osuapi.User{user})

View File

@ -8,7 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"github.com/getsentry/raven-go" raven "github.com/getsentry/raven-go"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -32,7 +32,7 @@ func Recovery(client *raven.Client, onlyCrashes bool) gin.HandlerFunc {
} }
ravenUser := &raven.User{ ravenUser := &raven.User{
ID: token, Username: token,
IP: c.Request.RemoteAddr, IP: c.Request.RemoteAddr,
} }