From 12755b697ecc1422746598deb68e18de47a111b9 Mon Sep 17 00:00:00 2001 From: Swan Date: Wed, 14 Aug 2024 10:22:23 -0400 Subject: [PATCH] Add game_mode to ranking queue comment actions --- db/mapset_ranking_queue_comments.go | 6 ++++++ handlers/ranking_actions.go | 9 ++++++++- handlers/ranking_comments.go | 4 +++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/db/mapset_ranking_queue_comments.go b/db/mapset_ranking_queue_comments.go index a80778b..e94a955 100644 --- a/db/mapset_ranking_queue_comments.go +++ b/db/mapset_ranking_queue_comments.go @@ -1,6 +1,7 @@ package db import ( + "github.com/Quaver/api2/enums" "gorm.io/gorm" "time" ) @@ -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"` } @@ -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() diff --git a/handlers/ranking_actions.go b/handlers/ranking_actions.go index 4dda928..40347b2 100644 --- a/handlers/ranking_actions.go +++ b/handlers/ranking_actions.go @@ -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 @@ -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 { @@ -63,6 +65,7 @@ func validateRankingQueueRequest(c *gin.Context) (*rankingQueueRequestData, *API User: user, QueueMapset: queueMapset, Comment: body.Comment, + GameMode: body.GameMode, }, nil } @@ -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) @@ -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 { @@ -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 { @@ -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 { diff --git a/handlers/ranking_comments.go b/handlers/ranking_comments.go index 24a25a7..511be48 100644 --- a/handlers/ranking_comments.go +++ b/handlers/ranking_comments.go @@ -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 { @@ -74,6 +75,7 @@ func AddRankingQueueComment(c *gin.Context) *APIError { UserId: user.Id, MapsetId: queueMapset.MapsetId, Comment: body.Comment, + GameMode: &body.GameMode, IsActive: true, }