Start implementing get_beatmaps
This commit is contained in:
parent
de2aeb338b
commit
45c67cf9b7
38
app/peppy/beatmap.go
Normal file
38
app/peppy/beatmap.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package peppy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetBeatmap retrieves general beatmap information.
|
||||||
|
func GetBeatmap(c *gin.Context, db *sql.DB) {
|
||||||
|
var whereClauses []string
|
||||||
|
var params []string
|
||||||
|
|
||||||
|
// since value is not stored, silently ignore
|
||||||
|
if c.Query("s") != "" {
|
||||||
|
whereClauses = append(whereClauses, "beatmaps.beatmapset_id = ?")
|
||||||
|
params = append(params, c.Query("s"))
|
||||||
|
}
|
||||||
|
if c.Query("b") != "" {
|
||||||
|
whereClauses = append(whereClauses, "beatmaps.beatmap_id = ?")
|
||||||
|
params = append(params, c.Query("b"))
|
||||||
|
}
|
||||||
|
if c.Query("u") != "" {
|
||||||
|
wc, p := genUser(c, db)
|
||||||
|
whereClauses = append(whereClauses, wc)
|
||||||
|
params = append(params, p)
|
||||||
|
}
|
||||||
|
// silently ignore m
|
||||||
|
// silently ignore a
|
||||||
|
if c.Query("h") != "" {
|
||||||
|
whereClauses = append(whereClauses, "beatmaps.beatmap_md5 = ?")
|
||||||
|
params = append(params, c.Query("h"))
|
||||||
|
}
|
||||||
|
|
||||||
|
//bm := osuapi.Beatmap{}
|
||||||
|
|
||||||
|
//db.Query("SELECT beatmaps.beatmapset_id, beatmaps.beatmap FROM ")
|
||||||
|
}
|
|
@ -31,7 +31,7 @@ func genUser(c *gin.Context, db *sql.DB) (string, string) {
|
||||||
switch {
|
switch {
|
||||||
// We know for sure that it's an username.
|
// We know for sure that it's an username.
|
||||||
case c.Query("type") == "string":
|
case c.Query("type") == "string":
|
||||||
whereClause = "WHERE users.username = ?"
|
whereClause = "users.username = ?"
|
||||||
p = c.Query("u")
|
p = c.Query("u")
|
||||||
// It could be an user ID, so we look for an user with that username first.
|
// It could be an user ID, so we look for an user with that username first.
|
||||||
case err == nil:
|
case err == nil:
|
||||||
|
@ -39,15 +39,15 @@ func genUser(c *gin.Context, db *sql.DB) (string, string) {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
// If no user with that userID were found, assume username.
|
// If no user with that userID were found, assume username.
|
||||||
p = c.Query("u")
|
p = c.Query("u")
|
||||||
whereClause = "WHERE users.username = ?"
|
whereClause = "users.username = ?"
|
||||||
} else {
|
} else {
|
||||||
// An user with that userID was found. Thus it's an userID.
|
// An user with that userID was found. Thus it's an userID.
|
||||||
whereClause = "WHERE users.id = ?"
|
whereClause = "users.id = ?"
|
||||||
}
|
}
|
||||||
// u contains letters, so it's an username.
|
// u contains letters, so it's an username.
|
||||||
default:
|
default:
|
||||||
p = c.Query("u")
|
p = c.Query("u")
|
||||||
whereClause = "WHERE users.username = ?"
|
whereClause = "users.username = ?"
|
||||||
}
|
}
|
||||||
return whereClause, p
|
return whereClause, p
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ func GetUser(c *gin.Context, db *sql.DB) {
|
||||||
}
|
}
|
||||||
var user osuapi.User
|
var user osuapi.User
|
||||||
whereClause, p := genUser(c, db)
|
whereClause, p := genUser(c, db)
|
||||||
|
whereClause = "WHERE " + whereClause
|
||||||
|
|
||||||
mode := genmode(c.Query("m"))
|
mode := genmode(c.Query("m"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user