aboutsummaryrefslogtreecommitdiff
path: root/backend/handlers/mod.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/handlers/mod.go')
-rw-r--r--backend/handlers/mod.go39
1 files changed, 21 insertions, 18 deletions
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go
index 89e3618..845152f 100644
--- a/backend/handlers/mod.go
+++ b/backend/handlers/mod.go
@@ -1,6 +1,7 @@
1package handlers 1package handlers
2 2
3import ( 3import (
4 "fmt"
4 "net/http" 5 "net/http"
5 "strconv" 6 "strconv"
6 "time" 7 "time"
@@ -67,7 +68,7 @@ func CreateMapSummary(c *gin.Context) {
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 {
70 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "BIND: "+err.Error()) 71 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("BIND: %s", err.Error()))
71 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 72 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
72 return 73 return
73 } 74 }
@@ -83,7 +84,7 @@ func CreateMapSummary(c *gin.Context) {
83 sql := `SELECT m.id FROM maps m WHERE m.id = $1` 84 sql := `SELECT m.id FROM maps m WHERE m.id = $1`
84 err = database.DB.QueryRow(sql, mapID).Scan(&checkMapID) 85 err = database.DB.QueryRow(sql, mapID).Scan(&checkMapID)
85 if err != nil { 86 if err != nil {
86 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "S#maps: "+err.Error()) 87 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("SELECT#maps: %s", err.Error()))
87 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 88 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
88 return 89 return
89 } 90 }
@@ -96,7 +97,7 @@ func CreateMapSummary(c *gin.Context) {
96 VALUES ($1,$2,$3,$4,$5)` 97 VALUES ($1,$2,$3,$4,$5)`
97 _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) 98 _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase)
98 if err != nil { 99 if err != nil {
99 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "I#map_routes: "+err.Error()) 100 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_routes: %s", err.Error()))
100 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 101 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
101 return 102 return
102 } 103 }
@@ -104,7 +105,7 @@ func CreateMapSummary(c *gin.Context) {
104 VALUES ($1,$2,$3,$4,$5)` 105 VALUES ($1,$2,$3,$4,$5)`
105 _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate) 106 _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate)
106 if err != nil { 107 if err != nil {
107 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, "I#map_history: "+err.Error()) 108 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateFail, fmt.Sprintf("INSERT#map_history: %s", err.Error()))
108 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 109 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
109 return 110 return
110 } 111 }
@@ -112,7 +113,7 @@ func CreateMapSummary(c *gin.Context) {
112 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 113 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
113 return 114 return
114 } 115 }
115 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateSuccess) 116 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreateSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, request.CategoryID, *request.ScoreCount))
116 c.JSON(http.StatusOK, models.Response{ 117 c.JSON(http.StatusOK, models.Response{
117 Success: true, 118 Success: true,
118 Message: "Successfully created map summary.", 119 Message: "Successfully created map summary.",
@@ -151,7 +152,7 @@ func EditMapSummary(c *gin.Context) {
151 } 152 }
152 var request EditMapSummaryRequest 153 var request EditMapSummaryRequest
153 if err := c.BindJSON(&request); err != nil { 154 if err := c.BindJSON(&request); err != nil {
154 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "BIND: "+err.Error()) 155 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("BIND: %s", err.Error()))
155 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 156 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
156 return 157 return
157 } 158 }
@@ -167,14 +168,14 @@ func EditMapSummary(c *gin.Context) {
167 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` 168 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`
168 err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) 169 err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount)
169 if err != nil { 170 if err != nil {
170 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "S#map_routes: "+err.Error()) 171 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) SELECT#map_routes: %s", request.RouteID, err.Error()))
171 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 172 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
172 return 173 return
173 } 174 }
174 sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` 175 sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3`
175 err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID) 176 err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID)
176 if err != nil { 177 if err != nil {
177 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "S#map_history: "+err.Error()) 178 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) SELECT#map_history: %s", request.RouteID, err.Error()))
178 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 179 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
179 return 180 return
180 } 181 }
@@ -182,14 +183,14 @@ func EditMapSummary(c *gin.Context) {
182 sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` 183 sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1`
183 _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) 184 _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase)
184 if err != nil { 185 if err != nil {
185 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "U#map_routes: "+err.Error()) 186 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) UPDATE#map_routes: %s", request.RouteID, err.Error()))
186 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 187 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
187 return 188 return
188 } 189 }
189 sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` 190 sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1`
190 _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) 191 _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate)
191 if err != nil { 192 if err != nil {
192 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "U#map_history"+err.Error()) 193 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(HistoryID: %d) UPDATE#map_history: %s", historyID, err.Error()))
193 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 194 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
194 return 195 return
195 } 196 }
@@ -197,7 +198,7 @@ func EditMapSummary(c *gin.Context) {
197 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 198 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
198 return 199 return
199 } 200 }
200 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditSuccess) 201 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, categoryID, scoreCount))
201 c.JSON(http.StatusOK, models.Response{ 202 c.JSON(http.StatusOK, models.Response{
202 Success: true, 203 Success: true,
203 Message: "Successfully updated map summary.", 204 Message: "Successfully updated map summary.",
@@ -236,7 +237,7 @@ func DeleteMapSummary(c *gin.Context) {
236 } 237 }
237 var request DeleteMapSummaryRequest 238 var request DeleteMapSummaryRequest
238 if err := c.BindJSON(&request); err != nil { 239 if err := c.BindJSON(&request); err != nil {
239 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, "BIND: "+err.Error()) 240 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditFail, fmt.Sprintf("(RouteID: %d) BIND: %s", request.RouteID, err.Error()))
240 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 241 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
241 return 242 return
242 } 243 }
@@ -252,7 +253,7 @@ func DeleteMapSummary(c *gin.Context) {
252 sql := `SELECT m.id, mr.score_count, mr.category_id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2` 253 sql := `SELECT m.id, mr.score_count, mr.category_id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2`
253 err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount, &categoryID) 254 err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount, &categoryID)
254 if err != nil { 255 if err != nil {
255 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "S#map_routes: "+err.Error()) 256 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) SELECT#map_routes: %s", request.RouteID, err.Error()))
256 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 257 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
257 return 258 return
258 } 259 }
@@ -263,7 +264,7 @@ func DeleteMapSummary(c *gin.Context) {
263 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 mh.category_id = $2 AND mh.score_count = $3` 264 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 mh.category_id = $2 AND mh.score_count = $3`
264 err = database.DB.QueryRow(sql, mapID, categoryID, scoreCount).Scan(&mapHistoryID) 265 err = database.DB.QueryRow(sql, mapID, categoryID, scoreCount).Scan(&mapHistoryID)
265 if err != nil { 266 if err != nil {
266 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "S#map_history: "+err.Error()) 267 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) SELECT#map_history: %s", request.RouteID, err.Error()))
267 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 268 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
268 return 269 return
269 } 270 }
@@ -271,14 +272,14 @@ func DeleteMapSummary(c *gin.Context) {
271 sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` 272 sql = `DELETE FROM map_routes mr WHERE mr.id = $1 `
272 _, err = tx.Exec(sql, request.RouteID) 273 _, err = tx.Exec(sql, request.RouteID)
273 if err != nil { 274 if err != nil {
274 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "D#map_routes: "+err.Error()) 275 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(RouteID: %d) DELETE#map_routes: %s", request.RouteID, err.Error()))
275 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 276 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
276 return 277 return
277 } 278 }
278 sql = `DELETE FROM map_history mh WHERE mh.id = $1` 279 sql = `DELETE FROM map_history mh WHERE mh.id = $1`
279 _, err = tx.Exec(sql, mapHistoryID) 280 _, err = tx.Exec(sql, mapHistoryID)
280 if err != nil { 281 if err != nil {
281 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, "D#map_history: "+err.Error()) 282 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteFail, fmt.Sprintf("(HistoryID: %d) DELETE#map_history: %s", mapHistoryID, err.Error()))
282 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 283 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
283 return 284 return
284 } 285 }
@@ -286,7 +287,7 @@ func DeleteMapSummary(c *gin.Context) {
286 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 287 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
287 return 288 return
288 } 289 }
289 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteSuccess) 290 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDeleteSuccess, fmt.Sprintf("MapID: %d | CategoryID: %d | ScoreCount: %d", mapID, categoryID, scoreCount))
290 c.JSON(http.StatusOK, models.Response{ 291 c.JSON(http.StatusOK, models.Response{
291 Success: true, 292 Success: true,
292 Message: "Successfully delete map summary.", 293 Message: "Successfully delete map summary.",
@@ -325,6 +326,7 @@ func EditMapImage(c *gin.Context) {
325 } 326 }
326 var request EditMapImageRequest 327 var request EditMapImageRequest
327 if err := c.BindJSON(&request); err != nil { 328 if err := c.BindJSON(&request); err != nil {
329 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditImageFail, fmt.Sprintf("BIND: %s", err.Error()))
328 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 330 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
329 return 331 return
330 } 332 }
@@ -332,10 +334,11 @@ func EditMapImage(c *gin.Context) {
332 sql := `UPDATE maps SET image = $2 WHERE id = $1` 334 sql := `UPDATE maps SET image = $2 WHERE id = $1`
333 _, err = database.DB.Exec(sql, mapID, request.Image) 335 _, err = database.DB.Exec(sql, mapID, request.Image)
334 if err != nil { 336 if err != nil {
337 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditImageFail, fmt.Sprintf("UPDATE#maps: %s", err.Error()))
335 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 338 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
336 return 339 return
337 } 340 }
338 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditImage) 341 CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditImageSuccess)
339 c.JSON(http.StatusOK, models.Response{ 342 c.JSON(http.StatusOK, models.Response{
340 Success: true, 343 Success: true,
341 Message: "Successfully updated map image.", 344 Message: "Successfully updated map image.",