diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-02 22:02:11 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-02 22:02:11 +0300 |
| commit | 266698e46744063752f7cc893c539f132e3cdc37 (patch) | |
| tree | 535523867d77bc0c3717b2753ab62984724f5ee8 /backend/handlers/record.go | |
| parent | feat: map summary logs (#55) (diff) | |
| download | lphub-266698e46744063752f7cc893c539f132e3cdc37.tar.gz lphub-266698e46744063752f7cc893c539f132e3cdc37.tar.bz2 lphub-266698e46744063752f7cc893c539f132e3cdc37.zip | |
feat: detailed logs for records (#55)
Former-commit-id: af37633ce05f08fc517cb3e8fec3e84a0bd5ba49
Diffstat (limited to 'backend/handlers/record.go')
| -rw-r--r-- | backend/handlers/record.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/backend/handlers/record.go b/backend/handlers/record.go index 00c9b7d..3d29eb8 100644 --- a/backend/handlers/record.go +++ b/backend/handlers/record.go | |||
| @@ -66,6 +66,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 66 | return | 66 | return |
| 67 | } | 67 | } |
| 68 | if isDisabled { | 68 | if isDisabled { |
| 69 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | ||
| 69 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) | 70 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) |
| 70 | return | 71 | return |
| 71 | } | 72 | } |
| @@ -75,10 +76,12 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 75 | // Get record request | 76 | // Get record request |
| 76 | var record RecordRequest | 77 | var record RecordRequest |
| 77 | if err := c.ShouldBind(&record); err != nil { | 78 | if err := c.ShouldBind(&record); err != nil { |
| 79 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | ||
| 78 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 80 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 79 | return | 81 | return |
| 80 | } | 82 | } |
| 81 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { | 83 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { |
| 84 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | ||
| 82 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid entry for coop record submission.")) | 85 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid entry for coop record submission.")) |
| 83 | return | 86 | return |
| 84 | } | 87 | } |
| @@ -108,23 +111,27 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 108 | // Upload & insert into demos | 111 | // Upload & insert into demos |
| 109 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") | 112 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") |
| 110 | if err != nil { | 113 | if err != nil { |
| 114 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailSaveDemo) | ||
| 111 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 115 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 112 | return | 116 | return |
| 113 | } | 117 | } |
| 114 | defer os.Remove("backend/parser/" + uuid + ".dem") | 118 | defer os.Remove("backend/parser/" + uuid + ".dem") |
| 115 | f, err := os.Open("backend/parser/" + uuid + ".dem") | 119 | f, err := os.Open("backend/parser/" + uuid + ".dem") |
| 116 | if err != nil { | 120 | if err != nil { |
| 121 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailOpenDemo) | ||
| 117 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 122 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 118 | return | 123 | return |
| 119 | } | 124 | } |
| 120 | defer f.Close() | 125 | defer f.Close() |
| 121 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) | 126 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) |
| 122 | if err != nil { | 127 | if err != nil { |
| 128 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailCreateDemo) | ||
| 123 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 129 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 124 | return | 130 | return |
| 125 | } | 131 | } |
| 126 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") | 132 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") |
| 127 | if err != nil { | 133 | if err != nil { |
| 134 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailProcessDemo) | ||
| 128 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 135 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 129 | return | 136 | return |
| 130 | } | 137 | } |
| @@ -138,6 +145,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 138 | _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) | 145 | _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) |
| 139 | if err != nil { | 146 | if err != nil { |
| 140 | deleteFile(srv, file.Id) | 147 | deleteFile(srv, file.Id) |
| 148 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertDemo) | ||
| 141 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 149 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 142 | return | 150 | return |
| 143 | } | 151 | } |
| @@ -159,6 +167,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 159 | if err != nil { | 167 | if err != nil { |
| 160 | deleteFile(srv, hostDemoFileID) | 168 | deleteFile(srv, hostDemoFileID) |
| 161 | deleteFile(srv, partnerDemoFileID) | 169 | deleteFile(srv, partnerDemoFileID) |
| 170 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | ||
| 162 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 171 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 163 | return | 172 | return |
| 164 | } | 173 | } |
| @@ -176,6 +185,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 176 | _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, user.(models.User).SteamID, hostDemoUUID) | 185 | _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, user.(models.User).SteamID, hostDemoUUID) |
| 177 | if err != nil { | 186 | if err != nil { |
| 178 | deleteFile(srv, hostDemoFileID) | 187 | deleteFile(srv, hostDemoFileID) |
| 188 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | ||
| 179 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 189 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 180 | return | 190 | return |
| 181 | } | 191 | } |
| @@ -192,6 +202,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 192 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 202 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) |
| 193 | return | 203 | return |
| 194 | } | 204 | } |
| 205 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordSuccess) | ||
| 195 | c.JSON(http.StatusOK, models.Response{ | 206 | c.JSON(http.StatusOK, models.Response{ |
| 196 | Success: true, | 207 | Success: true, |
| 197 | Message: "Successfully created record.", | 208 | Message: "Successfully created record.", |