diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-12 00:25:15 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-12 00:25:15 +0300 |
| commit | df6f6cb5ff8957be8f01d58d60857da2c094a3d9 (patch) | |
| tree | 5ec5a8a95633d7fa6cce62654a9bc6fc6204f788 /backend | |
| parent | refactor: fix module ver (diff) | |
| download | lphub-df6f6cb5ff8957be8f01d58d60857da2c094a3d9.tar.gz lphub-df6f6cb5ff8957be8f01d58d60857da2c094a3d9.tar.bz2 lphub-df6f6cb5ff8957be8f01d58d60857da2c094a3d9.zip | |
refactor: unofficial rankings implementation
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/routes.go | 6 | ||||
| -rw-r--r-- | backend/docs/docs.go | 90 | ||||
| -rw-r--r-- | backend/docs/swagger.json | 90 | ||||
| -rw-r--r-- | backend/docs/swagger.yaml | 57 | ||||
| -rw-r--r-- | backend/handlers/home.go | 100 |
5 files changed, 329 insertions, 14 deletions
diff --git a/backend/api/routes.go b/backend/api/routes.go index 050a3bd..81f1ec6 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go | |||
| @@ -25,7 +25,8 @@ const ( | |||
| 25 | mapRecordIDPath string = "/maps/:mapid/record/:recordid" | 25 | mapRecordIDPath string = "/maps/:mapid/record/:recordid" |
| 26 | mapDiscussionsPath string = "/maps/:mapid/discussions" | 26 | mapDiscussionsPath string = "/maps/:mapid/discussions" |
| 27 | mapDiscussionIDPath string = "/maps/:mapid/discussions/:discussionid" | 27 | mapDiscussionIDPath string = "/maps/:mapid/discussions/:discussionid" |
| 28 | rankingsPath string = "/rankings" | 28 | rankingsLPHUBPath string = "/rankings/lphub" |
| 29 | rankingsSteamPath string = "/rankings/steam" | ||
| 29 | searchPath string = "/search" | 30 | searchPath string = "/search" |
| 30 | gamesPath string = "/games" | 31 | gamesPath string = "/games" |
| 31 | chaptersPath string = "/games/:gameid" | 32 | chaptersPath string = "/games/:gameid" |
| @@ -73,7 +74,8 @@ func InitRoutes(router *gin.Engine) { | |||
| 73 | v1.PUT(mapDiscussionIDPath, CheckAuth, handlers.EditMapDiscussion) | 74 | v1.PUT(mapDiscussionIDPath, CheckAuth, handlers.EditMapDiscussion) |
| 74 | v1.DELETE(mapDiscussionIDPath, CheckAuth, handlers.DeleteMapDiscussion) | 75 | v1.DELETE(mapDiscussionIDPath, CheckAuth, handlers.DeleteMapDiscussion) |
| 75 | // Rankings, search | 76 | // Rankings, search |
| 76 | v1.GET(rankingsPath, handlers.Rankings) | 77 | v1.GET(rankingsLPHUBPath, handlers.RankingsLPHUB) |
| 78 | v1.GET(rankingsSteamPath, handlers.RankingsSteam) | ||
| 77 | v1.GET(searchPath, handlers.SearchWithQuery) | 79 | v1.GET(searchPath, handlers.SearchWithQuery) |
| 78 | // Games, chapters, maps | 80 | // Games, chapters, maps |
| 79 | v1.GET(gamesPath, handlers.FetchGames) | 81 | v1.GET(gamesPath, handlers.FetchGames) |
diff --git a/backend/docs/docs.go b/backend/docs/docs.go index f652a1e..c4b2801 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go | |||
| @@ -1171,9 +1171,9 @@ const docTemplate = `{ | |||
| 1171 | } | 1171 | } |
| 1172 | } | 1172 | } |
| 1173 | }, | 1173 | }, |
| 1174 | "/rankings": { | 1174 | "/rankings/lphub": { |
| 1175 | "get": { | 1175 | "get": { |
| 1176 | "description": "Get rankings of every player.", | 1176 | "description": "Get rankings of every player from LPHUB.", |
| 1177 | "produces": [ | 1177 | "produces": [ |
| 1178 | "application/json" | 1178 | "application/json" |
| 1179 | ], | 1179 | ], |
| @@ -1202,6 +1202,37 @@ const docTemplate = `{ | |||
| 1202 | } | 1202 | } |
| 1203 | } | 1203 | } |
| 1204 | }, | 1204 | }, |
| 1205 | "/rankings/steam": { | ||
| 1206 | "get": { | ||
| 1207 | "description": "Get rankings of every player from Steam.", | ||
| 1208 | "produces": [ | ||
| 1209 | "application/json" | ||
| 1210 | ], | ||
| 1211 | "tags": [ | ||
| 1212 | "rankings" | ||
| 1213 | ], | ||
| 1214 | "responses": { | ||
| 1215 | "200": { | ||
| 1216 | "description": "OK", | ||
| 1217 | "schema": { | ||
| 1218 | "allOf": [ | ||
| 1219 | { | ||
| 1220 | "$ref": "#/definitions/models.Response" | ||
| 1221 | }, | ||
| 1222 | { | ||
| 1223 | "type": "object", | ||
| 1224 | "properties": { | ||
| 1225 | "data": { | ||
| 1226 | "$ref": "#/definitions/handlers.RankingsSteamResponse" | ||
| 1227 | } | ||
| 1228 | } | ||
| 1229 | } | ||
| 1230 | ] | ||
| 1231 | } | ||
| 1232 | } | ||
| 1233 | } | ||
| 1234 | } | ||
| 1235 | }, | ||
| 1205 | "/search": { | 1236 | "/search": { |
| 1206 | "get": { | 1237 | "get": { |
| 1207 | "description": "Get all user and map data matching to the query.", | 1238 | "description": "Get all user and map data matching to the query.", |
| @@ -1789,6 +1820,29 @@ const docTemplate = `{ | |||
| 1789 | } | 1820 | } |
| 1790 | } | 1821 | } |
| 1791 | }, | 1822 | }, |
| 1823 | "handlers.RankingsSteamResponse": { | ||
| 1824 | "type": "object", | ||
| 1825 | "properties": { | ||
| 1826 | "rankings_multiplayer": { | ||
| 1827 | "type": "array", | ||
| 1828 | "items": { | ||
| 1829 | "$ref": "#/definitions/handlers.SteamUserRanking" | ||
| 1830 | } | ||
| 1831 | }, | ||
| 1832 | "rankings_overall": { | ||
| 1833 | "type": "array", | ||
| 1834 | "items": { | ||
| 1835 | "$ref": "#/definitions/handlers.SteamUserRanking" | ||
| 1836 | } | ||
| 1837 | }, | ||
| 1838 | "rankings_singleplayer": { | ||
| 1839 | "type": "array", | ||
| 1840 | "items": { | ||
| 1841 | "$ref": "#/definitions/handlers.SteamUserRanking" | ||
| 1842 | } | ||
| 1843 | } | ||
| 1844 | } | ||
| 1845 | }, | ||
| 1792 | "handlers.RecordResponse": { | 1846 | "handlers.RecordResponse": { |
| 1793 | "type": "object", | 1847 | "type": "object", |
| 1794 | "properties": { | 1848 | "properties": { |
| @@ -1854,6 +1908,38 @@ const docTemplate = `{ | |||
| 1854 | } | 1908 | } |
| 1855 | } | 1909 | } |
| 1856 | }, | 1910 | }, |
| 1911 | "handlers.SteamUserRanking": { | ||
| 1912 | "type": "object", | ||
| 1913 | "properties": { | ||
| 1914 | "avatar_link": { | ||
| 1915 | "type": "string" | ||
| 1916 | }, | ||
| 1917 | "mp_rank": { | ||
| 1918 | "type": "integer" | ||
| 1919 | }, | ||
| 1920 | "mp_score": { | ||
| 1921 | "type": "integer" | ||
| 1922 | }, | ||
| 1923 | "overall_rank": { | ||
| 1924 | "type": "integer" | ||
| 1925 | }, | ||
| 1926 | "overall_score": { | ||
| 1927 | "type": "integer" | ||
| 1928 | }, | ||
| 1929 | "sp_rank": { | ||
| 1930 | "type": "integer" | ||
| 1931 | }, | ||
| 1932 | "sp_score": { | ||
| 1933 | "type": "integer" | ||
| 1934 | }, | ||
| 1935 | "steam_id": { | ||
| 1936 | "type": "string" | ||
| 1937 | }, | ||
| 1938 | "user_name": { | ||
| 1939 | "type": "string" | ||
| 1940 | } | ||
| 1941 | } | ||
| 1942 | }, | ||
| 1857 | "models.Category": { | 1943 | "models.Category": { |
| 1858 | "type": "object", | 1944 | "type": "object", |
| 1859 | "properties": { | 1945 | "properties": { |
diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index 6de5978..7613d2c 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json | |||
| @@ -1165,9 +1165,9 @@ | |||
| 1165 | } | 1165 | } |
| 1166 | } | 1166 | } |
| 1167 | }, | 1167 | }, |
| 1168 | "/rankings": { | 1168 | "/rankings/lphub": { |
| 1169 | "get": { | 1169 | "get": { |
| 1170 | "description": "Get rankings of every player.", | 1170 | "description": "Get rankings of every player from LPHUB.", |
| 1171 | "produces": [ | 1171 | "produces": [ |
| 1172 | "application/json" | 1172 | "application/json" |
| 1173 | ], | 1173 | ], |
| @@ -1196,6 +1196,37 @@ | |||
| 1196 | } | 1196 | } |
| 1197 | } | 1197 | } |
| 1198 | }, | 1198 | }, |
| 1199 | "/rankings/steam": { | ||
| 1200 | "get": { | ||
| 1201 | "description": "Get rankings of every player from Steam.", | ||
| 1202 | "produces": [ | ||
| 1203 | "application/json" | ||
| 1204 | ], | ||
| 1205 | "tags": [ | ||
| 1206 | "rankings" | ||
| 1207 | ], | ||
| 1208 | "responses": { | ||
| 1209 | "200": { | ||
| 1210 | "description": "OK", | ||
| 1211 | "schema": { | ||
| 1212 | "allOf": [ | ||
| 1213 | { | ||
| 1214 | "$ref": "#/definitions/models.Response" | ||
| 1215 | }, | ||
| 1216 | { | ||
| 1217 | "type": "object", | ||
| 1218 | "properties": { | ||
| 1219 | "data": { | ||
| 1220 | "$ref": "#/definitions/handlers.RankingsSteamResponse" | ||
| 1221 | } | ||
| 1222 | } | ||
| 1223 | } | ||
| 1224 | ] | ||
| 1225 | } | ||
| 1226 | } | ||
| 1227 | } | ||
| 1228 | } | ||
| 1229 | }, | ||
| 1199 | "/search": { | 1230 | "/search": { |
| 1200 | "get": { | 1231 | "get": { |
| 1201 | "description": "Get all user and map data matching to the query.", | 1232 | "description": "Get all user and map data matching to the query.", |
| @@ -1783,6 +1814,29 @@ | |||
| 1783 | } | 1814 | } |
| 1784 | } | 1815 | } |
| 1785 | }, | 1816 | }, |
| 1817 | "handlers.RankingsSteamResponse": { | ||
| 1818 | "type": "object", | ||
| 1819 | "properties": { | ||
| 1820 | "rankings_multiplayer": { | ||
| 1821 | "type": "array", | ||
| 1822 | "items": { | ||
| 1823 | "$ref": "#/definitions/handlers.SteamUserRanking" | ||
| 1824 | } | ||
| 1825 | }, | ||
| 1826 | "rankings_overall": { | ||
| 1827 | "type": "array", | ||
| 1828 | "items": { | ||
| 1829 | "$ref": "#/definitions/handlers.SteamUserRanking" | ||
| 1830 | } | ||
| 1831 | }, | ||
| 1832 | "rankings_singleplayer": { | ||
| 1833 | "type": "array", | ||
| 1834 | "items": { | ||
| 1835 | "$ref": "#/definitions/handlers.SteamUserRanking" | ||
| 1836 | } | ||
| 1837 | } | ||
| 1838 | } | ||
| 1839 | }, | ||
| 1786 | "handlers.RecordResponse": { | 1840 | "handlers.RecordResponse": { |
| 1787 | "type": "object", | 1841 | "type": "object", |
| 1788 | "properties": { | 1842 | "properties": { |
| @@ -1848,6 +1902,38 @@ | |||
| 1848 | } | 1902 | } |
| 1849 | } | 1903 | } |
| 1850 | }, | 1904 | }, |
| 1905 | "handlers.SteamUserRanking": { | ||
| 1906 | "type": "object", | ||
| 1907 | "properties": { | ||
| 1908 | "avatar_link": { | ||
| 1909 | "type": "string" | ||
| 1910 | }, | ||
| 1911 | "mp_rank": { | ||
| 1912 | "type": "integer" | ||
| 1913 | }, | ||
| 1914 | "mp_score": { | ||
| 1915 | "type": "integer" | ||
| 1916 | }, | ||
| 1917 | "overall_rank": { | ||
| 1918 | "type": "integer" | ||
| 1919 | }, | ||
| 1920 | "overall_score": { | ||
| 1921 | "type": "integer" | ||
| 1922 | }, | ||
| 1923 | "sp_rank": { | ||
| 1924 | "type": "integer" | ||
| 1925 | }, | ||
| 1926 | "sp_score": { | ||
| 1927 | "type": "integer" | ||
| 1928 | }, | ||
| 1929 | "steam_id": { | ||
| 1930 | "type": "string" | ||
| 1931 | }, | ||
| 1932 | "user_name": { | ||
| 1933 | "type": "string" | ||
| 1934 | } | ||
| 1935 | } | ||
| 1936 | }, | ||
| 1851 | "models.Category": { | 1937 | "models.Category": { |
| 1852 | "type": "object", | 1938 | "type": "object", |
| 1853 | "properties": { | 1939 | "properties": { |
diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 853b3b9..22651e3 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml | |||
| @@ -283,6 +283,21 @@ definitions: | |||
| 283 | $ref: '#/definitions/models.UserRanking' | 283 | $ref: '#/definitions/models.UserRanking' |
| 284 | type: array | 284 | type: array |
| 285 | type: object | 285 | type: object |
| 286 | handlers.RankingsSteamResponse: | ||
| 287 | properties: | ||
| 288 | rankings_multiplayer: | ||
| 289 | items: | ||
| 290 | $ref: '#/definitions/handlers.SteamUserRanking' | ||
| 291 | type: array | ||
| 292 | rankings_overall: | ||
| 293 | items: | ||
| 294 | $ref: '#/definitions/handlers.SteamUserRanking' | ||
| 295 | type: array | ||
| 296 | rankings_singleplayer: | ||
| 297 | items: | ||
| 298 | $ref: '#/definitions/handlers.SteamUserRanking' | ||
| 299 | type: array | ||
| 300 | type: object | ||
| 286 | handlers.RecordResponse: | 301 | handlers.RecordResponse: |
| 287 | properties: | 302 | properties: |
| 288 | score_count: | 303 | score_count: |
| @@ -325,6 +340,27 @@ definitions: | |||
| 325 | $ref: '#/definitions/models.UserShortWithAvatar' | 340 | $ref: '#/definitions/models.UserShortWithAvatar' |
| 326 | type: array | 341 | type: array |
| 327 | type: object | 342 | type: object |
| 343 | handlers.SteamUserRanking: | ||
| 344 | properties: | ||
| 345 | avatar_link: | ||
| 346 | type: string | ||
| 347 | mp_rank: | ||
| 348 | type: integer | ||
| 349 | mp_score: | ||
| 350 | type: integer | ||
| 351 | overall_rank: | ||
| 352 | type: integer | ||
| 353 | overall_score: | ||
| 354 | type: integer | ||
| 355 | sp_rank: | ||
| 356 | type: integer | ||
| 357 | sp_score: | ||
| 358 | type: integer | ||
| 359 | steam_id: | ||
| 360 | type: string | ||
| 361 | user_name: | ||
| 362 | type: string | ||
| 363 | type: object | ||
| 328 | models.Category: | 364 | models.Category: |
| 329 | properties: | 365 | properties: |
| 330 | id: | 366 | id: |
| @@ -1216,9 +1252,9 @@ paths: | |||
| 1216 | $ref: '#/definitions/models.Response' | 1252 | $ref: '#/definitions/models.Response' |
| 1217 | tags: | 1253 | tags: |
| 1218 | - users | 1254 | - users |
| 1219 | /rankings: | 1255 | /rankings/lphub: |
| 1220 | get: | 1256 | get: |
| 1221 | description: Get rankings of every player. | 1257 | description: Get rankings of every player from LPHUB. |
| 1222 | produces: | 1258 | produces: |
| 1223 | - application/json | 1259 | - application/json |
| 1224 | responses: | 1260 | responses: |
| @@ -1233,6 +1269,23 @@ paths: | |||
| 1233 | type: object | 1269 | type: object |
| 1234 | tags: | 1270 | tags: |
| 1235 | - rankings | 1271 | - rankings |
| 1272 | /rankings/steam: | ||
| 1273 | get: | ||
| 1274 | description: Get rankings of every player from Steam. | ||
| 1275 | produces: | ||
| 1276 | - application/json | ||
| 1277 | responses: | ||
| 1278 | "200": | ||
| 1279 | description: OK | ||
| 1280 | schema: | ||
| 1281 | allOf: | ||
| 1282 | - $ref: '#/definitions/models.Response' | ||
| 1283 | - properties: | ||
| 1284 | data: | ||
| 1285 | $ref: '#/definitions/handlers.RankingsSteamResponse' | ||
| 1286 | type: object | ||
| 1287 | tags: | ||
| 1288 | - rankings | ||
| 1236 | /search: | 1289 | /search: |
| 1237 | get: | 1290 | get: |
| 1238 | description: Get all user and map data matching to the query. | 1291 | description: Get all user and map data matching to the query. |
diff --git a/backend/handlers/home.go b/backend/handlers/home.go index 1734d28..fd7c6c0 100644 --- a/backend/handlers/home.go +++ b/backend/handlers/home.go | |||
| @@ -1,8 +1,11 @@ | |||
| 1 | package handlers | 1 | package handlers |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "encoding/json" | ||
| 5 | "io" | ||
| 4 | "log" | 6 | "log" |
| 5 | "net/http" | 7 | "net/http" |
| 8 | "os" | ||
| 6 | "sort" | 9 | "sort" |
| 7 | "strings" | 10 | "strings" |
| 8 | 11 | ||
| @@ -18,9 +21,26 @@ type SearchResponse struct { | |||
| 18 | } | 21 | } |
| 19 | 22 | ||
| 20 | type RankingsResponse struct { | 23 | type RankingsResponse struct { |
| 21 | Overall []models.UserRanking `json:"rankings_overall"` | ||
| 22 | Singleplayer []models.UserRanking `json:"rankings_singleplayer"` | 24 | Singleplayer []models.UserRanking `json:"rankings_singleplayer"` |
| 23 | Multiplayer []models.UserRanking `json:"rankings_multiplayer"` | 25 | Multiplayer []models.UserRanking `json:"rankings_multiplayer"` |
| 26 | Overall []models.UserRanking `json:"rankings_overall"` | ||
| 27 | } | ||
| 28 | |||
| 29 | type SteamUserRanking struct { | ||
| 30 | UserName string `json:"user_name"` | ||
| 31 | AvatarLink string `json:"avatar_link"` | ||
| 32 | SteamID string `json:"steam_id"` | ||
| 33 | SpScore int `json:"sp_score"` | ||
| 34 | MpScore int `json:"mp_score"` | ||
| 35 | OverallScore int `json:"overall_score"` | ||
| 36 | SpRank int `json:"sp_rank"` | ||
| 37 | MpRank int `json:"mp_rank"` | ||
| 38 | OverallRank int `json:"overall_rank"` | ||
| 39 | } | ||
| 40 | type RankingsSteamResponse struct { | ||
| 41 | Singleplayer []SteamUserRanking `json:"rankings_singleplayer"` | ||
| 42 | Multiplayer []SteamUserRanking `json:"rankings_multiplayer"` | ||
| 43 | Overall []SteamUserRanking `json:"rankings_overall"` | ||
| 24 | } | 44 | } |
| 25 | 45 | ||
| 26 | type MapShortWithGame struct { | 46 | type MapShortWithGame struct { |
| @@ -30,18 +50,18 @@ type MapShortWithGame struct { | |||
| 30 | Map string `json:"map"` | 50 | Map string `json:"map"` |
| 31 | } | 51 | } |
| 32 | 52 | ||
| 33 | // GET Rankings | 53 | // GET Rankings LPHUB |
| 34 | // | 54 | // |
| 35 | // @Description Get rankings of every player. | 55 | // @Description Get rankings of every player from LPHUB. |
| 36 | // @Tags rankings | 56 | // @Tags rankings |
| 37 | // @Produce json | 57 | // @Produce json |
| 38 | // @Success 200 {object} models.Response{data=RankingsResponse} | 58 | // @Success 200 {object} models.Response{data=RankingsResponse} |
| 39 | // @Router /rankings [get] | 59 | // @Router /rankings/lphub [get] |
| 40 | func Rankings(c *gin.Context) { | 60 | func RankingsLPHUB(c *gin.Context) { |
| 41 | response := RankingsResponse{ | 61 | response := RankingsResponse{ |
| 42 | Overall: []models.UserRanking{}, | ||
| 43 | Singleplayer: []models.UserRanking{}, | 62 | Singleplayer: []models.UserRanking{}, |
| 44 | Multiplayer: []models.UserRanking{}, | 63 | Multiplayer: []models.UserRanking{}, |
| 64 | Overall: []models.UserRanking{}, | ||
| 45 | } | 65 | } |
| 46 | // Singleplayer rankings | 66 | // Singleplayer rankings |
| 47 | sql := `SELECT u.steam_id, u.user_name, u.avatar_link, COUNT(DISTINCT map_id), | 67 | sql := `SELECT u.steam_id, u.user_name, u.avatar_link, COUNT(DISTINCT map_id), |
| @@ -171,6 +191,74 @@ func Rankings(c *gin.Context) { | |||
| 171 | }) | 191 | }) |
| 172 | } | 192 | } |
| 173 | 193 | ||
| 194 | // GET Rankings Steam | ||
| 195 | // | ||
| 196 | // @Description Get rankings of every player from Steam. | ||
| 197 | // @Tags rankings | ||
| 198 | // @Produce json | ||
| 199 | // @Success 200 {object} models.Response{data=RankingsSteamResponse} | ||
| 200 | // @Router /rankings/steam [get] | ||
| 201 | func RankingsSteam(c *gin.Context) { | ||
| 202 | response := RankingsSteamResponse{ | ||
| 203 | Singleplayer: []SteamUserRanking{}, | ||
| 204 | Multiplayer: []SteamUserRanking{}, | ||
| 205 | Overall: []SteamUserRanking{}, | ||
| 206 | } | ||
| 207 | spJson, err := os.Open("../rankings/output/sp.json") | ||
| 208 | if err != nil { | ||
| 209 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 210 | return | ||
| 211 | } | ||
| 212 | defer spJson.Close() | ||
| 213 | spJsonBytes, err := io.ReadAll(spJson) | ||
| 214 | if err != nil { | ||
| 215 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 216 | return | ||
| 217 | } | ||
| 218 | err = json.Unmarshal(spJsonBytes, &response.Singleplayer) | ||
| 219 | if err != nil { | ||
| 220 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 221 | return | ||
| 222 | } | ||
| 223 | mpJson, err := os.Open("../rankings/output/mp.json") | ||
| 224 | if err != nil { | ||
| 225 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 226 | return | ||
| 227 | } | ||
| 228 | defer mpJson.Close() | ||
| 229 | mpJsonBytes, err := io.ReadAll(mpJson) | ||
| 230 | if err != nil { | ||
| 231 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 232 | return | ||
| 233 | } | ||
| 234 | err = json.Unmarshal(mpJsonBytes, &response.Multiplayer) | ||
| 235 | if err != nil { | ||
| 236 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 237 | return | ||
| 238 | } | ||
| 239 | overallJson, err := os.Open("../rankings/output/overall.json") | ||
| 240 | if err != nil { | ||
| 241 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 242 | return | ||
| 243 | } | ||
| 244 | defer overallJson.Close() | ||
| 245 | overallJsonBytes, err := io.ReadAll(overallJson) | ||
| 246 | if err != nil { | ||
| 247 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 248 | return | ||
| 249 | } | ||
| 250 | err = json.Unmarshal(overallJsonBytes, &response.Overall) | ||
| 251 | if err != nil { | ||
| 252 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) | ||
| 253 | return | ||
| 254 | } | ||
| 255 | c.JSON(http.StatusOK, models.Response{ | ||
| 256 | Success: true, | ||
| 257 | Message: "Successfully retrieved rankings.", | ||
| 258 | Data: response, | ||
| 259 | }) | ||
| 260 | } | ||
| 261 | |||
| 174 | // GET Search With Query | 262 | // GET Search With Query |
| 175 | // | 263 | // |
| 176 | // @Description Get all user and map data matching to the query. | 264 | // @Description Get all user and map data matching to the query. |