aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/controllers/recordController.go20
1 files changed, 19 insertions, 1 deletions
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) {
27 return 27 return
28 } 28 }
29 // Check if map is sp or mp 29 // Check if map is sp or mp
30 var wrScore int
31 var wrTime int
30 var isCoop bool 32 var isCoop bool
31 var isDisabled bool 33 var isDisabled bool
32 err := database.DB.QueryRow(`SELECT is_coop, is_disabled FROM maps WHERE id = $1;`, mapId).Scan(&isCoop, &isDisabled) 34 err := database.DB.QueryRow(`SELECT wr_score, wr_time, is_coop, is_disabled FROM maps WHERE id = $1;`, mapId).Scan(&wrScore, &wrTime, &isCoop, &isDisabled)
33 if err != nil { 35 if err != nil {
34 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 36 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
35 return 37 return
@@ -136,6 +138,14 @@ func CreateRecordWithDemo(c *gin.Context) {
136 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 138 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
137 return 139 return
138 } 140 }
141 // If a new world record based on portal count
142 if record.ScoreCount < wrScore {
143 _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId)
144 if err != nil {
145 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
146 return
147 }
148 }
139 } else { 149 } else {
140 sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) 150 sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id)
141 VALUES($1, $2, $3, $4, $5);` 151 VALUES($1, $2, $3, $4, $5);`
@@ -144,6 +154,14 @@ func CreateRecordWithDemo(c *gin.Context) {
144 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 154 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
145 return 155 return
146 } 156 }
157 // If a new world record based on portal count
158 if record.ScoreCount < wrScore {
159 _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId)
160 if err != nil {
161 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
162 return
163 }
164 }
147 } 165 }
148 c.JSON(http.StatusOK, models.Response{ 166 c.JSON(http.StatusOK, models.Response{
149 Success: true, 167 Success: true,