ripple-api/app/v1/beatmap.go

97 lines
2.7 KiB
Go
Raw Normal View History

2016-04-27 18:03:06 +00:00
package v1
import "git.zxq.co/ripple/rippleapi/common"
type beatmap struct {
BeatmapID int `json:"beatmap_id"`
BeatmapsetID int `json:"beatmapset_id"`
2016-05-19 15:15:17 +00:00
BeatmapMD5 string `json:"beatmap_md5"`
SongName string `json:"song_name"`
2016-04-27 18:03:06 +00:00
AR float32 `json:"ar"`
OD float32 `json:"od"`
Difficulty float64 `json:"difficulty"`
MaxCombo int `json:"max_combo"`
HitLength int `json:"hit_length"`
Ranked int `json:"ranked"`
RankedStatusFrozen int `json:"ranked_status_frozen"`
LatestUpdate int `json:"latest_update"`
}
2016-05-19 15:15:17 +00:00
type beatmapMayOrMayNotExist struct {
BeatmapID *int
BeatmapsetID *int
BeatmapMD5 *string
SongName *string
AR *float32
OD *float32
Difficulty *float64
MaxCombo *int
HitLength *int
Ranked *int
RankedStatusFrozen *int
LatestUpdate *int
}
func (b *beatmapMayOrMayNotExist) toBeatmap() *beatmap {
if b.BeatmapID == nil {
return nil
}
return &beatmap{
BeatmapID: *b.BeatmapID,
BeatmapsetID: *b.BeatmapsetID,
BeatmapMD5: *b.BeatmapMD5,
SongName: *b.SongName,
AR: *b.AR,
OD: *b.OD,
Difficulty: *b.Difficulty,
MaxCombo: *b.MaxCombo,
HitLength: *b.HitLength,
Ranked: *b.Ranked,
RankedStatusFrozen: *b.RankedStatusFrozen,
LatestUpdate: *b.LatestUpdate,
}
}
2016-04-27 18:03:06 +00:00
type beatmapResponse struct {
common.ResponseBase
beatmap
}
type beatmapSetResponse struct {
common.ResponseBase
Beatmaps []beatmap `json:"beatmaps"`
}
type beatmapSetStatusData struct {
BeatmapSetID int `json:"beatmapset_id"`
RankedStatus int `json:"ranked_status"`
Frozen int `json:"frozen"`
}
// BeatmapSetStatusPOST changes the ranked status of a beatmap, and whether the beatmap ranked status is frozen. Or freezed. Freezed best meme 2k16
func BeatmapSetStatusPOST(md common.MethodData) common.CodeMessager {
var req beatmapSetStatusData
md.RequestData.Unmarshal(&req)
var miss []string
if req.BeatmapSetID == 0 {
miss = append(miss, "beatmapset_id")
}
if len(miss) != 0 {
return ErrMissingField(miss...)
}
if req.Frozen != 0 && req.Frozen != 1 {
return common.SimpleResponse(400, "frozen status must be either 0 or 1")
}
2016-04-27 19:03:16 +00:00
if req.RankedStatus > 4 || -1 > req.RankedStatus {
return common.SimpleResponse(400, "ranked status must be 5 < x < -2")
2016-04-27 18:03:06 +00:00
}
md.DB.Exec("UPDATE beatmaps SET ranked = ?, ranked_status_freezed = ? WHERE beatmapset_id = ?", req.RankedStatus, req.Frozen, req.BeatmapSetID)
// TODO: replace with beatmapSetResponse when implemented
return common.ResponseBase{
Code: 200,
}
}