diff options
Diffstat (limited to 'backend/handlers/logs.go')
| -rw-r--r-- | backend/handlers/logs.go | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go deleted file mode 100644 index 693c448..0000000 --- a/backend/handlers/logs.go +++ /dev/null | |||
| @@ -1,103 +0,0 @@ | |||
| 1 | package handlers | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "net/http" | ||
| 5 | "time" | ||
| 6 | |||
| 7 | "lphub/database" | ||
| 8 | "lphub/models" | ||
| 9 | |||
| 10 | "github.com/gin-gonic/gin" | ||
| 11 | ) | ||
| 12 | |||
| 13 | type Log struct { | ||
| 14 | User models.UserShort `json:"user"` | ||
| 15 | Type string `json:"type"` | ||
| 16 | Description string `json:"description"` | ||
| 17 | Message string `json:"message"` | ||
| 18 | Date time.Time `json:"date"` | ||
| 19 | } | ||
| 20 | |||
| 21 | type LogsResponse struct { | ||
| 22 | Logs []LogsResponseDetails `json:"logs"` | ||
| 23 | } | ||
| 24 | |||
| 25 | type LogsResponseDetails struct { | ||
| 26 | User models.UserShort `json:"user"` | ||
| 27 | Log string `json:"detail"` | ||
| 28 | Message string `json:"message"` | ||
| 29 | Date time.Time `json:"date"` | ||
| 30 | } | ||
| 31 | |||
| 32 | type ScoreLogsResponse struct { | ||
| 33 | Logs []ScoreLogsResponseDetails `json:"scores"` | ||
| 34 | } | ||
| 35 | |||
| 36 | type ScoreLogsResponseDetails struct { | ||
| 37 | Game models.Game `json:"game"` | ||
| 38 | User models.UserShort `json:"user"` | ||
| 39 | Map models.MapShort `json:"map"` | ||
| 40 | ScoreCount int `json:"score_count"` | ||
| 41 | ScoreTime int `json:"score_time"` | ||
| 42 | DemoID string `json:"demo_id"` | ||
| 43 | Date time.Time `json:"date"` | ||
| 44 | } | ||
| 45 | |||
| 46 | // GET Score Logs | ||
| 47 | // | ||
| 48 | // @Description Get score logs of every player. | ||
| 49 | // @Tags logs | ||
| 50 | // @Produce json | ||
| 51 | // @Success 200 {object} models.Response{data=ScoreLogsResponse} | ||
| 52 | // @Router /logs/score [get] | ||
| 53 | func ScoreLogs(c *gin.Context) { | ||
| 54 | response := ScoreLogsResponse{Logs: []ScoreLogsResponseDetails{}} | ||
| 55 | sql := `SELECT g.id, | ||
| 56 | g."name", | ||
| 57 | g.is_coop, | ||
| 58 | rs.map_id, | ||
| 59 | m.name AS map_name, | ||
| 60 | u.steam_id, | ||
| 61 | u.user_name, | ||
| 62 | rs.score_count, | ||
| 63 | rs.score_time, | ||
| 64 | rs.demo_id, | ||
| 65 | rs.record_date | ||
| 66 | FROM ( | ||
| 67 | SELECT id, map_id, user_id, score_count, score_time, demo_id, record_date | ||
| 68 | FROM records_sp WHERE is_deleted = false | ||
| 69 | |||
| 70 | UNION ALL | ||
| 71 | |||
| 72 | SELECT id, map_id, host_id AS user_id, score_count, score_time, host_demo_id AS demo_id, record_date | ||
| 73 | FROM records_mp WHERE is_deleted = false | ||
| 74 | |||
| 75 | UNION ALL | ||
| 76 | |||
| 77 | SELECT id, map_id, partner_id AS user_id, score_count, score_time, partner_demo_id AS demo_id, record_date | ||
| 78 | FROM records_mp WHERE is_deleted = false | ||
| 79 | ) AS rs | ||
| 80 | JOIN users u ON rs.user_id = u.steam_id | ||
| 81 | JOIN maps m ON rs.map_id = m.id | ||
| 82 | JOIN games g ON m.game_id = g.id | ||
| 83 | ORDER BY rs.record_date DESC LIMIT 100;` | ||
| 84 | rows, err := database.DB.Query(sql) | ||
| 85 | if err != nil { | ||
| 86 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 87 | return | ||
| 88 | } | ||
| 89 | for rows.Next() { | ||
| 90 | score := ScoreLogsResponseDetails{} | ||
| 91 | err = rows.Scan(&score.Game.ID, &score.Game.Name, &score.Game.IsCoop, &score.Map.ID, &score.Map.Name, &score.User.SteamID, &score.User.UserName, &score.ScoreCount, &score.ScoreTime, &score.DemoID, &score.Date) | ||
| 92 | if err != nil { | ||
| 93 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 94 | return | ||
| 95 | } | ||
| 96 | response.Logs = append(response.Logs, score) | ||
| 97 | } | ||
| 98 | c.JSON(http.StatusOK, models.Response{ | ||
| 99 | Success: true, | ||
| 100 | Message: "Successfully retrieved score logs.", | ||
| 101 | Data: response, | ||
| 102 | }) | ||
| 103 | } | ||