diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-02 21:41:02 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-02 21:41:02 +0300 |
| commit | f56488d3cf25a1141ce73378241ee0048f440842 (patch) | |
| tree | 07a31e27b715f19cdfd48cccff3549ede3651c66 /backend | |
| parent | fix: remove redundant home route (diff) | |
| download | lphub-f56488d3cf25a1141ce73378241ee0048f440842.tar.gz lphub-f56488d3cf25a1141ce73378241ee0048f440842.tar.bz2 lphub-f56488d3cf25a1141ce73378241ee0048f440842.zip | |
feat: map summary logs (#55)
Former-commit-id: 4ef8800f1270e3b3aa61913bef8cc07ce4a55656
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/handlers/logs.go | 5 | ||||
| -rw-r--r-- | backend/handlers/mod.go | 20 |
2 files changed, 15 insertions, 10 deletions
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index 882632d..0fef6a1 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go | |||
| @@ -18,6 +18,11 @@ const ( | |||
| 18 | LogDescriptionLoginFailToken string = "TokenFail" | 18 | LogDescriptionLoginFailToken string = "TokenFail" |
| 19 | LogDescriptionLoginFailValidate string = "ValidateFail" | 19 | LogDescriptionLoginFailValidate string = "ValidateFail" |
| 20 | LogDescriptionLoginFailSummary string = "SummaryFail" | 20 | LogDescriptionLoginFailSummary string = "SummaryFail" |
| 21 | |||
| 22 | LogDescriptionMapSummaryCreate string = "MapSummaryCreate" | ||
| 23 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" | ||
| 24 | LogDescriptionMapSummaryEditImage string = "MapSummaryEditImage" | ||
| 25 | LogDescriptionMapSummaryDelete string = "MapSummaryDelete" | ||
| 21 | ) | 26 | ) |
| 22 | 27 | ||
| 23 | type Log struct { | 28 | type Log struct { |
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go index e47cb3f..a9b7a20 100644 --- a/backend/handlers/mod.go +++ b/backend/handlers/mod.go | |||
| @@ -15,7 +15,7 @@ type CreateMapSummaryRequest struct { | |||
| 15 | Description string `json:"description" binding:"required"` | 15 | Description string `json:"description" binding:"required"` |
| 16 | Showcase string `json:"showcase"` | 16 | Showcase string `json:"showcase"` |
| 17 | UserName string `json:"user_name" binding:"required"` | 17 | UserName string `json:"user_name" binding:"required"` |
| 18 | ScoreCount *int `json:"score_count" binding:"required"` | 18 | ScoreCount int `json:"score_count" binding:"required"` |
| 19 | RecordDate time.Time `json:"record_date" binding:"required"` | 19 | RecordDate time.Time `json:"record_date" binding:"required"` |
| 20 | } | 20 | } |
| 21 | 21 | ||
| @@ -24,7 +24,7 @@ type EditMapSummaryRequest struct { | |||
| 24 | Description string `json:"description" binding:"required"` | 24 | Description string `json:"description" binding:"required"` |
| 25 | Showcase string `json:"showcase"` | 25 | Showcase string `json:"showcase"` |
| 26 | UserName string `json:"user_name" binding:"required"` | 26 | UserName string `json:"user_name" binding:"required"` |
| 27 | ScoreCount *int `json:"score_count" binding:"required"` | 27 | ScoreCount int `json:"score_count" binding:"required"` |
| 28 | RecordDate time.Time `json:"record_date" binding:"required"` | 28 | RecordDate time.Time `json:"record_date" binding:"required"` |
| 29 | } | 29 | } |
| 30 | 30 | ||
| @@ -49,7 +49,7 @@ type EditMapImageRequest struct { | |||
| 49 | // @Router /maps/{id}/summary [post] | 49 | // @Router /maps/{id}/summary [post] |
| 50 | func CreateMapSummary(c *gin.Context) { | 50 | func CreateMapSummary(c *gin.Context) { |
| 51 | // Check if user exists | 51 | // Check if user exists |
| 52 | _, exists := c.Get("user") | 52 | user, exists := c.Get("user") |
| 53 | if !exists { | 53 | if !exists { |
| 54 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 54 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) |
| 55 | return | 55 | return |
| @@ -109,7 +109,7 @@ func CreateMapSummary(c *gin.Context) { | |||
| 109 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 109 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) |
| 110 | return | 110 | return |
| 111 | } | 111 | } |
| 112 | // Return response | 112 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreate) |
| 113 | c.JSON(http.StatusOK, models.Response{ | 113 | c.JSON(http.StatusOK, models.Response{ |
| 114 | Success: true, | 114 | Success: true, |
| 115 | Message: "Successfully created map summary.", | 115 | Message: "Successfully created map summary.", |
| @@ -130,7 +130,7 @@ func CreateMapSummary(c *gin.Context) { | |||
| 130 | // @Router /maps/{id}/summary [put] | 130 | // @Router /maps/{id}/summary [put] |
| 131 | func EditMapSummary(c *gin.Context) { | 131 | func EditMapSummary(c *gin.Context) { |
| 132 | // Check if user exists | 132 | // Check if user exists |
| 133 | _, exists := c.Get("user") | 133 | user, exists := c.Get("user") |
| 134 | if !exists { | 134 | if !exists { |
| 135 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 135 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) |
| 136 | return | 136 | return |
| @@ -190,7 +190,7 @@ func EditMapSummary(c *gin.Context) { | |||
| 190 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 190 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) |
| 191 | return | 191 | return |
| 192 | } | 192 | } |
| 193 | // Return response | 193 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEdit) |
| 194 | c.JSON(http.StatusOK, models.Response{ | 194 | c.JSON(http.StatusOK, models.Response{ |
| 195 | Success: true, | 195 | Success: true, |
| 196 | Message: "Successfully updated map summary.", | 196 | Message: "Successfully updated map summary.", |
| @@ -211,7 +211,7 @@ func EditMapSummary(c *gin.Context) { | |||
| 211 | // @Router /maps/{id}/summary [delete] | 211 | // @Router /maps/{id}/summary [delete] |
| 212 | func DeleteMapSummary(c *gin.Context) { | 212 | func DeleteMapSummary(c *gin.Context) { |
| 213 | // Check if user exists | 213 | // Check if user exists |
| 214 | _, exists := c.Get("user") | 214 | user, exists := c.Get("user") |
| 215 | if !exists { | 215 | if !exists { |
| 216 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 216 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) |
| 217 | return | 217 | return |
| @@ -275,7 +275,7 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 275 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 275 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) |
| 276 | return | 276 | return |
| 277 | } | 277 | } |
| 278 | // Return response | 278 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDelete) |
| 279 | c.JSON(http.StatusOK, models.Response{ | 279 | c.JSON(http.StatusOK, models.Response{ |
| 280 | Success: true, | 280 | Success: true, |
| 281 | Message: "Successfully delete map summary.", | 281 | Message: "Successfully delete map summary.", |
| @@ -296,7 +296,7 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 296 | // @Router /maps/{id}/image [put] | 296 | // @Router /maps/{id}/image [put] |
| 297 | func EditMapImage(c *gin.Context) { | 297 | func EditMapImage(c *gin.Context) { |
| 298 | // Check if user exists | 298 | // Check if user exists |
| 299 | _, exists := c.Get("user") | 299 | user, exists := c.Get("user") |
| 300 | if !exists { | 300 | if !exists { |
| 301 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 301 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) |
| 302 | return | 302 | return |
| @@ -325,7 +325,7 @@ func EditMapImage(c *gin.Context) { | |||
| 325 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 325 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 326 | return | 326 | return |
| 327 | } | 327 | } |
| 328 | // Return response | 328 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditImage) |
| 329 | c.JSON(http.StatusOK, models.Response{ | 329 | c.JSON(http.StatusOK, models.Response{ |
| 330 | Success: true, | 330 | Success: true, |
| 331 | Message: "Successfully updated map image.", | 331 | Message: "Successfully updated map image.", |