diff options
Diffstat (limited to 'backend/handlers/logs.go')
| -rw-r--r-- | backend/handlers/logs.go | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index c971f79..b5704d6 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go | |||
| @@ -12,13 +12,13 @@ import ( | |||
| 12 | 12 | ||
| 13 | const ( | 13 | const ( |
| 14 | LogTypeMod string = "Mod" | 14 | LogTypeMod string = "Mod" |
| 15 | LogTypeLogin string = "Login" | 15 | LogTypeLogin string = "User" |
| 16 | LogTypeRecord string = "Record" | 16 | LogTypeRecord string = "Record" |
| 17 | 17 | ||
| 18 | LogDescriptionLoginSuccess string = "Success" | 18 | LogDescriptionUserLoginSuccess string = "LoginSuccess" |
| 19 | LogDescriptionLoginFailToken string = "TokenFail" | 19 | LogDescriptionUserLoginFailToken string = "LoginTokenFail" |
| 20 | LogDescriptionLoginFailValidate string = "ValidateFail" | 20 | LogDescriptionUserLoginFailValidate string = "LoginValidateFail" |
| 21 | LogDescriptionLoginFailSummary string = "SummaryFail" | 21 | LogDescriptionUserLoginFailSummary string = "LoginSummaryFail" |
| 22 | 22 | ||
| 23 | LogDescriptionMapSummaryCreate string = "MapSummaryCreate" | 23 | LogDescriptionMapSummaryCreate string = "MapSummaryCreate" |
| 24 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" | 24 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" |
| @@ -39,6 +39,7 @@ type Log struct { | |||
| 39 | User models.UserShort `json:"user"` | 39 | User models.UserShort `json:"user"` |
| 40 | Type string `json:"type"` | 40 | Type string `json:"type"` |
| 41 | Description string `json:"description"` | 41 | Description string `json:"description"` |
| 42 | Date time.Time `json:"date"` | ||
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | type LogsResponse struct { | 45 | type LogsResponse struct { |
| @@ -48,6 +49,7 @@ type LogsResponse struct { | |||
| 48 | type LogsResponseDetails struct { | 49 | type LogsResponseDetails struct { |
| 49 | User models.UserShort `json:"user"` | 50 | User models.UserShort `json:"user"` |
| 50 | Log string `json:"detail"` | 51 | Log string `json:"detail"` |
| 52 | Date time.Time `json:"date"` | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | type ScoreLogsResponse struct { | 55 | type ScoreLogsResponse struct { |
| @@ -70,7 +72,7 @@ type ScoreLogsResponseDetails struct { | |||
| 70 | // @Tags logs | 72 | // @Tags logs |
| 71 | // @Produce json | 73 | // @Produce json |
| 72 | // @Param Authorization header string true "JWT Token" | 74 | // @Param Authorization header string true "JWT Token" |
| 73 | // @Success 200 {object} models.Response{data=ScoreLogsResponse} | 75 | // @Success 200 {object} models.Response{data=LogsResponse} |
| 74 | // @Failure 400 {object} models.Response | 76 | // @Failure 400 {object} models.Response |
| 75 | // @Router /logs/mod [get] | 77 | // @Router /logs/mod [get] |
| 76 | func ModLogs(c *gin.Context) { | 78 | func ModLogs(c *gin.Context) { |
| @@ -80,7 +82,7 @@ func ModLogs(c *gin.Context) { | |||
| 80 | return | 82 | return |
| 81 | } | 83 | } |
| 82 | response := LogsResponse{Logs: []LogsResponseDetails{}} | 84 | response := LogsResponse{Logs: []LogsResponseDetails{}} |
| 83 | sql := `SELECT u.user_name, l.user_id, l.type, l.description | 85 | sql := `SELECT u.user_name, l.user_id, l.type, l.description, l.date |
| 84 | FROM logs l INNER JOIN users u ON l.user_id = u.steam_id WHERE type != 'Score'` | 86 | FROM logs l INNER JOIN users u ON l.user_id = u.steam_id WHERE type != 'Score'` |
| 85 | rows, err := database.DB.Query(sql) | 87 | rows, err := database.DB.Query(sql) |
| 86 | if err != nil { | 88 | if err != nil { |
| @@ -89,7 +91,7 @@ func ModLogs(c *gin.Context) { | |||
| 89 | } | 91 | } |
| 90 | for rows.Next() { | 92 | for rows.Next() { |
| 91 | log := Log{} | 93 | log := Log{} |
| 92 | err = rows.Scan(&log.User.UserName, &log.User.SteamID, &log.Type, &log.Description) | 94 | err = rows.Scan(&log.User.UserName, &log.User.SteamID, &log.Type, &log.Description, &log.Date) |
| 93 | if err != nil { | 95 | if err != nil { |
| 94 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 96 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 95 | return | 97 | return |
| @@ -100,7 +102,8 @@ func ModLogs(c *gin.Context) { | |||
| 100 | SteamID: log.User.SteamID, | 102 | SteamID: log.User.SteamID, |
| 101 | UserName: log.User.UserName, | 103 | UserName: log.User.UserName, |
| 102 | }, | 104 | }, |
| 103 | Log: detail, | 105 | Log: detail, |
| 106 | Date: log.Date, | ||
| 104 | }) | 107 | }) |
| 105 | } | 108 | } |
| 106 | c.JSON(http.StatusOK, models.Response{ | 109 | c.JSON(http.StatusOK, models.Response{ |