diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-06-29 18:57:39 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-06-29 18:57:39 +0300 |
| commit | 41529b1d6938c52fcbc52aa50a186a0d368d70e5 (patch) | |
| tree | 4ee8e03cce386349473cec99c35c11b761c79cf9 /backend/controllers/modController.go | |
| parent | fix: map summary sql (diff) | |
| download | lphub-41529b1d6938c52fcbc52aa50a186a0d368d70e5.tar.gz lphub-41529b1d6938c52fcbc52aa50a186a0d368d70e5.tar.bz2 lphub-41529b1d6938c52fcbc52aa50a186a0d368d70e5.zip | |
feat: return back to single map summary edit
Former-commit-id: 853dd376267ea63e67b1e4e7041f4c5c5f1be380
Diffstat (limited to 'backend/controllers/modController.go')
| -rw-r--r-- | backend/controllers/modController.go | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index 7c258ef..5fe0f68 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go | |||
| @@ -55,34 +55,29 @@ func EditMapSummary(c *gin.Context) { | |||
| 55 | return | 55 | return |
| 56 | } | 56 | } |
| 57 | defer tx.Rollback() | 57 | defer tx.Rollback() |
| 58 | if request.Image != "" { | 58 | // Fetch route category and score count |
| 59 | tx.Exec(`UPDATE maps m SET image = $2 WHERE m.id = $1`, mapID, request.Image) | 59 | var categoryID, scoreCount int |
| 60 | } | 60 | sql := `SELECT mr.category_id, mr.score_count |
| 61 | for _, route := range request.Routes { | ||
| 62 | // Fetch route category and score count | ||
| 63 | var categoryID, scoreCount int | ||
| 64 | sql := `SELECT mr.category_id, mr.score_count | ||
| 65 | FROM map_routes mr | 61 | FROM map_routes mr |
| 66 | INNER JOIN maps m | 62 | INNER JOIN maps m |
| 67 | WHERE m.id = $1 AND mr.id = $2` | 63 | WHERE m.id = $1 AND mr.id = $2` |
| 68 | err = database.DB.QueryRow(sql, mapID, route.RouteID).Scan(&categoryID, &scoreCount) | 64 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) |
| 69 | if err != nil { | 65 | if err != nil { |
| 70 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 66 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 71 | return | 67 | return |
| 72 | } | 68 | } |
| 73 | // Update database with new data | 69 | // Update database with new data |
| 74 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` | 70 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` |
| 75 | _, err = tx.Exec(sql, route.RouteID, route.ScoreCount, route.Description, route.Showcase) | 71 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) |
| 76 | if err != nil { | 72 | if err != nil { |
| 77 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 73 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 78 | return | 74 | return |
| 79 | } | 75 | } |
| 80 | sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` | 76 | sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` |
| 81 | _, err = tx.Exec(sql, mapID, categoryID, route.UserName, route.ScoreCount, route.RecordDate) | 77 | _, err = tx.Exec(sql, mapID, categoryID, request.UserName, request.ScoreCount, request.RecordDate) |
| 82 | if err != nil { | 78 | if err != nil { |
| 83 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 79 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 84 | return | 80 | return |
| 85 | } | ||
| 86 | } | 81 | } |
| 87 | if err = tx.Commit(); err != nil { | 82 | if err = tx.Commit(); err != nil { |
| 88 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 83 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) |