Skip to content

Commit

Permalink
Merge pull request #62 from Quaver/game-mode-ranking-queue
Browse files Browse the repository at this point in the history
Add game_mode to ranking queue comment actions
  • Loading branch information
Swan authored Aug 14, 2024
2 parents 6b4a909 + 12755b6 commit 2fb368f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions db/mapset_ranking_queue_comments.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"github.com/Quaver/api2/enums"
"gorm.io/gorm"
"time"
)
Expand All @@ -27,6 +28,7 @@ type MapsetRankingQueueComment struct {
Comment string `gorm:"comment" json:"comment"`
DateLastUpdated int64 `gorm:"date_last_updated" json:"-"`
DateLastUpdatedJSON time.Time `gorm:"-:all" json:"date_last_updated"`
GameMode *enums.GameMode `gorm:"column:game_mode" json:"game_mode"`
User *User `gorm:"foreignKey:UserId; references:Id" json:"user,omitempty"`
}

Expand All @@ -42,6 +44,10 @@ func (c *MapsetRankingQueueComment) AfterFind(*gorm.DB) (err error) {

// Insert Inserts a ranking queue comment into the database
func (c *MapsetRankingQueueComment) Insert() error {
if *c.GameMode <= 0 {
c.GameMode = nil
}

c.Timestamp = time.Now().UnixMilli()
c.DateLastUpdated = time.Now().UnixMilli()

Expand Down
9 changes: 8 additions & 1 deletion handlers/ranking_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type rankingQueueRequestData struct {
User *db.User
QueueMapset *db.RankingQueueMapset
Comment string
GameMode enums.GameMode
}

// Validates and returns common data used for ranking queue action requests
Expand All @@ -33,7 +34,8 @@ func validateRankingQueueRequest(c *gin.Context) (*rankingQueueRequestData, *API
}

body := struct {
Comment string `form:"comment" json:"comment" binding:"required"`
Comment string `form:"comment" json:"comment" binding:"required"`
GameMode enums.GameMode `form:"game_mode" json:"game_mode"`
}{}

if err := c.ShouldBind(&body); err != nil {
Expand Down Expand Up @@ -63,6 +65,7 @@ func validateRankingQueueRequest(c *gin.Context) (*rankingQueueRequestData, *API
User: user,
QueueMapset: queueMapset,
Comment: body.Comment,
GameMode: body.GameMode,
}, nil
}

Expand Down Expand Up @@ -112,6 +115,7 @@ func VoteForRankingQueueMapset(c *gin.Context) *APIError {
ActionType: db.RankingQueueActionVote,
IsActive: true,
Comment: data.Comment,
GameMode: &data.GameMode,
}

existingVotes = append(existingVotes, newVoteAction)
Expand Down Expand Up @@ -204,6 +208,7 @@ func DenyRankingQueueMapset(c *gin.Context) *APIError {
ActionType: db.RankingQueueActionDeny,
IsActive: true,
Comment: data.Comment,
GameMode: &data.GameMode,
}

if err := denyAction.Insert(); err != nil {
Expand Down Expand Up @@ -259,6 +264,7 @@ func BlacklistRankingQueueMapset(c *gin.Context) *APIError {
ActionType: db.RankingQueueActionBlacklist,
IsActive: true,
Comment: data.Comment,
GameMode: &data.GameMode,
}

if err := blacklistAction.Insert(); err != nil {
Expand Down Expand Up @@ -307,6 +313,7 @@ func OnHoldRankingQueueMapset(c *gin.Context) *APIError {
ActionType: db.RankingQueueActionOnHold,
IsActive: true,
Comment: data.Comment,
GameMode: &data.GameMode,
}

if err := onHoldAction.Insert(); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion handlers/ranking_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func AddRankingQueueComment(c *gin.Context) *APIError {
}

body := struct {
Comment string `form:"comment" json:"comment" binding:"required"`
Comment string `form:"comment" json:"comment" binding:"required"`
GameMode enums.GameMode `form:"game_mode" json:"game_mode"`
}{}

if err := c.ShouldBind(&body); err != nil {
Expand Down Expand Up @@ -74,6 +75,7 @@ func AddRankingQueueComment(c *gin.Context) *APIError {
UserId: user.Id,
MapsetId: queueMapset.MapsetId,
Comment: body.Comment,
GameMode: &body.GameMode,
IsActive: true,
}

Expand Down

0 comments on commit 2fb368f

Please sign in to comment.