From 45c67cf9b79ac5dd67c3ce9f7dcd0da9e68a055c Mon Sep 17 00:00:00 2001 From: Howl Date: Wed, 18 May 2016 18:37:36 +0200 Subject: [PATCH] Start implementing get_beatmaps --- app/peppy/beatmap.go | 38 ++++++++++++++++++++++++++++++++++++++ app/peppy/common.go | 8 ++++---- app/peppy/user.go | 1 + 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 app/peppy/beatmap.go diff --git a/app/peppy/beatmap.go b/app/peppy/beatmap.go new file mode 100644 index 0000000..2467071 --- /dev/null +++ b/app/peppy/beatmap.go @@ -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 ") +} diff --git a/app/peppy/common.go b/app/peppy/common.go index 995756e..223f24d 100644 --- a/app/peppy/common.go +++ b/app/peppy/common.go @@ -31,7 +31,7 @@ func genUser(c *gin.Context, db *sql.DB) (string, string) { switch { // We know for sure that it's an username. case c.Query("type") == "string": - whereClause = "WHERE users.username = ?" + whereClause = "users.username = ?" p = c.Query("u") // It could be an user ID, so we look for an user with that username first. case err == nil: @@ -39,15 +39,15 @@ func genUser(c *gin.Context, db *sql.DB) (string, string) { if err == sql.ErrNoRows { // If no user with that userID were found, assume username. p = c.Query("u") - whereClause = "WHERE users.username = ?" + whereClause = "users.username = ?" } else { // 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. default: p = c.Query("u") - whereClause = "WHERE users.username = ?" + whereClause = "users.username = ?" } return whereClause, p } diff --git a/app/peppy/user.go b/app/peppy/user.go index 8c20391..aa644fa 100644 --- a/app/peppy/user.go +++ b/app/peppy/user.go @@ -18,6 +18,7 @@ func GetUser(c *gin.Context, db *sql.DB) { } var user osuapi.User whereClause, p := genUser(c, db) + whereClause = "WHERE " + whereClause mode := genmode(c.Query("m"))