diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-07-12 18:27:31 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-07-12 18:27:31 +0300 |
| commit | a337af807c13d5923e71eb23b4d83e6505a7f44d (patch) | |
| tree | 7f27959b7360974a41ece259fd4977679d259545 /backend/controllers | |
| parent | feat: edit map image (diff) | |
| download | lphub-a337af807c13d5923e71eb23b4d83e6505a7f44d.tar.gz lphub-a337af807c13d5923e71eb23b4d83e6505a7f44d.tar.bz2 lphub-a337af807c13d5923e71eb23b4d83e6505a7f44d.zip | |
fix: logic error on editing map summary (#48)
Former-commit-id: 406a95993a6210ed30f78ad3ea562b2f23e3310a
Diffstat (limited to 'backend/controllers')
| -rw-r--r-- | backend/controllers/modController.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index 98fb165..72f1a53 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go | |||
| @@ -143,13 +143,19 @@ func EditMapSummary(c *gin.Context) { | |||
| 143 | } | 143 | } |
| 144 | defer tx.Rollback() | 144 | defer tx.Rollback() |
| 145 | // Fetch route category and score count | 145 | // Fetch route category and score count |
| 146 | var categoryID, scoreCount int | 146 | var categoryID, scoreCount, historyID int |
| 147 | sql := `SELECT mr.category_id, mr.score_count FROM map_routes mr INNER JOIN maps m ON m.id = mr.map_id WHERE m.id = $1 AND mr.id = $2` | 147 | sql := `SELECT mr.category_id, mr.score_count FROM map_routes mr INNER JOIN maps m ON m.id = mr.map_id WHERE m.id = $1 AND mr.id = $2` |
| 148 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) | 148 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) |
| 149 | if err != nil { | 149 | if err != nil { |
| 150 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 150 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 151 | return | 151 | return |
| 152 | } | 152 | } |
| 153 | sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` | ||
| 154 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&historyID) | ||
| 155 | if err != nil { | ||
| 156 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 157 | return | ||
| 158 | } | ||
| 153 | // Update database with new data | 159 | // Update database with new data |
| 154 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` | 160 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` |
| 155 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) | 161 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) |
| @@ -157,8 +163,8 @@ func EditMapSummary(c *gin.Context) { | |||
| 157 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 163 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 158 | return | 164 | return |
| 159 | } | 165 | } |
| 160 | sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` | 166 | sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` |
| 161 | _, err = tx.Exec(sql, mapID, categoryID, request.UserName, request.ScoreCount, request.RecordDate) | 167 | _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) |
| 162 | if err != nil { | 168 | if err != nil { |
| 163 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 169 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 164 | return | 170 | return |