From a337af807c13d5923e71eb23b4d83e6505a7f44d Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Wed, 12 Jul 2023 18:27:31 +0300 Subject: fix: logic error on editing map summary (#48) Former-commit-id: 406a95993a6210ed30f78ad3ea562b2f23e3310a --- backend/controllers/modController.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'backend/controllers') 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) { } defer tx.Rollback() // Fetch route category and score count - var categoryID, scoreCount int + var categoryID, scoreCount, historyID int 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` err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } + sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` + err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&historyID) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } // Update database with new data sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) @@ -157,8 +163,8 @@ func EditMapSummary(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` - _, err = tx.Exec(sql, mapID, categoryID, request.UserName, request.ScoreCount, request.RecordDate) + sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` + _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return -- cgit v1.2.3