diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/handlers/login.go | 8 | ||||
| -rw-r--r-- | backend/handlers/logs.go | 18 | ||||
| -rw-r--r-- | backend/handlers/mod.go | 9 | ||||
| -rw-r--r-- | backend/handlers/record.go | 44 | ||||
| -rw-r--r-- | backend/handlers/user.go | 4 |
5 files changed, 33 insertions, 50 deletions
diff --git a/backend/handlers/login.go b/backend/handlers/login.go index b0f5ef6..1a74166 100644 --- a/backend/handlers/login.go +++ b/backend/handlers/login.go | |||
| @@ -37,7 +37,7 @@ func Login(c *gin.Context) { | |||
| 37 | default: | 37 | default: |
| 38 | steamID, err := openID.ValidateAndGetID() | 38 | steamID, err := openID.ValidateAndGetID() |
| 39 | if err != nil { | 39 | if err != nil { |
| 40 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailValidate) | 40 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailValidate, err.Error()) |
| 41 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 41 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 42 | return | 42 | return |
| 43 | } | 43 | } |
| @@ -48,7 +48,7 @@ func Login(c *gin.Context) { | |||
| 48 | if checkSteamID == 0 { | 48 | if checkSteamID == 0 { |
| 49 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) | 49 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) |
| 50 | if err != nil { | 50 | if err != nil { |
| 51 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailSummary) | 51 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailSummary, err.Error()) |
| 52 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 52 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 53 | return | 53 | return |
| 54 | } | 54 | } |
| @@ -78,12 +78,12 @@ func Login(c *gin.Context) { | |||
| 78 | // Sign and get the complete encoded token as a string using the secret | 78 | // Sign and get the complete encoded token as a string using the secret |
| 79 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) | 79 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) |
| 80 | if err != nil { | 80 | if err != nil { |
| 81 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailToken) | 81 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailToken, err.Error()) |
| 82 | c.JSON(http.StatusOK, models.ErrorResponse("Failed to generate token.")) | 82 | c.JSON(http.StatusOK, models.ErrorResponse("Failed to generate token.")) |
| 83 | return | 83 | return |
| 84 | } | 84 | } |
| 85 | c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true) | 85 | c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true) |
| 86 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginSuccess) | 86 | // CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginSuccess) |
| 87 | c.Redirect(http.StatusTemporaryRedirect, "/") | 87 | c.Redirect(http.StatusTemporaryRedirect, "/") |
| 88 | // c.JSON(http.StatusOK, models.Response{ | 88 | // c.JSON(http.StatusOK, models.Response{ |
| 89 | // Success: true, | 89 | // Success: true, |
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index d0561bd..0a0b6be 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go | |||
| @@ -33,14 +33,16 @@ const ( | |||
| 33 | LogDescriptionMapSummaryDeleteSuccess string = "MapSummaryDeleteSuccess" | 33 | LogDescriptionMapSummaryDeleteSuccess string = "MapSummaryDeleteSuccess" |
| 34 | LogDescriptionMapSummaryDeleteFail string = "MapSummaryDeleteFail" | 34 | LogDescriptionMapSummaryDeleteFail string = "MapSummaryDeleteFail" |
| 35 | 35 | ||
| 36 | LogDescriptionRecordSuccess string = "Success" | 36 | LogDescriptionCreateRecordSuccess string = "CreateRecordSuccess" |
| 37 | LogDescriptionRecordFailInsertRecord string = "InsertRecordFail" | 37 | LogDescriptionCreateRecordInsertRecordFail string = "InsertRecordFail" |
| 38 | LogDescriptionRecordFailInsertDemo string = "InsertDemoFail" | 38 | LogDescriptionCreateRecordInsertDemoFail string = "InsertDemoFail" |
| 39 | LogDescriptionRecordFailProcessDemo string = "ProcessDemoFail" | 39 | LogDescriptionCreateRecordProcessDemoFail string = "ProcessDemoFail" |
| 40 | LogDescriptionRecordFailCreateDemo string = "CreateDemoFail" | 40 | LogDescriptionCreateRecordCreateDemoFail string = "CreateDemoFail" |
| 41 | LogDescriptionRecordFailOpenDemo string = "OpenDemoFail" | 41 | LogDescriptionCreateRecordOpenDemoFail string = "OpenDemoFail" |
| 42 | LogDescriptionRecordFailSaveDemo string = "SaveDemoFail" | 42 | LogDescriptionCreateRecordSaveDemoFail string = "SaveDemoFail" |
| 43 | LogDescriptionRecordFailInvalidRequest string = "InvalidRequestFail" | 43 | LogDescriptionCreateRecordInvalidRequestFail string = "InvalidRequestFail" |
| 44 | LogDescriptionDeleteRecordSuccess string = "DeleteRecordSuccess" | ||
| 45 | LogDescriptionDeleteRecordFail string = "DeleteRecordFail" | ||
| 44 | ) | 46 | ) |
| 45 | 47 | ||
| 46 | type Log struct { | 48 | type Log struct { |
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go index b8b6f9f..95b37c8 100644 --- a/backend/handlers/mod.go +++ b/backend/handlers/mod.go | |||
| @@ -62,7 +62,6 @@ 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()) | ||
| 66 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 65 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 67 | return | 66 | return |
| 68 | } | 67 | } |
| @@ -75,7 +74,6 @@ func CreateMapSummary(c *gin.Context) { | |||
| 75 | // Start database transaction | 74 | // Start database transaction |
| 76 | tx, err := database.DB.Begin() | 75 | tx, err := database.DB.Begin() |
| 77 | if err != nil { | 76 | if err != nil { |
| 78 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "TX#B: "+err.Error()) | ||
| 79 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 77 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 80 | return | 78 | return |
| 81 | } | 79 | } |
| @@ -111,7 +109,6 @@ func CreateMapSummary(c *gin.Context) { | |||
| 111 | return | 109 | return |
| 112 | } | 110 | } |
| 113 | if err = tx.Commit(); err != nil { | 111 | if err = tx.Commit(); err != nil { |
| 114 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "TX#C: "+err.Error()) | ||
| 115 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 112 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 116 | return | 113 | return |
| 117 | } | 114 | } |
| @@ -149,7 +146,6 @@ func EditMapSummary(c *gin.Context) { | |||
| 149 | id := c.Param("mapid") | 146 | id := c.Param("mapid") |
| 150 | mapID, err := strconv.Atoi(id) | 147 | mapID, err := strconv.Atoi(id) |
| 151 | if err != nil { | 148 | if err != nil { |
| 152 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "ATOI: "+err.Error()) | ||
| 153 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 149 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 154 | return | 150 | return |
| 155 | } | 151 | } |
| @@ -162,7 +158,6 @@ func EditMapSummary(c *gin.Context) { | |||
| 162 | // Start database transaction | 158 | // Start database transaction |
| 163 | tx, err := database.DB.Begin() | 159 | tx, err := database.DB.Begin() |
| 164 | if err != nil { | 160 | if err != nil { |
| 165 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "TX#B: "+err.Error()) | ||
| 166 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 161 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 167 | return | 162 | return |
| 168 | } | 163 | } |
| @@ -199,7 +194,6 @@ func EditMapSummary(c *gin.Context) { | |||
| 199 | return | 194 | return |
| 200 | } | 195 | } |
| 201 | if err = tx.Commit(); err != nil { | 196 | if err = tx.Commit(); err != nil { |
| 202 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "TX#C: "+err.Error()) | ||
| 203 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 197 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 204 | return | 198 | return |
| 205 | } | 199 | } |
| @@ -237,7 +231,6 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 237 | id := c.Param("mapid") | 231 | id := c.Param("mapid") |
| 238 | mapID, err := strconv.Atoi(id) | 232 | mapID, err := strconv.Atoi(id) |
| 239 | if err != nil { | 233 | if err != nil { |
| 240 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "ATOI: "+err.Error()) | ||
| 241 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 234 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 242 | return | 235 | return |
| 243 | } | 236 | } |
| @@ -250,7 +243,6 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 250 | // Start database transaction | 243 | // Start database transaction |
| 251 | tx, err := database.DB.Begin() | 244 | tx, err := database.DB.Begin() |
| 252 | if err != nil { | 245 | if err != nil { |
| 253 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "TX#B: "+err.Error()) | ||
| 254 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 246 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 255 | return | 247 | return |
| 256 | } | 248 | } |
| @@ -291,7 +283,6 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 291 | return | 283 | return |
| 292 | } | 284 | } |
| 293 | if err = tx.Commit(); err != nil { | 285 | if err = tx.Commit(); err != nil { |
| 294 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "TX#C: "+err.Error()) | ||
| 295 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 286 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 296 | return | 287 | return |
| 297 | } | 288 | } |
diff --git a/backend/handlers/record.go b/backend/handlers/record.go index 4b0fafa..2dbc766 100644 --- a/backend/handlers/record.go +++ b/backend/handlers/record.go | |||
| @@ -65,7 +65,6 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 65 | return | 65 | return |
| 66 | } | 66 | } |
| 67 | if isDisabled { | 67 | if isDisabled { |
| 68 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | ||
| 69 | c.JSON(http.StatusOK, models.ErrorResponse("Map is not available for competitive boards.")) | 68 | c.JSON(http.StatusOK, models.ErrorResponse("Map is not available for competitive boards.")) |
| 70 | return | 69 | return |
| 71 | } | 70 | } |
| @@ -75,12 +74,12 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 75 | // Get record request | 74 | // Get record request |
| 76 | var record RecordRequest | 75 | var record RecordRequest |
| 77 | if err := c.ShouldBind(&record); err != nil { | 76 | if err := c.ShouldBind(&record); err != nil { |
| 78 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | 77 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordInvalidRequestFail, "BIND: "+err.Error()) |
| 79 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 78 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 80 | return | 79 | return |
| 81 | } | 80 | } |
| 82 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { | 81 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { |
| 83 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | 82 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordInvalidRequestFail) |
| 84 | c.JSON(http.StatusOK, models.ErrorResponse("Invalid entry for coop record submission.")) | 83 | c.JSON(http.StatusOK, models.ErrorResponse("Invalid entry for coop record submission.")) |
| 85 | return | 84 | return |
| 86 | } | 85 | } |
| @@ -110,28 +109,28 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 110 | // Upload & insert into demos | 109 | // Upload & insert into demos |
| 111 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") | 110 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") |
| 112 | if err != nil { | 111 | if err != nil { |
| 113 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailSaveDemo) | 112 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordSaveDemoFail, err.Error()) |
| 114 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 113 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 115 | return | 114 | return |
| 116 | } | 115 | } |
| 117 | defer os.Remove("backend/parser/" + uuid + ".dem") | 116 | defer os.Remove("backend/parser/" + uuid + ".dem") |
| 118 | f, err := os.Open("backend/parser/" + uuid + ".dem") | 117 | f, err := os.Open("backend/parser/" + uuid + ".dem") |
| 119 | if err != nil { | 118 | if err != nil { |
| 120 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailOpenDemo) | 119 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordOpenDemoFail, err.Error()) |
| 121 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 120 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 122 | return | 121 | return |
| 123 | } | 122 | } |
| 124 | defer f.Close() | 123 | defer f.Close() |
| 125 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) | 124 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) |
| 126 | if err != nil { | 125 | if err != nil { |
| 127 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailCreateDemo) | 126 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordCreateDemoFail, err.Error()) |
| 128 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 127 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 129 | return | 128 | return |
| 130 | } | 129 | } |
| 131 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") | 130 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") |
| 132 | if err != nil { | 131 | if err != nil { |
| 133 | deleteFile(srv, file.Id) | 132 | deleteFile(srv, file.Id) |
| 134 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailProcessDemo) | 133 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordProcessDemoFail, err.Error()) |
| 135 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 134 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 136 | return | 135 | return |
| 137 | } | 136 | } |
| @@ -145,7 +144,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 145 | _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) | 144 | _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) |
| 146 | if err != nil { | 145 | if err != nil { |
| 147 | deleteFile(srv, file.Id) | 146 | deleteFile(srv, file.Id) |
| 148 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertDemo) | 147 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordInsertDemoFail, err.Error()) |
| 149 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 148 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 150 | return | 149 | return |
| 151 | } | 150 | } |
| @@ -167,42 +166,26 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 167 | if err != nil { | 166 | if err != nil { |
| 168 | deleteFile(srv, hostDemoFileID) | 167 | deleteFile(srv, hostDemoFileID) |
| 169 | deleteFile(srv, partnerDemoFileID) | 168 | deleteFile(srv, partnerDemoFileID) |
| 170 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | 169 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordInsertRecordFail, err.Error()) |
| 171 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 170 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 172 | return | 171 | return |
| 173 | } | 172 | } |
| 174 | // If a new world record based on portal count | ||
| 175 | // if record.ScoreCount < wrScore { | ||
| 176 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) | ||
| 177 | // if err != nil { | ||
| 178 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 179 | // return | ||
| 180 | // } | ||
| 181 | // } | ||
| 182 | } else { | 173 | } else { |
| 183 | sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) | 174 | sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) |
| 184 | VALUES($1, $2, $3, $4, $5)` | 175 | VALUES($1, $2, $3, $4, $5)` |
| 185 | _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, user.(models.User).SteamID, hostDemoUUID) | 176 | _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, user.(models.User).SteamID, hostDemoUUID) |
| 186 | if err != nil { | 177 | if err != nil { |
| 187 | deleteFile(srv, hostDemoFileID) | 178 | deleteFile(srv, hostDemoFileID) |
| 188 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | 179 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordInsertRecordFail, err.Error()) |
| 189 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 180 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 190 | return | 181 | return |
| 191 | } | 182 | } |
| 192 | // If a new world record based on portal count | ||
| 193 | // if record.ScoreCount < wrScore { | ||
| 194 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) | ||
| 195 | // if err != nil { | ||
| 196 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 197 | // return | ||
| 198 | // } | ||
| 199 | // } | ||
| 200 | } | 183 | } |
| 201 | if err = tx.Commit(); err != nil { | 184 | if err = tx.Commit(); err != nil { |
| 202 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 185 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 203 | return | 186 | return |
| 204 | } | 187 | } |
| 205 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordSuccess) | 188 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordSuccess) |
| 206 | c.JSON(http.StatusOK, models.Response{ | 189 | c.JSON(http.StatusOK, models.Response{ |
| 207 | Success: true, | 190 | Success: true, |
| 208 | Message: "Successfully created record.", | 191 | Message: "Successfully created record.", |
| @@ -256,10 +239,12 @@ func DeleteRecord(c *gin.Context) { | |||
| 256 | sql = `SELECT mp.id FROM records_mp mp WHERE mp.id = $1 AND mp.map_id = $2 AND (mp.host_id = $3 OR mp.partner_id = $3) AND is_deleted = false` | 239 | sql = `SELECT mp.id FROM records_mp mp WHERE mp.id = $1 AND mp.map_id = $2 AND (mp.host_id = $3 OR mp.partner_id = $3) AND is_deleted = false` |
| 257 | err = database.DB.QueryRow(sql, recordID, mapID, user.(models.User).SteamID).Scan(&validateRecordID) | 240 | err = database.DB.QueryRow(sql, recordID, mapID, user.(models.User).SteamID).Scan(&validateRecordID) |
| 258 | if err != nil { | 241 | if err != nil { |
| 242 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionDeleteRecordFail, "S#records_mp: "+err.Error()) | ||
| 259 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 243 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 260 | return | 244 | return |
| 261 | } | 245 | } |
| 262 | if recordID != validateRecordID { | 246 | if recordID != validateRecordID { |
| 247 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionDeleteRecordFail, "recordID != validateRecordID") | ||
| 263 | c.JSON(http.StatusOK, models.ErrorResponse("Selected record does not exist.")) | 248 | c.JSON(http.StatusOK, models.ErrorResponse("Selected record does not exist.")) |
| 264 | return | 249 | return |
| 265 | } | 250 | } |
| @@ -267,6 +252,7 @@ func DeleteRecord(c *gin.Context) { | |||
| 267 | sql = `UPDATE records_mp SET is_deleted = true WHERE id = $1` | 252 | sql = `UPDATE records_mp SET is_deleted = true WHERE id = $1` |
| 268 | _, err = database.DB.Exec(sql, recordID) | 253 | _, err = database.DB.Exec(sql, recordID) |
| 269 | if err != nil { | 254 | if err != nil { |
| 255 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionDeleteRecordFail, "U#records_mp: "+err.Error()) | ||
| 270 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 256 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 271 | return | 257 | return |
| 272 | } | 258 | } |
| @@ -276,10 +262,12 @@ func DeleteRecord(c *gin.Context) { | |||
| 276 | sql = `SELECT sp.id FROM records_sp sp WHERE sp.id = $1 AND sp.map_id = $2 AND sp.user_id = $3 AND is_deleted = false` | 262 | sql = `SELECT sp.id FROM records_sp sp WHERE sp.id = $1 AND sp.map_id = $2 AND sp.user_id = $3 AND is_deleted = false` |
| 277 | err = database.DB.QueryRow(sql, recordID, mapID, user.(models.User).SteamID).Scan(&validateRecordID) | 263 | err = database.DB.QueryRow(sql, recordID, mapID, user.(models.User).SteamID).Scan(&validateRecordID) |
| 278 | if err != nil { | 264 | if err != nil { |
| 265 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionDeleteRecordFail, "S#records_sp: "+err.Error()) | ||
| 279 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 266 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 280 | return | 267 | return |
| 281 | } | 268 | } |
| 282 | if recordID != validateRecordID { | 269 | if recordID != validateRecordID { |
| 270 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionDeleteRecordFail, "recordID != validateRecordID") | ||
| 283 | c.JSON(http.StatusOK, models.ErrorResponse("Selected record does not exist.")) | 271 | c.JSON(http.StatusOK, models.ErrorResponse("Selected record does not exist.")) |
| 284 | return | 272 | return |
| 285 | } | 273 | } |
| @@ -287,10 +275,12 @@ func DeleteRecord(c *gin.Context) { | |||
| 287 | sql = `UPDATE records_sp SET is_deleted = true WHERE id = $1` | 275 | sql = `UPDATE records_sp SET is_deleted = true WHERE id = $1` |
| 288 | _, err = database.DB.Exec(sql, recordID) | 276 | _, err = database.DB.Exec(sql, recordID) |
| 289 | if err != nil { | 277 | if err != nil { |
| 278 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionDeleteRecordFail, "U#records_sp: "+err.Error()) | ||
| 290 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 279 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 291 | return | 280 | return |
| 292 | } | 281 | } |
| 293 | } | 282 | } |
| 283 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionDeleteRecordSuccess) | ||
| 294 | c.JSON(http.StatusOK, models.Response{ | 284 | c.JSON(http.StatusOK, models.Response{ |
| 295 | Success: true, | 285 | Success: true, |
| 296 | Message: "Successfully deleted record.", | 286 | Message: "Successfully deleted record.", |
diff --git a/backend/handlers/user.go b/backend/handlers/user.go index 1b20af0..461e521 100644 --- a/backend/handlers/user.go +++ b/backend/handlers/user.go | |||
| @@ -800,7 +800,7 @@ func UpdateUser(c *gin.Context) { | |||
| 800 | } | 800 | } |
| 801 | profile, err := GetPlayerSummaries(user.(models.User).SteamID, os.Getenv("API_KEY")) | 801 | profile, err := GetPlayerSummaries(user.(models.User).SteamID, os.Getenv("API_KEY")) |
| 802 | if err != nil { | 802 | if err != nil { |
| 803 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSummaryFail) | 803 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSummaryFail, err.Error()) |
| 804 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 804 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 805 | return | 805 | return |
| 806 | } | 806 | } |
| @@ -808,7 +808,7 @@ func UpdateUser(c *gin.Context) { | |||
| 808 | _, err = database.DB.Exec(`UPDATE users SET username = $1, avatar_link = $2, country_code = $3, updated_at = $4 | 808 | _, err = database.DB.Exec(`UPDATE users SET username = $1, avatar_link = $2, country_code = $3, updated_at = $4 |
| 809 | WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) | 809 | WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) |
| 810 | if err != nil { | 810 | if err != nil { |
| 811 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateFail) | 811 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateFail, "U#users: "+err.Error()) |
| 812 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | 812 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 813 | return | 813 | return |
| 814 | } | 814 | } |