beatmap ranking in API

This commit is contained in:
Howl 2016-04-27 20:03:06 +02:00
parent 32029d963e
commit 3782ed3c7c
3 changed files with 73 additions and 1 deletions

View File

@ -46,6 +46,9 @@ func Start(conf common.Conf, db *sql.DB) *gin.Engine {
gv1.POST("/friends/del", Method(v1.FriendsDelPOST, db, common.PrivilegeWrite))
gv1.GET("/friends/del/:id", Method(v1.FriendsDelGET, db, common.PrivilegeWrite))
// Admin: beatmap
gv1.POST("/beatmaps/set_status", Method(v1.BeatmapSetStatusPOST, db, common.PrivilegeBeatmap))
// Admin: user managing
gv1.POST("/users/manage/set_allowed", Method(v1.UserManageSetAllowedPOST, db, common.PrivilegeManageUser))

61
app/v1/beatmap.go Normal file
View File

@ -0,0 +1,61 @@
package v1
import "git.zxq.co/ripple/rippleapi/common"
type beatmap struct {
BeatmapID int `json:"beatmap_id"`
BeatmapsetID int `json:"beatmapset_id"`
BeatmapMD5 int `json:"beatmap_md5"`
SongName int `json:"song_name"`
AR float32 `json:"ar"`
OD float32 `json:"od"`
Difficulty float64 `json:"difficulty"`
MaxCombo int `json:"max_combo"`
HitLength int `json:"hit_length"`
BPM float64 `json:"bpm"`
Ranked int `json:"ranked"`
RankedStatusFrozen int `json:"ranked_status_frozen"`
LatestUpdate int `json:"latest_update"`
}
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")
}
if req.RankedStatus > 3 || -2 > req.RankedStatus {
return common.SimpleResponse(400, "ranked status must be 4 < x < -3")
}
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,
}
}

View File

@ -16,6 +16,7 @@ const (
PrivilegeManageAPIKeys // admin permission to manage user permission, not only self permissions. Only ever do this if you completely trust the application, because this essentially means to put the entire ripple database in the hands of a (potentially evil?) application.
PrivilegeBlog // can do pretty much anything to the blog, and the documentation.
PrivilegeAPIMeta // can do /meta API calls. basically means they can restart the API server.
PrivilegeBeatmap // rank/unrank beatmaps. also BAT when implemented
)
// Privileges is a bitwise enum of the privileges of an user's API key.
@ -76,11 +77,16 @@ func (p Privileges) HasPrivilegeBlog() bool {
return p&PrivilegeBlog != 0
}
// HasPrivilegeAPIMeta returns whether the Blog privilege is included in the privileges.
// HasPrivilegeAPIMeta returns whether the APIMeta privilege is included in the privileges.
func (p Privileges) HasPrivilegeAPIMeta() bool {
return p&PrivilegeAPIMeta != 0
}
// HasPrivilegeBeatmap returns whether the Beatmap privilege is included in the privileges.
func (p Privileges) HasPrivilegeBeatmap() bool {
return p&PrivilegeBeatmap != 0
}
var privilegeString = [...]string{
"Read",
"ReadConfidential",
@ -94,6 +100,7 @@ var privilegeString = [...]string{
"ManageAPIKeys",
"Blog",
"APIMeta",
"Beatmap",
}
func (p Privileges) String() string {
@ -119,6 +126,7 @@ var privilegeMustBe = [...]int{
4,
3,
4,
4,
}
// CanOnly removes any privilege that the user has requested to have, but cannot have due to their rank.