beatmap ranking in API
This commit is contained in:
parent
32029d963e
commit
3782ed3c7c
|
@ -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.POST("/friends/del", Method(v1.FriendsDelPOST, db, common.PrivilegeWrite))
|
||||||
gv1.GET("/friends/del/:id", Method(v1.FriendsDelGET, 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
|
// Admin: user managing
|
||||||
gv1.POST("/users/manage/set_allowed", Method(v1.UserManageSetAllowedPOST, db, common.PrivilegeManageUser))
|
gv1.POST("/users/manage/set_allowed", Method(v1.UserManageSetAllowedPOST, db, common.PrivilegeManageUser))
|
||||||
|
|
||||||
|
|
61
app/v1/beatmap.go
Normal file
61
app/v1/beatmap.go
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.
|
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.
|
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.
|
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.
|
// 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
|
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 {
|
func (p Privileges) HasPrivilegeAPIMeta() bool {
|
||||||
return p&PrivilegeAPIMeta != 0
|
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{
|
var privilegeString = [...]string{
|
||||||
"Read",
|
"Read",
|
||||||
"ReadConfidential",
|
"ReadConfidential",
|
||||||
|
@ -94,6 +100,7 @@ var privilegeString = [...]string{
|
||||||
"ManageAPIKeys",
|
"ManageAPIKeys",
|
||||||
"Blog",
|
"Blog",
|
||||||
"APIMeta",
|
"APIMeta",
|
||||||
|
"Beatmap",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Privileges) String() string {
|
func (p Privileges) String() string {
|
||||||
|
@ -119,6 +126,7 @@ var privilegeMustBe = [...]int{
|
||||||
4,
|
4,
|
||||||
3,
|
3,
|
||||||
4,
|
4,
|
||||||
|
4,
|
||||||
}
|
}
|
||||||
|
|
||||||
// CanOnly removes any privilege that the user has requested to have, but cannot have due to their rank.
|
// CanOnly removes any privilege that the user has requested to have, but cannot have due to their rank.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user