From cb6dd6de72da88a0e76e3cf75a9a79d921801f5d Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sun, 15 Jan 2023 10:49:20 +0300 Subject: also update maps table when a new world record is achieved --- backend/controllers/recordController.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index b212e1f..ca863bb 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go @@ -27,9 +27,11 @@ func CreateRecordWithDemo(c *gin.Context) { return } // Check if map is sp or mp + var wrScore int + var wrTime int var isCoop bool var isDisabled bool - err := database.DB.QueryRow(`SELECT is_coop, is_disabled FROM maps WHERE id = $1;`, mapId).Scan(&isCoop, &isDisabled) + err := database.DB.QueryRow(`SELECT wr_score, wr_time, is_coop, is_disabled FROM maps WHERE id = $1;`, mapId).Scan(&wrScore, &wrTime, &isCoop, &isDisabled) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return @@ -136,6 +138,14 @@ func CreateRecordWithDemo(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } + // If a new world record based on portal count + if record.ScoreCount < wrScore { + _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + } } else { sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) VALUES($1, $2, $3, $4, $5);` @@ -144,6 +154,14 @@ func CreateRecordWithDemo(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } + // If a new world record based on portal count + if record.ScoreCount < wrScore { + _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + } } c.JSON(http.StatusOK, models.Response{ Success: true, -- cgit v1.2.3