Skip to content

Commit

Permalink
Add endpoint to get a single ranking queue mapset
Browse files Browse the repository at this point in the history
  • Loading branch information
Swan committed Aug 13, 2024
1 parent 09c0a42 commit 0e7e17a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func initializeRoutes(engine *gin.Engine) {
engine.GET("/v2/ranking/config", handlers.CreateHandler(handlers.GetRankingQueueConfig))
engine.GET("/v2/ranking/queue/mode/:mode", handlers.CreateHandler(handlers.GetRankingQueue))
engine.GET("/v2/ranking/queue/supervisors/actions", middleware.RequireAuth, handlers.CreateHandler(handlers.GetRankingSupervisorActions))
engine.GET("/v2/ranking/queue/:id", handlers.CreateHandler(handlers.GetRankingQueueMapset))
engine.POST("/v2/ranking/queue/:id/submit", middleware.RequireAuth, handlers.CreateHandler(handlers.SubmitMapsetToRankingQueue))
engine.POST("/v2/ranking/queue/:id/remove", middleware.RequireAuth, handlers.CreateHandler(handlers.RemoveFromRankingQueue))
engine.GET("/v2/ranking/queue/:id/comments", handlers.CreateHandler(handlers.GetRankingQueueComments))
Expand Down
4 changes: 2 additions & 2 deletions db/mapset_ranking_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type RankingQueueMapset struct {
NeedsAttention bool `gorm:"column:needs_attention" json:"-"`
VoteCount int `gorm:"-:all" json:"-"`
Mapset *Mapset `gorm:"foreignKey:MapsetId; references:Id" json:"mapset"`
Votes []*MapsetRankingQueueComment `gorm:"-:all" json:"votes"`
Denies []*MapsetRankingQueueComment `gorm:"-:all" json:"denies"`
Votes []*MapsetRankingQueueComment `gorm:"-:all" json:"votes,omitempty"`
Denies []*MapsetRankingQueueComment `gorm:"-:all" json:"denies,omitempty"`

Comments []*MapsetRankingQueueComment `gorm:"foreignKey:MapsetId; references:MapsetId" json:"-"`
}
Expand Down
23 changes: 23 additions & 0 deletions handlers/ranking.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ func GetRankingQueue(c *gin.Context) *APIError {
return nil
}

// GetRankingQueueMapset Gets a single mapset in the ranking queue
// Endpoint: GET /v2/ranking/queue/:id
func GetRankingQueueMapset(c *gin.Context) *APIError {
id, err := strconv.Atoi(c.Param("id"))

if err != nil {
return APIErrorBadRequest("You must provide a valid mapset id")
}

mapset, err := db.GetRankingQueueMapset(id)

if err != nil && err != gorm.ErrRecordNotFound {
return APIErrorServerError("Error retrieving ranking queue mapset", err)
}

if mapset == nil {
return APIErrorNotFound("Mapset")
}

c.JSON(http.StatusOK, gin.H{"ranking_queue_mapset": mapset})
return nil
}

// SubmitMapsetToRankingQueue Submits a mapsets to the ranking queue
// Endpoint: POST /v2/ranking/queue/:id/submit
func SubmitMapsetToRankingQueue(c *gin.Context) *APIError {
Expand Down

0 comments on commit 0e7e17a

Please sign in to comment.