Add BeatmapsRankedFrozenFullGET, an endpoint to get all beatmaps having a frozen ranked status

This commit is contained in:
Howl 2016-06-08 23:33:08 +02:00
parent 9b821e3230
commit b1fc609706
2 changed files with 40 additions and 0 deletions

View File

@ -52,6 +52,7 @@ func Start(conf common.Conf, dbO *sql.DB) *gin.Engine {
// Admin: beatmap
gv1.POST("/beatmaps/set_status", Method(v1.BeatmapSetStatusPOST, common.PrivilegeBeatmap))
gv1.GET("/beatmaps/ranked_frozen_full", Method(v1.BeatmapRankedFrozenFullGET, common.PrivilegeBeatmap))
// Admin: user managing
gv1.POST("/users/manage/set_allowed", Method(v1.UserManageSetAllowedPOST, common.PrivilegeManageUser))

View File

@ -192,3 +192,42 @@ func getBeatmap(md common.MethodData, beatmapID int) common.CodeMessager {
r.beatmap = b
return r
}
type beatmapReduced struct {
BeatmapID int `json:"beatmap_id"`
BeatmapsetID int `json:"beatmapset_id"`
BeatmapMD5 string `json:"beatmap_md5"`
Ranked int `json:"ranked"`
RankedStatusFrozen int `json:"ranked_status_frozen"`
}
type beatmapRankedFrozenFullResponse struct {
common.ResponseBase
Beatmaps []beatmapReduced `json:"beatmaps"`
}
// BeatmapRankedFrozenFullGET retrieves all beatmaps with a certain
// ranked_status_freezed
func BeatmapRankedFrozenFullGET(md common.MethodData) common.CodeMessager {
rows, err := md.DB.Query(`
SELECT beatmap_id, beatmapset_id, beatmap_md5, ranked, ranked_status_freezed
FROM beatmaps
WHERE ranked_status_freezed = '1'
`)
if err != nil {
md.Err(err)
return Err500
}
var r beatmapRankedFrozenFullResponse
for rows.Next() {
var b beatmapReduced
err = rows.Scan(&b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5, &b.Ranked, &b.RankedStatusFrozen)
if err != nil {
md.Err(err)
continue
}
r.Beatmaps = append(r.Beatmaps, b)
}
r.Code = 200
return r
}