From 9481de5e4e13f7f62e5f1fc1f1e402e1f91d13f1 Mon Sep 17 00:00:00 2001 From: Howl Date: Sat, 14 May 2016 21:02:05 +0200 Subject: [PATCH] Merge /badges/:id into /badges --- app/start.go | 1 - app/v1/badge.go | 33 +++++++++++---------------------- app/v1/user_scores.go | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 app/v1/user_scores.go diff --git a/app/start.go b/app/start.go index 79c4461..5e21934 100644 --- a/app/start.go +++ b/app/start.go @@ -33,7 +33,6 @@ func Start(conf common.Conf, db *sql.DB) *gin.Engine { gv1.GET("/users/full", Method(v1.UserFullGET, db, common.PrivilegeRead)) gv1.GET("/users/userpage", Method(v1.UserUserpageGET, db, common.PrivilegeRead)) gv1.GET("/badges", Method(v1.BadgesGET, db, common.PrivilegeRead)) - gv1.GET("/badges/:id", Method(v1.BadgeByIDGET, db, common.PrivilegeRead)) // ReadConfidential privilege required gv1.GET("/friends", Method(v1.FriendsGET, db, common.PrivilegeReadConfidential)) diff --git a/app/v1/badge.go b/app/v1/badge.go index 1849b6d..33eac1f 100644 --- a/app/v1/badge.go +++ b/app/v1/badge.go @@ -12,26 +12,6 @@ type singleBadge struct { Icon string `json:"icon"` } -type badgeData struct { - common.ResponseBase - singleBadge -} - -// BadgeByIDGET is the handler for /badge/:id -func BadgeByIDGET(md common.MethodData) common.CodeMessager { - var b badgeData - err := md.DB.QueryRow("SELECT id, name, icon FROM badges WHERE id=? LIMIT 1", md.C.Param("id")).Scan(&b.ID, &b.Name, &b.Icon) - switch { - case err == sql.ErrNoRows: - return common.SimpleResponse(404, "No such badge was found") - case err != nil: - md.Err(err) - return Err500 - } - b.Code = 200 - return b -} - type multiBadgeData struct { common.ResponseBase Badges []singleBadge `json:"badges"` @@ -39,8 +19,17 @@ type multiBadgeData struct { // BadgesGET retrieves all the badges on this ripple instance. func BadgesGET(md common.MethodData) common.CodeMessager { - var r multiBadgeData - rows, err := md.DB.Query("SELECT id, name, icon FROM badges") + var ( + r multiBadgeData + rows *sql.Rows + err error + ) + if md.C.Query("id") != "" { + // TODO(howl): ID validation + rows, err = md.DB.Query("SELECT id, name, icon FROM badges WHERE id = ?", md.C.Query("id")) + } else { + rows, err = md.DB.Query("SELECT id, name, icon FROM badges") + } if err != nil { md.Err(err) return Err500 diff --git a/app/v1/user_scores.go b/app/v1/user_scores.go new file mode 100644 index 0000000..24144e7 --- /dev/null +++ b/app/v1/user_scores.go @@ -0,0 +1,21 @@ +package v1 + +import "time" + +type userScore struct { + ScoreID int `json:"score_id"` + BeatmapMD5 string `json:"beatmap_md5"` + Score int64 `json:"score"` + MaxCombo int `json:"max_combo"` + FullCombo bool `json:"full_combo"` + Mods int `json:"mods"` + Count300 int `json:"count_300"` + Count100 int `json:"count_100"` + Count50 int `json:"count_50"` + CountGeki int `json:"count_geki"` + CountKatu int `json:"count_katu"` + CountMiss int `json:"count_miss"` + Time time.Time `json:"time"` + PlayMode int `json:"play_mode"` + Accuracy float64 `json:"accuracy"` +}