Merge /badges/:id into /badges

This commit is contained in:
Howl 2016-05-14 21:02:05 +02:00
parent 4448fcdfdb
commit 9481de5e4e
3 changed files with 32 additions and 23 deletions

View File

@ -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))

View File

@ -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

21
app/v1/user_scores.go Normal file
View File

@ -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"`
}