diff options
Diffstat (limited to '')
| -rw-r--r-- | backend/controllers/homeController.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/backend/controllers/homeController.go b/backend/controllers/homeController.go index c94590a..d1b99cb 100644 --- a/backend/controllers/homeController.go +++ b/backend/controllers/homeController.go | |||
| @@ -10,6 +10,16 @@ import ( | |||
| 10 | "github.com/pektezol/leastportalshub/backend/models" | 10 | "github.com/pektezol/leastportalshub/backend/models" |
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | type SearchResponse struct { | ||
| 14 | Players []models.UserShort `json:"players"` | ||
| 15 | Maps []models.MapShort `json:"maps"` | ||
| 16 | } | ||
| 17 | |||
| 18 | type RankingsResponse struct { | ||
| 19 | RankingsSP []models.UserRanking `json:"rankings_sp"` | ||
| 20 | RankingsMP []models.UserRanking `json:"rankings_mp"` | ||
| 21 | } | ||
| 22 | |||
| 13 | func Home(c *gin.Context) { | 23 | func Home(c *gin.Context) { |
| 14 | user, exists := c.Get("user") | 24 | user, exists := c.Get("user") |
| 15 | if !exists { | 25 | if !exists { |
| @@ -26,7 +36,7 @@ func Home(c *gin.Context) { | |||
| 26 | // @Description Get rankings of every player. | 36 | // @Description Get rankings of every player. |
| 27 | // @Tags rankings | 37 | // @Tags rankings |
| 28 | // @Produce json | 38 | // @Produce json |
| 29 | // @Success 200 {object} models.Response{data=models.RankingsResponse} | 39 | // @Success 200 {object} models.Response{data=RankingsResponse} |
| 30 | // @Failure 400 {object} models.Response | 40 | // @Failure 400 {object} models.Response |
| 31 | // @Router /rankings [get] | 41 | // @Router /rankings [get] |
| 32 | func Rankings(c *gin.Context) { | 42 | func Rankings(c *gin.Context) { |
| @@ -116,7 +126,7 @@ func Rankings(c *gin.Context) { | |||
| 116 | c.JSON(http.StatusOK, models.Response{ | 126 | c.JSON(http.StatusOK, models.Response{ |
| 117 | Success: true, | 127 | Success: true, |
| 118 | Message: "Successfully retrieved rankings.", | 128 | Message: "Successfully retrieved rankings.", |
| 119 | Data: models.RankingsResponse{ | 129 | Data: RankingsResponse{ |
| 120 | RankingsSP: spRankings, | 130 | RankingsSP: spRankings, |
| 121 | RankingsMP: mpRankings, | 131 | RankingsMP: mpRankings, |
| 122 | }, | 132 | }, |
| @@ -129,14 +139,14 @@ func Rankings(c *gin.Context) { | |||
| 129 | // @Tags search | 139 | // @Tags search |
| 130 | // @Produce json | 140 | // @Produce json |
| 131 | // @Param q query string false "Search user or map name." | 141 | // @Param q query string false "Search user or map name." |
| 132 | // @Success 200 {object} models.Response{data=models.SearchResponse} | 142 | // @Success 200 {object} models.Response{data=SearchResponse} |
| 133 | // @Failure 400 {object} models.Response | 143 | // @Failure 400 {object} models.Response |
| 134 | // @Router /search [get] | 144 | // @Router /search [get] |
| 135 | func SearchWithQuery(c *gin.Context) { | 145 | func SearchWithQuery(c *gin.Context) { |
| 136 | query := c.Query("q") | 146 | query := c.Query("q") |
| 137 | query = strings.ToLower(query) | 147 | query = strings.ToLower(query) |
| 138 | log.Println(query) | 148 | log.Println(query) |
| 139 | var response models.SearchResponse | 149 | var response SearchResponse |
| 140 | // Cache all maps for faster response | 150 | // Cache all maps for faster response |
| 141 | var maps = []models.MapShort{ | 151 | var maps = []models.MapShort{ |
| 142 | {ID: 1, Name: "Container Ride"}, | 152 | {ID: 1, Name: "Container Ride"}, |