diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-27 22:33:57 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-27 22:33:57 +0300 |
| commit | 87113c5fb4c539573a33114581debddecfc9ece9 (patch) | |
| tree | 5c02f05744b85c4218924fb802dcfae745c7a67d | |
| parent | feat: check for deleted records in users (#56) (diff) | |
| download | lphub-87113c5fb4c539573a33114581debddecfc9ece9.tar.gz lphub-87113c5fb4c539573a33114581debddecfc9ece9.tar.bz2 lphub-87113c5fb4c539573a33114581debddecfc9ece9.zip | |
feat: detailed logging, db changes (#55)
Former-commit-id: 74219281915f55ac46cff3795edd4364be84d561
| -rw-r--r-- | backend/database/init.sql | 3 | ||||
| -rw-r--r-- | backend/handlers/logs.go | 21 | ||||
| -rw-r--r-- | backend/handlers/mod.go | 29 |
3 files changed, 42 insertions, 11 deletions
diff --git a/backend/database/init.sql b/backend/database/init.sql index 9d7b68c..92ddb07 100644 --- a/backend/database/init.sql +++ b/backend/database/init.sql | |||
| @@ -50,7 +50,7 @@ CREATE TABLE map_routes ( | |||
| 50 | category_id SMALLINT NOT NULL, | 50 | category_id SMALLINT NOT NULL, |
| 51 | score_count SMALLINT NOT NULL, | 51 | score_count SMALLINT NOT NULL, |
| 52 | description TEXT NOT NULL, | 52 | description TEXT NOT NULL, |
| 53 | showcase TEXT NOT NULL, | 53 | showcase TEXT NOT NULL DEFAULT '-', |
| 54 | PRIMARY KEY (id), | 54 | PRIMARY KEY (id), |
| 55 | FOREIGN KEY (map_id) REFERENCES maps(id), | 55 | FOREIGN KEY (map_id) REFERENCES maps(id), |
| 56 | FOREIGN KEY (category_id) REFERENCES categories(id), | 56 | FOREIGN KEY (category_id) REFERENCES categories(id), |
| @@ -181,6 +181,7 @@ CREATE TABLE logs ( | |||
| 181 | user_id TEXT NOT NULL, | 181 | user_id TEXT NOT NULL, |
| 182 | type TEXT NOT NULL, | 182 | type TEXT NOT NULL, |
| 183 | description TEXT NOT NULL, | 183 | description TEXT NOT NULL, |
| 184 | message TEXT NOT NULL DEFAULT '-', | ||
| 184 | date TIMESTAMP NOT NULL DEFAULT now(), | 185 | date TIMESTAMP NOT NULL DEFAULT now(), |
| 185 | PRIMARY KEY (id), | 186 | PRIMARY KEY (id), |
| 186 | FOREIGN KEY (user_id) REFERENCES users(steam_id) | 187 | FOREIGN KEY (user_id) REFERENCES users(steam_id) |
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index 4c7b415..d0561bd 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go | |||
| @@ -25,10 +25,13 @@ const ( | |||
| 25 | LogDescriptionUserUpdateCountrySuccess string = "UpdateCountrySuccess" | 25 | LogDescriptionUserUpdateCountrySuccess string = "UpdateCountrySuccess" |
| 26 | LogDescriptionUserUpdateCountryFail string = "UpdateCountryFail" | 26 | LogDescriptionUserUpdateCountryFail string = "UpdateCountryFail" |
| 27 | 27 | ||
| 28 | LogDescriptionMapSummaryCreate string = "MapSummaryCreate" | 28 | LogDescriptionMapSummaryCreateSuccess string = "MapSummaryCreateSuccess" |
| 29 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" | 29 | LogDescriptionMapSummaryCreateFail string = "MapSummaryCreateFail" |
| 30 | LogDescriptionMapSummaryEditImage string = "MapSummaryEditImage" | 30 | LogDescriptionMapSummaryEditSuccess string = "MapSummaryEditSuccess" |
| 31 | LogDescriptionMapSummaryDelete string = "MapSummaryDelete" | 31 | LogDescriptionMapSummaryEditFail string = "MapSummaryEditFail" |
| 32 | LogDescriptionMapSummaryEditImage string = "MapSummaryEditImage" | ||
| 33 | LogDescriptionMapSummaryDeleteSuccess string = "MapSummaryDeleteSuccess" | ||
| 34 | LogDescriptionMapSummaryDeleteFail string = "MapSummaryDeleteFail" | ||
| 32 | 35 | ||
| 33 | LogDescriptionRecordSuccess string = "Success" | 36 | LogDescriptionRecordSuccess string = "Success" |
| 34 | LogDescriptionRecordFailInsertRecord string = "InsertRecordFail" | 37 | LogDescriptionRecordFailInsertRecord string = "InsertRecordFail" |
| @@ -177,9 +180,13 @@ func ScoreLogs(c *gin.Context) { | |||
| 177 | }) | 180 | }) |
| 178 | } | 181 | } |
| 179 | 182 | ||
| 180 | func CreateLog(user_id string, log_type string, log_description string) (err error) { | 183 | func CreateLog(userID string, logType string, logDescription string, logMessage ...string) (err error) { |
| 181 | sql := `INSERT INTO logs (user_id, "type", description) VALUES($1, $2, $3)` | 184 | message := "-" |
| 182 | _, err = database.DB.Exec(sql, user_id, log_type, log_description) | 185 | if len(logMessage) == 1 { |
| 186 | message = logMessage[0] | ||
| 187 | } | ||
| 188 | sql := `INSERT INTO logs (user_id, "type", description, message) VALUES($1, $2, $3, $4)` | ||
| 189 | _, err = database.DB.Exec(sql, userID, logType, logDescription, message) | ||
| 183 | if err != nil { | 190 | if err != nil { |
| 184 | return err | 191 | return err |
| 185 | } | 192 | } |
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go index 3559887..b8b6f9f 100644 --- a/backend/handlers/mod.go +++ b/backend/handlers/mod.go | |||
| @@ -62,17 +62,20 @@ func CreateMapSummary(c *gin.Context) { | |||
| 62 | id := c.Param("mapid") | 62 | id := c.Param("mapid") |
| 63 | mapID, err := strconv.Atoi(id) | 63 | mapID, err := strconv.Atoi(id) |
| 64 | if err != nil { | 64 | if err != nil { |
| 65 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "ATOI: "+err.Error()) | ||
| 65 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 66 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 66 | return | 67 | return |
| 67 | } | 68 | } |
| 68 | var request CreateMapSummaryRequest | 69 | var request CreateMapSummaryRequest |
| 69 | if err := c.BindJSON(&request); err != nil { | 70 | if err := c.BindJSON(&request); err != nil { |
| 71 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "BIND: "+err.Error()) | ||
| 70 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 72 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 71 | return | 73 | return |
| 72 | } | 74 | } |
| 73 | // Start database transaction | 75 | // Start database transaction |
| 74 | tx, err := database.DB.Begin() | 76 | tx, err := database.DB.Begin() |
| 75 | if err != nil { | 77 | if err != nil { |
| 78 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "TX#B: "+err.Error()) | ||
| 76 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 79 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 77 | return | 80 | return |
| 78 | } | 81 | } |
| @@ -82,6 +85,7 @@ func CreateMapSummary(c *gin.Context) { | |||
| 82 | sql := `SELECT m.id FROM maps m WHERE m.id = $1` | 85 | sql := `SELECT m.id FROM maps m WHERE m.id = $1` |
| 83 | err = database.DB.QueryRow(sql, mapID).Scan(&checkMapID) | 86 | err = database.DB.QueryRow(sql, mapID).Scan(&checkMapID) |
| 84 | if err != nil { | 87 | if err != nil { |
| 88 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "S#maps: "+err.Error()) | ||
| 85 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 89 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 86 | return | 90 | return |
| 87 | } | 91 | } |
| @@ -94,6 +98,7 @@ func CreateMapSummary(c *gin.Context) { | |||
| 94 | VALUES ($1,$2,$3,$4,$5)` | 98 | VALUES ($1,$2,$3,$4,$5)` |
| 95 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) | 99 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) |
| 96 | if err != nil { | 100 | if err != nil { |
| 101 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "I#map_routes: "+err.Error()) | ||
| 97 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 102 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 98 | return | 103 | return |
| 99 | } | 104 | } |
| @@ -101,14 +106,16 @@ func CreateMapSummary(c *gin.Context) { | |||
| 101 | VALUES ($1,$2,$3,$4,$5)` | 106 | VALUES ($1,$2,$3,$4,$5)` |
| 102 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate) | 107 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate) |
| 103 | if err != nil { | 108 | if err != nil { |
| 109 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "I#map_history: "+err.Error()) | ||
| 104 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 110 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 105 | return | 111 | return |
| 106 | } | 112 | } |
| 107 | if err = tx.Commit(); err != nil { | 113 | if err = tx.Commit(); err != nil { |
| 114 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "TX#C: "+err.Error()) | ||
| 108 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 115 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 109 | return | 116 | return |
| 110 | } | 117 | } |
| 111 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreate) | 118 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateSuccess) |
| 112 | c.JSON(http.StatusOK, models.Response{ | 119 | c.JSON(http.StatusOK, models.Response{ |
| 113 | Success: true, | 120 | Success: true, |
| 114 | Message: "Successfully created map summary.", | 121 | Message: "Successfully created map summary.", |
| @@ -142,17 +149,20 @@ func EditMapSummary(c *gin.Context) { | |||
| 142 | id := c.Param("mapid") | 149 | id := c.Param("mapid") |
| 143 | mapID, err := strconv.Atoi(id) | 150 | mapID, err := strconv.Atoi(id) |
| 144 | if err != nil { | 151 | if err != nil { |
| 152 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "ATOI: "+err.Error()) | ||
| 145 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 153 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 146 | return | 154 | return |
| 147 | } | 155 | } |
| 148 | var request EditMapSummaryRequest | 156 | var request EditMapSummaryRequest |
| 149 | if err := c.BindJSON(&request); err != nil { | 157 | if err := c.BindJSON(&request); err != nil { |
| 158 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "BIND: "+err.Error()) | ||
| 150 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 159 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 151 | return | 160 | return |
| 152 | } | 161 | } |
| 153 | // Start database transaction | 162 | // Start database transaction |
| 154 | tx, err := database.DB.Begin() | 163 | tx, err := database.DB.Begin() |
| 155 | if err != nil { | 164 | if err != nil { |
| 165 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "TX#B: "+err.Error()) | ||
| 156 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 166 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 157 | return | 167 | return |
| 158 | } | 168 | } |
| @@ -162,12 +172,14 @@ func EditMapSummary(c *gin.Context) { | |||
| 162 | 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` | 172 | 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` |
| 163 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) | 173 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) |
| 164 | if err != nil { | 174 | if err != nil { |
| 175 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "S#map_routes: "+err.Error()) | ||
| 165 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 176 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 166 | return | 177 | return |
| 167 | } | 178 | } |
| 168 | sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` | 179 | sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` |
| 169 | err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID) | 180 | err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID) |
| 170 | if err != nil { | 181 | if err != nil { |
| 182 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "S#map_history: "+err.Error()) | ||
| 171 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 183 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 172 | return | 184 | return |
| 173 | } | 185 | } |
| @@ -175,20 +187,23 @@ func EditMapSummary(c *gin.Context) { | |||
| 175 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` | 187 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` |
| 176 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) | 188 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) |
| 177 | if err != nil { | 189 | if err != nil { |
| 190 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "U#map_routes: "+err.Error()) | ||
| 178 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 191 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 179 | return | 192 | return |
| 180 | } | 193 | } |
| 181 | sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` | 194 | sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` |
| 182 | _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) | 195 | _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) |
| 183 | if err != nil { | 196 | if err != nil { |
| 197 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "U#map_history"+err.Error()) | ||
| 184 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 198 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 185 | return | 199 | return |
| 186 | } | 200 | } |
| 187 | if err = tx.Commit(); err != nil { | 201 | if err = tx.Commit(); err != nil { |
| 202 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "TX#C: "+err.Error()) | ||
| 188 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 203 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 189 | return | 204 | return |
| 190 | } | 205 | } |
| 191 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEdit) | 206 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditSuccess) |
| 192 | c.JSON(http.StatusOK, models.Response{ | 207 | c.JSON(http.StatusOK, models.Response{ |
| 193 | Success: true, | 208 | Success: true, |
| 194 | Message: "Successfully updated map summary.", | 209 | Message: "Successfully updated map summary.", |
| @@ -222,17 +237,20 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 222 | id := c.Param("mapid") | 237 | id := c.Param("mapid") |
| 223 | mapID, err := strconv.Atoi(id) | 238 | mapID, err := strconv.Atoi(id) |
| 224 | if err != nil { | 239 | if err != nil { |
| 240 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "ATOI: "+err.Error()) | ||
| 225 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 241 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 226 | return | 242 | return |
| 227 | } | 243 | } |
| 228 | var request DeleteMapSummaryRequest | 244 | var request DeleteMapSummaryRequest |
| 229 | if err := c.BindJSON(&request); err != nil { | 245 | if err := c.BindJSON(&request); err != nil { |
| 246 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "BIND: "+err.Error()) | ||
| 230 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 247 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 231 | return | 248 | return |
| 232 | } | 249 | } |
| 233 | // Start database transaction | 250 | // Start database transaction |
| 234 | tx, err := database.DB.Begin() | 251 | tx, err := database.DB.Begin() |
| 235 | if err != nil { | 252 | if err != nil { |
| 253 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "TX#B: "+err.Error()) | ||
| 236 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 254 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 237 | return | 255 | return |
| 238 | } | 256 | } |
| @@ -242,6 +260,7 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 242 | sql := `SELECT m.id, mr.score_count FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2` | 260 | sql := `SELECT m.id, mr.score_count FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2` |
| 243 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount) | 261 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount) |
| 244 | if err != nil { | 262 | if err != nil { |
| 263 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "S#map_routes: "+err.Error()) | ||
| 245 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 264 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 246 | return | 265 | return |
| 247 | } | 266 | } |
| @@ -252,6 +271,7 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 252 | sql = `SELECT mh.id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id INNER JOIN map_history mh ON m.id=mh.map_id WHERE m.id = $1 AND mr.id = $2 AND mh.score_count = $3` | 271 | sql = `SELECT mh.id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id INNER JOIN map_history mh ON m.id=mh.map_id WHERE m.id = $1 AND mr.id = $2 AND mh.score_count = $3` |
| 253 | err = database.DB.QueryRow(sql, mapID, request.RouteID, scoreCount).Scan(&mapHistoryID) | 272 | err = database.DB.QueryRow(sql, mapID, request.RouteID, scoreCount).Scan(&mapHistoryID) |
| 254 | if err != nil { | 273 | if err != nil { |
| 274 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "S#map_history: "+err.Error()) | ||
| 255 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 275 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 256 | return | 276 | return |
| 257 | } | 277 | } |
| @@ -259,20 +279,23 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 259 | sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` | 279 | sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` |
| 260 | _, err = tx.Exec(sql, request.RouteID) | 280 | _, err = tx.Exec(sql, request.RouteID) |
| 261 | if err != nil { | 281 | if err != nil { |
| 282 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "D#map_routes: "+err.Error()) | ||
| 262 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 283 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 263 | return | 284 | return |
| 264 | } | 285 | } |
| 265 | sql = `DELETE FROM map_history mh WHERE mh.id = $1` | 286 | sql = `DELETE FROM map_history mh WHERE mh.id = $1` |
| 266 | _, err = tx.Exec(sql, mapHistoryID) | 287 | _, err = tx.Exec(sql, mapHistoryID) |
| 267 | if err != nil { | 288 | if err != nil { |
| 289 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "D#map_history: "+err.Error()) | ||
| 268 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 290 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 269 | return | 291 | return |
| 270 | } | 292 | } |
| 271 | if err = tx.Commit(); err != nil { | 293 | if err = tx.Commit(); err != nil { |
| 294 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "TX#C: "+err.Error()) | ||
| 272 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 295 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 273 | return | 296 | return |
| 274 | } | 297 | } |
| 275 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDelete) | 298 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteSuccess) |
| 276 | c.JSON(http.StatusOK, models.Response{ | 299 | c.JSON(http.StatusOK, models.Response{ |
| 277 | Success: true, | 300 | Success: true, |
| 278 | Message: "Successfully delete map summary.", | 301 | Message: "Successfully delete map summary.", |