diff options
Diffstat (limited to '')
| -rw-r--r-- | backend/controllers/recordController.go | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index aa43d6b..cfd3e86 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go | |||
| @@ -43,11 +43,11 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 43 | return | 43 | return |
| 44 | } | 44 | } |
| 45 | // Check if map is sp or mp | 45 | // Check if map is sp or mp |
| 46 | var wrScore int | 46 | var gameID int |
| 47 | var wrTime int | ||
| 48 | var isCoop bool | 47 | var isCoop bool |
| 49 | var isDisabled bool | 48 | var isDisabled bool |
| 50 | err := database.DB.QueryRow(`SELECT wr_score, wr_time, is_coop, is_disabled FROM maps WHERE id = $1;`, mapId).Scan(&wrScore, &wrTime, &isCoop, &isDisabled) | 49 | sql := `SELECT game_id, is_disabled FROM maps WHERE id = $1;` |
| 50 | err := database.DB.QueryRow(sql, mapId).Scan(&gameID, &isDisabled) | ||
| 51 | if err != nil { | 51 | if err != nil { |
| 52 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 52 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 53 | return | 53 | return |
| @@ -56,6 +56,9 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 56 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) | 56 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) |
| 57 | return | 57 | return |
| 58 | } | 58 | } |
| 59 | if gameID == 2 { | ||
| 60 | isCoop = true | ||
| 61 | } | ||
| 59 | // Get record request | 62 | // Get record request |
| 60 | var record models.RecordRequest | 63 | var record models.RecordRequest |
| 61 | score_count, err := strconv.Atoi(c.PostForm("score_count")) | 64 | score_count, err := strconv.Atoi(c.PostForm("score_count")) |
| @@ -159,13 +162,13 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 159 | return | 162 | return |
| 160 | } | 163 | } |
| 161 | // If a new world record based on portal count | 164 | // If a new world record based on portal count |
| 162 | if record.ScoreCount < wrScore { | 165 | // if record.ScoreCount < wrScore { |
| 163 | _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) | 166 | // _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) |
| 164 | if err != nil { | 167 | // if err != nil { |
| 165 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 168 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 166 | return | 169 | // return |
| 167 | } | 170 | // } |
| 168 | } | 171 | // } |
| 169 | } else { | 172 | } else { |
| 170 | sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) | 173 | sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) |
| 171 | VALUES($1, $2, $3, $4, $5);` | 174 | VALUES($1, $2, $3, $4, $5);` |
| @@ -176,13 +179,13 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 176 | return | 179 | return |
| 177 | } | 180 | } |
| 178 | // If a new world record based on portal count | 181 | // If a new world record based on portal count |
| 179 | if record.ScoreCount < wrScore { | 182 | // if record.ScoreCount < wrScore { |
| 180 | _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) | 183 | // _, err := database.DB.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) |
| 181 | if err != nil { | 184 | // if err != nil { |
| 182 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 185 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 183 | return | 186 | // return |
| 184 | } | 187 | // } |
| 185 | } | 188 | // } |
| 186 | } | 189 | } |
| 187 | c.JSON(http.StatusOK, models.Response{ | 190 | c.JSON(http.StatusOK, models.Response{ |
| 188 | Success: true, | 191 | Success: true, |