diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-05-02 23:25:48 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-05-02 23:25:48 +0300 |
| commit | 0a2c6021e36be31aaffe8ace232179e2211b3140 (patch) | |
| tree | ac75a36f2f1cca02f782800144de2292782cbc0c | |
| parent | feat: set cookie and redirect after login (diff) | |
| download | lphub-0a2c6021e36be31aaffe8ace232179e2211b3140.tar.gz lphub-0a2c6021e36be31aaffe8ace232179e2211b3140.tar.bz2 lphub-0a2c6021e36be31aaffe8ace232179e2211b3140.zip | |
feat: game, chapter, map endpoints for records page
| -rw-r--r-- | backend/controllers/mapController.go | 108 | ||||
| -rw-r--r-- | backend/models/models.go | 17 | ||||
| -rw-r--r-- | backend/routes/routes.go | 3 | ||||
| -rw-r--r-- | docs/docs.go | 228 | ||||
| -rw-r--r-- | docs/swagger.json | 228 | ||||
| -rw-r--r-- | docs/swagger.yaml | 138 |
6 files changed, 703 insertions, 19 deletions
diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index bd85a97..2bf1fdc 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go | |||
| @@ -15,7 +15,6 @@ import ( | |||
| 15 | // | 15 | // |
| 16 | // @Summary Get map summary with specified id. | 16 | // @Summary Get map summary with specified id. |
| 17 | // @Tags maps | 17 | // @Tags maps |
| 18 | // @Accept json | ||
| 19 | // @Produce json | 18 | // @Produce json |
| 20 | // @Param id path int true "Map ID" | 19 | // @Param id path int true "Map ID" |
| 21 | // @Success 200 {object} models.Response{data=models.Map{data=models.MapSummary}} | 20 | // @Success 200 {object} models.Response{data=models.Map{data=models.MapSummary}} |
| @@ -103,7 +102,6 @@ func FetchMapSummary(c *gin.Context) { | |||
| 103 | // | 102 | // |
| 104 | // @Summary Get map leaderboards with specified id. | 103 | // @Summary Get map leaderboards with specified id. |
| 105 | // @Tags maps | 104 | // @Tags maps |
| 106 | // @Accept json | ||
| 107 | // @Produce json | 105 | // @Produce json |
| 108 | // @Param id path int true "Map ID" | 106 | // @Param id path int true "Map ID" |
| 109 | // @Success 200 {object} models.Response{data=models.Map{data=models.MapRecords}} | 107 | // @Success 200 {object} models.Response{data=models.Map{data=models.MapRecords}} |
| @@ -215,3 +213,109 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 215 | Data: mapData, | 213 | Data: mapData, |
| 216 | }) | 214 | }) |
| 217 | } | 215 | } |
| 216 | |||
| 217 | // GET Games | ||
| 218 | // | ||
| 219 | // @Summary Get games from the leaderboards. | ||
| 220 | // @Tags games | ||
| 221 | // @Produce json | ||
| 222 | // @Success 200 {object} models.Response{data=[]models.Game} | ||
| 223 | // @Failure 400 {object} models.Response | ||
| 224 | // @Router /games [get] | ||
| 225 | func FetchGames(c *gin.Context) { | ||
| 226 | rows, err := database.DB.Query(`SELECT id, name FROM games`) | ||
| 227 | if err != nil { | ||
| 228 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 229 | return | ||
| 230 | } | ||
| 231 | var games []models.Game | ||
| 232 | for rows.Next() { | ||
| 233 | var game models.Game | ||
| 234 | if err := rows.Scan(&game.ID, &game.Name); err != nil { | ||
| 235 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 236 | return | ||
| 237 | } | ||
| 238 | games = append(games, game) | ||
| 239 | } | ||
| 240 | c.JSON(http.StatusOK, models.Response{ | ||
| 241 | Success: true, | ||
| 242 | Message: "Successfully retrieved games.", | ||
| 243 | Data: games, | ||
| 244 | }) | ||
| 245 | } | ||
| 246 | |||
| 247 | // GET Chapters of a Game | ||
| 248 | // | ||
| 249 | // @Summary Get chapters from the specified game id. | ||
| 250 | // @Tags chapters | ||
| 251 | // @Produce json | ||
| 252 | // @Param id path int true "Game ID" | ||
| 253 | // @Success 200 {object} models.Response{data=[]models.Chapter} | ||
| 254 | // @Failure 400 {object} models.Response | ||
| 255 | // @Router /chapters/{id} [get] | ||
| 256 | func FetchChapters(c *gin.Context) { | ||
| 257 | gameID := c.Param("id") | ||
| 258 | intID, err := strconv.Atoi(gameID) | ||
| 259 | if err != nil { | ||
| 260 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 261 | return | ||
| 262 | } | ||
| 263 | rows, err := database.DB.Query(`SELECT id, name FROM chapters WHERE game_id = $1`, gameID) | ||
| 264 | if err != nil { | ||
| 265 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 266 | return | ||
| 267 | } | ||
| 268 | var chapters []models.Chapter | ||
| 269 | for rows.Next() { | ||
| 270 | var chapter models.Chapter | ||
| 271 | if err := rows.Scan(&chapter.ID, &chapter.Name); err != nil { | ||
| 272 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 273 | return | ||
| 274 | } | ||
| 275 | chapter.GameID = intID | ||
| 276 | chapters = append(chapters, chapter) | ||
| 277 | } | ||
| 278 | c.JSON(http.StatusOK, models.Response{ | ||
| 279 | Success: true, | ||
| 280 | Message: "Successfully retrieved chapters.", | ||
| 281 | Data: chapters, | ||
| 282 | }) | ||
| 283 | } | ||
| 284 | |||
| 285 | // GET Maps of a Chapter | ||
| 286 | // | ||
| 287 | // @Summary Get maps from the specified chapter id. | ||
| 288 | // @Tags maps | ||
| 289 | // @Produce json | ||
| 290 | // @Param id path int true "Chapter ID" | ||
| 291 | // @Success 200 {object} models.Response{data=[]models.MapShort} | ||
| 292 | // @Failure 400 {object} models.Response | ||
| 293 | // @Router /maps/{id} [get] | ||
| 294 | func FetchChapterMaps(c *gin.Context) { | ||
| 295 | chapterID := c.Param("id") | ||
| 296 | intID, err := strconv.Atoi(chapterID) | ||
| 297 | if err != nil { | ||
| 298 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 299 | return | ||
| 300 | } | ||
| 301 | rows, err := database.DB.Query(`SELECT id, name FROM maps WHERE chapter_id = $1`, chapterID) | ||
| 302 | if err != nil { | ||
| 303 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 304 | return | ||
| 305 | } | ||
| 306 | var maps []models.MapShort | ||
| 307 | for rows.Next() { | ||
| 308 | var mapShort models.MapShort | ||
| 309 | if err := rows.Scan(&mapShort.ID, &mapShort.Name); err != nil { | ||
| 310 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 311 | return | ||
| 312 | } | ||
| 313 | mapShort.ChapterID = intID | ||
| 314 | maps = append(maps, mapShort) | ||
| 315 | } | ||
| 316 | c.JSON(http.StatusOK, models.Response{ | ||
| 317 | Success: true, | ||
| 318 | Message: "Successfully retrieved maps.", | ||
| 319 | Data: maps, | ||
| 320 | }) | ||
| 321 | } | ||
diff --git a/backend/models/models.go b/backend/models/models.go index cdcd111..8f77a93 100644 --- a/backend/models/models.go +++ b/backend/models/models.go | |||
| @@ -153,6 +153,23 @@ type PlayerSummaries struct { | |||
| 153 | GameServerIp string `json:"gameserverip"` | 153 | GameServerIp string `json:"gameserverip"` |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | type Game struct { | ||
| 157 | ID int `json:"id"` | ||
| 158 | Name string `json:"name"` | ||
| 159 | } | ||
| 160 | |||
| 161 | type Chapter struct { | ||
| 162 | ID int `json:"id"` | ||
| 163 | GameID int `json:"game_id"` | ||
| 164 | Name string `json:"name"` | ||
| 165 | } | ||
| 166 | |||
| 167 | type MapShort struct { | ||
| 168 | ID int `json:"id"` | ||
| 169 | ChapterID int `json:"chapter_id"` | ||
| 170 | Name string `json:"name"` | ||
| 171 | } | ||
| 172 | |||
| 156 | func ErrorResponse(message string) Response { | 173 | func ErrorResponse(message string) Response { |
| 157 | return Response{ | 174 | return Response{ |
| 158 | Success: false, | 175 | Success: false, |
diff --git a/backend/routes/routes.go b/backend/routes/routes.go index 53d4e78..2741208 100644 --- a/backend/routes/routes.go +++ b/backend/routes/routes.go | |||
| @@ -26,7 +26,10 @@ func InitRoutes(router *gin.Engine) { | |||
| 26 | v1.GET("/maps/:id/summary", middleware.CheckAuth, controllers.FetchMapSummary) | 26 | v1.GET("/maps/:id/summary", middleware.CheckAuth, controllers.FetchMapSummary) |
| 27 | v1.GET("/maps/:id/leaderboards", middleware.CheckAuth, controllers.FetchMapLeaderboards) | 27 | v1.GET("/maps/:id/leaderboards", middleware.CheckAuth, controllers.FetchMapLeaderboards) |
| 28 | v1.POST("/maps/:id/record", middleware.CheckAuth, controllers.CreateRecordWithDemo) | 28 | v1.POST("/maps/:id/record", middleware.CheckAuth, controllers.CreateRecordWithDemo) |
| 29 | v1.GET("/maps/:id", controllers.FetchChapterMaps) | ||
| 29 | v1.GET("/rankings", middleware.CheckAuth, controllers.Rankings) | 30 | v1.GET("/rankings", middleware.CheckAuth, controllers.Rankings) |
| 30 | v1.GET("/search", controllers.Search) | 31 | v1.GET("/search", controllers.Search) |
| 32 | v1.GET("/games", controllers.FetchGames) | ||
| 33 | v1.GET("/chapters/:id", controllers.FetchChapters) | ||
| 31 | } | 34 | } |
| 32 | } | 35 | } |
diff --git a/docs/docs.go b/docs/docs.go index 22d4362..788ca3d 100644 --- a/docs/docs.go +++ b/docs/docs.go | |||
| @@ -20,6 +20,55 @@ const docTemplate = `{ | |||
| 20 | "host": "{{.Host}}", | 20 | "host": "{{.Host}}", |
| 21 | "basePath": "{{.BasePath}}", | 21 | "basePath": "{{.BasePath}}", |
| 22 | "paths": { | 22 | "paths": { |
| 23 | "/chapters/{id}": { | ||
| 24 | "get": { | ||
| 25 | "produces": [ | ||
| 26 | "application/json" | ||
| 27 | ], | ||
| 28 | "tags": [ | ||
| 29 | "chapters" | ||
| 30 | ], | ||
| 31 | "summary": "Get chapters from the specified game id.", | ||
| 32 | "parameters": [ | ||
| 33 | { | ||
| 34 | "type": "integer", | ||
| 35 | "description": "Game ID", | ||
| 36 | "name": "id", | ||
| 37 | "in": "path", | ||
| 38 | "required": true | ||
| 39 | } | ||
| 40 | ], | ||
| 41 | "responses": { | ||
| 42 | "200": { | ||
| 43 | "description": "OK", | ||
| 44 | "schema": { | ||
| 45 | "allOf": [ | ||
| 46 | { | ||
| 47 | "$ref": "#/definitions/models.Response" | ||
| 48 | }, | ||
| 49 | { | ||
| 50 | "type": "object", | ||
| 51 | "properties": { | ||
| 52 | "data": { | ||
| 53 | "type": "array", | ||
| 54 | "items": { | ||
| 55 | "$ref": "#/definitions/models.Chapter" | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | ] | ||
| 61 | } | ||
| 62 | }, | ||
| 63 | "400": { | ||
| 64 | "description": "Bad Request", | ||
| 65 | "schema": { | ||
| 66 | "$ref": "#/definitions/models.Response" | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | }, | ||
| 23 | "/demo": { | 72 | "/demo": { |
| 24 | "get": { | 73 | "get": { |
| 25 | "produces": [ | 74 | "produces": [ |
| @@ -94,6 +143,46 @@ const docTemplate = `{ | |||
| 94 | } | 143 | } |
| 95 | } | 144 | } |
| 96 | }, | 145 | }, |
| 146 | "/games": { | ||
| 147 | "get": { | ||
| 148 | "produces": [ | ||
| 149 | "application/json" | ||
| 150 | ], | ||
| 151 | "tags": [ | ||
| 152 | "games" | ||
| 153 | ], | ||
| 154 | "summary": "Get games from the leaderboards.", | ||
| 155 | "responses": { | ||
| 156 | "200": { | ||
| 157 | "description": "OK", | ||
| 158 | "schema": { | ||
| 159 | "allOf": [ | ||
| 160 | { | ||
| 161 | "$ref": "#/definitions/models.Response" | ||
| 162 | }, | ||
| 163 | { | ||
| 164 | "type": "object", | ||
| 165 | "properties": { | ||
| 166 | "data": { | ||
| 167 | "type": "array", | ||
| 168 | "items": { | ||
| 169 | "$ref": "#/definitions/models.Game" | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 174 | ] | ||
| 175 | } | ||
| 176 | }, | ||
| 177 | "400": { | ||
| 178 | "description": "Bad Request", | ||
| 179 | "schema": { | ||
| 180 | "$ref": "#/definitions/models.Response" | ||
| 181 | } | ||
| 182 | } | ||
| 183 | } | ||
| 184 | } | ||
| 185 | }, | ||
| 97 | "/login": { | 186 | "/login": { |
| 98 | "get": { | 187 | "get": { |
| 99 | "consumes": [ | 188 | "consumes": [ |
| @@ -134,11 +223,57 @@ const docTemplate = `{ | |||
| 134 | } | 223 | } |
| 135 | } | 224 | } |
| 136 | }, | 225 | }, |
| 137 | "/maps/{id}/leaderboards": { | 226 | "/maps/{id}": { |
| 138 | "get": { | 227 | "get": { |
| 139 | "consumes": [ | 228 | "produces": [ |
| 140 | "application/json" | 229 | "application/json" |
| 141 | ], | 230 | ], |
| 231 | "tags": [ | ||
| 232 | "maps" | ||
| 233 | ], | ||
| 234 | "summary": "Get maps from the specified chapter id.", | ||
| 235 | "parameters": [ | ||
| 236 | { | ||
| 237 | "type": "integer", | ||
| 238 | "description": "Chapter ID", | ||
| 239 | "name": "id", | ||
| 240 | "in": "path", | ||
| 241 | "required": true | ||
| 242 | } | ||
| 243 | ], | ||
| 244 | "responses": { | ||
| 245 | "200": { | ||
| 246 | "description": "OK", | ||
| 247 | "schema": { | ||
| 248 | "allOf": [ | ||
| 249 | { | ||
| 250 | "$ref": "#/definitions/models.Response" | ||
| 251 | }, | ||
| 252 | { | ||
| 253 | "type": "object", | ||
| 254 | "properties": { | ||
| 255 | "data": { | ||
| 256 | "type": "array", | ||
| 257 | "items": { | ||
| 258 | "$ref": "#/definitions/models.MapShort" | ||
| 259 | } | ||
| 260 | } | ||
| 261 | } | ||
| 262 | } | ||
| 263 | ] | ||
| 264 | } | ||
| 265 | }, | ||
| 266 | "400": { | ||
| 267 | "description": "Bad Request", | ||
| 268 | "schema": { | ||
| 269 | "$ref": "#/definitions/models.Response" | ||
| 270 | } | ||
| 271 | } | ||
| 272 | } | ||
| 273 | } | ||
| 274 | }, | ||
| 275 | "/maps/{id}/leaderboards": { | ||
| 276 | "get": { | ||
| 142 | "produces": [ | 277 | "produces": [ |
| 143 | "application/json" | 278 | "application/json" |
| 144 | ], | 279 | ], |
| @@ -290,9 +425,6 @@ const docTemplate = `{ | |||
| 290 | }, | 425 | }, |
| 291 | "/maps/{id}/summary": { | 426 | "/maps/{id}/summary": { |
| 292 | "get": { | 427 | "get": { |
| 293 | "consumes": [ | ||
| 294 | "application/json" | ||
| 295 | ], | ||
| 296 | "produces": [ | 428 | "produces": [ |
| 297 | "application/json" | 429 | "application/json" |
| 298 | ], | 430 | ], |
| @@ -530,7 +662,19 @@ const docTemplate = `{ | |||
| 530 | "200": { | 662 | "200": { |
| 531 | "description": "OK", | 663 | "description": "OK", |
| 532 | "schema": { | 664 | "schema": { |
| 533 | "$ref": "#/definitions/models.Response" | 665 | "allOf": [ |
| 666 | { | ||
| 667 | "$ref": "#/definitions/models.Response" | ||
| 668 | }, | ||
| 669 | { | ||
| 670 | "type": "object", | ||
| 671 | "properties": { | ||
| 672 | "data": { | ||
| 673 | "$ref": "#/definitions/models.SearchResponse" | ||
| 674 | } | ||
| 675 | } | ||
| 676 | } | ||
| 677 | ] | ||
| 534 | } | 678 | } |
| 535 | }, | 679 | }, |
| 536 | "400": { | 680 | "400": { |
| @@ -599,6 +743,31 @@ const docTemplate = `{ | |||
| 599 | } | 743 | } |
| 600 | }, | 744 | }, |
| 601 | "definitions": { | 745 | "definitions": { |
| 746 | "models.Chapter": { | ||
| 747 | "type": "object", | ||
| 748 | "properties": { | ||
| 749 | "game_id": { | ||
| 750 | "type": "integer" | ||
| 751 | }, | ||
| 752 | "id": { | ||
| 753 | "type": "integer" | ||
| 754 | }, | ||
| 755 | "name": { | ||
| 756 | "type": "string" | ||
| 757 | } | ||
| 758 | } | ||
| 759 | }, | ||
| 760 | "models.Game": { | ||
| 761 | "type": "object", | ||
| 762 | "properties": { | ||
| 763 | "id": { | ||
| 764 | "type": "integer" | ||
| 765 | }, | ||
| 766 | "name": { | ||
| 767 | "type": "string" | ||
| 768 | } | ||
| 769 | } | ||
| 770 | }, | ||
| 602 | "models.LoginResponse": { | 771 | "models.LoginResponse": { |
| 603 | "type": "object", | 772 | "type": "object", |
| 604 | "properties": { | 773 | "properties": { |
| @@ -662,6 +831,20 @@ const docTemplate = `{ | |||
| 662 | "records": {} | 831 | "records": {} |
| 663 | } | 832 | } |
| 664 | }, | 833 | }, |
| 834 | "models.MapShort": { | ||
| 835 | "type": "object", | ||
| 836 | "properties": { | ||
| 837 | "chapter_id": { | ||
| 838 | "type": "integer" | ||
| 839 | }, | ||
| 840 | "id": { | ||
| 841 | "type": "integer" | ||
| 842 | }, | ||
| 843 | "name": { | ||
| 844 | "type": "string" | ||
| 845 | } | ||
| 846 | } | ||
| 847 | }, | ||
| 665 | "models.MapSummary": { | 848 | "models.MapSummary": { |
| 666 | "type": "object", | 849 | "type": "object", |
| 667 | "properties": { | 850 | "properties": { |
| @@ -784,6 +967,39 @@ const docTemplate = `{ | |||
| 784 | "records": {} | 967 | "records": {} |
| 785 | } | 968 | } |
| 786 | }, | 969 | }, |
| 970 | "models.SearchResponse": { | ||
| 971 | "type": "object", | ||
| 972 | "properties": { | ||
| 973 | "maps": { | ||
| 974 | "type": "array", | ||
| 975 | "items": { | ||
| 976 | "type": "object", | ||
| 977 | "properties": { | ||
| 978 | "id": { | ||
| 979 | "type": "integer" | ||
| 980 | }, | ||
| 981 | "name": { | ||
| 982 | "type": "string" | ||
| 983 | } | ||
| 984 | } | ||
| 985 | } | ||
| 986 | }, | ||
| 987 | "players": { | ||
| 988 | "type": "array", | ||
| 989 | "items": { | ||
| 990 | "type": "object", | ||
| 991 | "properties": { | ||
| 992 | "steam_id": { | ||
| 993 | "type": "string" | ||
| 994 | }, | ||
| 995 | "user_name": { | ||
| 996 | "type": "string" | ||
| 997 | } | ||
| 998 | } | ||
| 999 | } | ||
| 1000 | } | ||
| 1001 | } | ||
| 1002 | }, | ||
| 787 | "models.UserRanking": { | 1003 | "models.UserRanking": { |
| 788 | "type": "object", | 1004 | "type": "object", |
| 789 | "properties": { | 1005 | "properties": { |
diff --git a/docs/swagger.json b/docs/swagger.json index 0bebe1c..ba0e8a3 100644 --- a/docs/swagger.json +++ b/docs/swagger.json | |||
| @@ -13,6 +13,55 @@ | |||
| 13 | "host": "lp.ardapektezol.com/api", | 13 | "host": "lp.ardapektezol.com/api", |
| 14 | "basePath": "/v1", | 14 | "basePath": "/v1", |
| 15 | "paths": { | 15 | "paths": { |
| 16 | "/chapters/{id}": { | ||
| 17 | "get": { | ||
| 18 | "produces": [ | ||
| 19 | "application/json" | ||
| 20 | ], | ||
| 21 | "tags": [ | ||
| 22 | "chapters" | ||
| 23 | ], | ||
| 24 | "summary": "Get chapters from the specified game id.", | ||
| 25 | "parameters": [ | ||
| 26 | { | ||
| 27 | "type": "integer", | ||
| 28 | "description": "Game ID", | ||
| 29 | "name": "id", | ||
| 30 | "in": "path", | ||
| 31 | "required": true | ||
| 32 | } | ||
| 33 | ], | ||
| 34 | "responses": { | ||
| 35 | "200": { | ||
| 36 | "description": "OK", | ||
| 37 | "schema": { | ||
| 38 | "allOf": [ | ||
| 39 | { | ||
| 40 | "$ref": "#/definitions/models.Response" | ||
| 41 | }, | ||
| 42 | { | ||
| 43 | "type": "object", | ||
| 44 | "properties": { | ||
| 45 | "data": { | ||
| 46 | "type": "array", | ||
| 47 | "items": { | ||
| 48 | "$ref": "#/definitions/models.Chapter" | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | ] | ||
| 54 | } | ||
| 55 | }, | ||
| 56 | "400": { | ||
| 57 | "description": "Bad Request", | ||
| 58 | "schema": { | ||
| 59 | "$ref": "#/definitions/models.Response" | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | }, | ||
| 16 | "/demo": { | 65 | "/demo": { |
| 17 | "get": { | 66 | "get": { |
| 18 | "produces": [ | 67 | "produces": [ |
| @@ -87,6 +136,46 @@ | |||
| 87 | } | 136 | } |
| 88 | } | 137 | } |
| 89 | }, | 138 | }, |
| 139 | "/games": { | ||
| 140 | "get": { | ||
| 141 | "produces": [ | ||
| 142 | "application/json" | ||
| 143 | ], | ||
| 144 | "tags": [ | ||
| 145 | "games" | ||
| 146 | ], | ||
| 147 | "summary": "Get games from the leaderboards.", | ||
| 148 | "responses": { | ||
| 149 | "200": { | ||
| 150 | "description": "OK", | ||
| 151 | "schema": { | ||
| 152 | "allOf": [ | ||
| 153 | { | ||
| 154 | "$ref": "#/definitions/models.Response" | ||
| 155 | }, | ||
| 156 | { | ||
| 157 | "type": "object", | ||
| 158 | "properties": { | ||
| 159 | "data": { | ||
| 160 | "type": "array", | ||
| 161 | "items": { | ||
| 162 | "$ref": "#/definitions/models.Game" | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | } | ||
| 167 | ] | ||
| 168 | } | ||
| 169 | }, | ||
| 170 | "400": { | ||
| 171 | "description": "Bad Request", | ||
| 172 | "schema": { | ||
| 173 | "$ref": "#/definitions/models.Response" | ||
| 174 | } | ||
| 175 | } | ||
| 176 | } | ||
| 177 | } | ||
| 178 | }, | ||
| 90 | "/login": { | 179 | "/login": { |
| 91 | "get": { | 180 | "get": { |
| 92 | "consumes": [ | 181 | "consumes": [ |
| @@ -127,11 +216,57 @@ | |||
| 127 | } | 216 | } |
| 128 | } | 217 | } |
| 129 | }, | 218 | }, |
| 130 | "/maps/{id}/leaderboards": { | 219 | "/maps/{id}": { |
| 131 | "get": { | 220 | "get": { |
| 132 | "consumes": [ | 221 | "produces": [ |
| 133 | "application/json" | 222 | "application/json" |
| 134 | ], | 223 | ], |
| 224 | "tags": [ | ||
| 225 | "maps" | ||
| 226 | ], | ||
| 227 | "summary": "Get maps from the specified chapter id.", | ||
| 228 | "parameters": [ | ||
| 229 | { | ||
| 230 | "type": "integer", | ||
| 231 | "description": "Chapter ID", | ||
| 232 | "name": "id", | ||
| 233 | "in": "path", | ||
| 234 | "required": true | ||
| 235 | } | ||
| 236 | ], | ||
| 237 | "responses": { | ||
| 238 | "200": { | ||
| 239 | "description": "OK", | ||
| 240 | "schema": { | ||
| 241 | "allOf": [ | ||
| 242 | { | ||
| 243 | "$ref": "#/definitions/models.Response" | ||
| 244 | }, | ||
| 245 | { | ||
| 246 | "type": "object", | ||
| 247 | "properties": { | ||
| 248 | "data": { | ||
| 249 | "type": "array", | ||
| 250 | "items": { | ||
| 251 | "$ref": "#/definitions/models.MapShort" | ||
| 252 | } | ||
| 253 | } | ||
| 254 | } | ||
| 255 | } | ||
| 256 | ] | ||
| 257 | } | ||
| 258 | }, | ||
| 259 | "400": { | ||
| 260 | "description": "Bad Request", | ||
| 261 | "schema": { | ||
| 262 | "$ref": "#/definitions/models.Response" | ||
| 263 | } | ||
| 264 | } | ||
| 265 | } | ||
| 266 | } | ||
| 267 | }, | ||
| 268 | "/maps/{id}/leaderboards": { | ||
| 269 | "get": { | ||
| 135 | "produces": [ | 270 | "produces": [ |
| 136 | "application/json" | 271 | "application/json" |
| 137 | ], | 272 | ], |
| @@ -283,9 +418,6 @@ | |||
| 283 | }, | 418 | }, |
| 284 | "/maps/{id}/summary": { | 419 | "/maps/{id}/summary": { |
| 285 | "get": { | 420 | "get": { |
| 286 | "consumes": [ | ||
| 287 | "application/json" | ||
| 288 | ], | ||
| 289 | "produces": [ | 421 | "produces": [ |
| 290 | "application/json" | 422 | "application/json" |
| 291 | ], | 423 | ], |
| @@ -523,7 +655,19 @@ | |||
| 523 | "200": { | 655 | "200": { |
| 524 | "description": "OK", | 656 | "description": "OK", |
| 525 | "schema": { | 657 | "schema": { |
| 526 | "$ref": "#/definitions/models.Response" | 658 | "allOf": [ |
| 659 | { | ||
| 660 | "$ref": "#/definitions/models.Response" | ||
| 661 | }, | ||
| 662 | { | ||
| 663 | "type": "object", | ||
| 664 | "properties": { | ||
| 665 | "data": { | ||
| 666 | "$ref": "#/definitions/models.SearchResponse" | ||
| 667 | } | ||
| 668 | } | ||
| 669 | } | ||
| 670 | ] | ||
| 527 | } | 671 | } |
| 528 | }, | 672 | }, |
| 529 | "400": { | 673 | "400": { |
| @@ -592,6 +736,31 @@ | |||
| 592 | } | 736 | } |
| 593 | }, | 737 | }, |
| 594 | "definitions": { | 738 | "definitions": { |
| 739 | "models.Chapter": { | ||
| 740 | "type": "object", | ||
| 741 | "properties": { | ||
| 742 | "game_id": { | ||
| 743 | "type": "integer" | ||
| 744 | }, | ||
| 745 | "id": { | ||
| 746 | "type": "integer" | ||
| 747 | }, | ||
| 748 | "name": { | ||
| 749 | "type": "string" | ||
| 750 | } | ||
| 751 | } | ||
| 752 | }, | ||
| 753 | "models.Game": { | ||
| 754 | "type": "object", | ||
| 755 | "properties": { | ||
| 756 | "id": { | ||
| 757 | "type": "integer" | ||
| 758 | }, | ||
| 759 | "name": { | ||
| 760 | "type": "string" | ||
| 761 | } | ||
| 762 | } | ||
| 763 | }, | ||
| 595 | "models.LoginResponse": { | 764 | "models.LoginResponse": { |
| 596 | "type": "object", | 765 | "type": "object", |
| 597 | "properties": { | 766 | "properties": { |
| @@ -655,6 +824,20 @@ | |||
| 655 | "records": {} | 824 | "records": {} |
| 656 | } | 825 | } |
| 657 | }, | 826 | }, |
| 827 | "models.MapShort": { | ||
| 828 | "type": "object", | ||
| 829 | "properties": { | ||
| 830 | "chapter_id": { | ||
| 831 | "type": "integer" | ||
| 832 | }, | ||
| 833 | "id": { | ||
| 834 | "type": "integer" | ||
| 835 | }, | ||
| 836 | "name": { | ||
| 837 | "type": "string" | ||
| 838 | } | ||
| 839 | } | ||
| 840 | }, | ||
| 658 | "models.MapSummary": { | 841 | "models.MapSummary": { |
| 659 | "type": "object", | 842 | "type": "object", |
| 660 | "properties": { | 843 | "properties": { |
| @@ -777,6 +960,39 @@ | |||
| 777 | "records": {} | 960 | "records": {} |
| 778 | } | 961 | } |
| 779 | }, | 962 | }, |
| 963 | "models.SearchResponse": { | ||
| 964 | "type": "object", | ||
| 965 | "properties": { | ||
| 966 | "maps": { | ||
| 967 | "type": "array", | ||
| 968 | "items": { | ||
| 969 | "type": "object", | ||
| 970 | "properties": { | ||
| 971 | "id": { | ||
| 972 | "type": "integer" | ||
| 973 | }, | ||
| 974 | "name": { | ||
| 975 | "type": "string" | ||
| 976 | } | ||
| 977 | } | ||
| 978 | } | ||
| 979 | }, | ||
| 980 | "players": { | ||
| 981 | "type": "array", | ||
| 982 | "items": { | ||
| 983 | "type": "object", | ||
| 984 | "properties": { | ||
| 985 | "steam_id": { | ||
| 986 | "type": "string" | ||
| 987 | }, | ||
| 988 | "user_name": { | ||
| 989 | "type": "string" | ||
| 990 | } | ||
| 991 | } | ||
| 992 | } | ||
| 993 | } | ||
| 994 | } | ||
| 995 | }, | ||
| 780 | "models.UserRanking": { | 996 | "models.UserRanking": { |
| 781 | "type": "object", | 997 | "type": "object", |
| 782 | "properties": { | 998 | "properties": { |
diff --git a/docs/swagger.yaml b/docs/swagger.yaml index f719008..8b66ec8 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml | |||
| @@ -1,5 +1,21 @@ | |||
| 1 | basePath: /v1 | 1 | basePath: /v1 |
| 2 | definitions: | 2 | definitions: |
| 3 | models.Chapter: | ||
| 4 | properties: | ||
| 5 | game_id: | ||
| 6 | type: integer | ||
| 7 | id: | ||
| 8 | type: integer | ||
| 9 | name: | ||
| 10 | type: string | ||
| 11 | type: object | ||
| 12 | models.Game: | ||
| 13 | properties: | ||
| 14 | id: | ||
| 15 | type: integer | ||
| 16 | name: | ||
| 17 | type: string | ||
| 18 | type: object | ||
| 3 | models.LoginResponse: | 19 | models.LoginResponse: |
| 4 | properties: | 20 | properties: |
| 5 | token: | 21 | token: |
| @@ -41,6 +57,15 @@ definitions: | |||
| 41 | properties: | 57 | properties: |
| 42 | records: {} | 58 | records: {} |
| 43 | type: object | 59 | type: object |
| 60 | models.MapShort: | ||
| 61 | properties: | ||
| 62 | chapter_id: | ||
| 63 | type: integer | ||
| 64 | id: | ||
| 65 | type: integer | ||
| 66 | name: | ||
| 67 | type: string | ||
| 68 | type: object | ||
| 44 | models.MapSummary: | 69 | models.MapSummary: |
| 45 | properties: | 70 | properties: |
| 46 | category_scores: | 71 | category_scores: |
| @@ -122,6 +147,27 @@ definitions: | |||
| 122 | type: integer | 147 | type: integer |
| 123 | records: {} | 148 | records: {} |
| 124 | type: object | 149 | type: object |
| 150 | models.SearchResponse: | ||
| 151 | properties: | ||
| 152 | maps: | ||
| 153 | items: | ||
| 154 | properties: | ||
| 155 | id: | ||
| 156 | type: integer | ||
| 157 | name: | ||
| 158 | type: string | ||
| 159 | type: object | ||
| 160 | type: array | ||
| 161 | players: | ||
| 162 | items: | ||
| 163 | properties: | ||
| 164 | steam_id: | ||
| 165 | type: string | ||
| 166 | user_name: | ||
| 167 | type: string | ||
| 168 | type: object | ||
| 169 | type: array | ||
| 170 | type: object | ||
| 125 | models.UserRanking: | 171 | models.UserRanking: |
| 126 | properties: | 172 | properties: |
| 127 | total_score: | 173 | total_score: |
| @@ -141,6 +187,35 @@ info: | |||
| 141 | title: Least Portals Database API | 187 | title: Least Portals Database API |
| 142 | version: "1.0" | 188 | version: "1.0" |
| 143 | paths: | 189 | paths: |
| 190 | /chapters/{id}: | ||
| 191 | get: | ||
| 192 | parameters: | ||
| 193 | - description: Game ID | ||
| 194 | in: path | ||
| 195 | name: id | ||
| 196 | required: true | ||
| 197 | type: integer | ||
| 198 | produces: | ||
| 199 | - application/json | ||
| 200 | responses: | ||
| 201 | "200": | ||
| 202 | description: OK | ||
| 203 | schema: | ||
| 204 | allOf: | ||
| 205 | - $ref: '#/definitions/models.Response' | ||
| 206 | - properties: | ||
| 207 | data: | ||
| 208 | items: | ||
| 209 | $ref: '#/definitions/models.Chapter' | ||
| 210 | type: array | ||
| 211 | type: object | ||
| 212 | "400": | ||
| 213 | description: Bad Request | ||
| 214 | schema: | ||
| 215 | $ref: '#/definitions/models.Response' | ||
| 216 | summary: Get chapters from the specified game id. | ||
| 217 | tags: | ||
| 218 | - chapters | ||
| 144 | /demo: | 219 | /demo: |
| 145 | get: | 220 | get: |
| 146 | produces: | 221 | produces: |
| @@ -186,6 +261,29 @@ paths: | |||
| 186 | summary: Get demo with specified demo uuid. | 261 | summary: Get demo with specified demo uuid. |
| 187 | tags: | 262 | tags: |
| 188 | - demo | 263 | - demo |
| 264 | /games: | ||
| 265 | get: | ||
| 266 | produces: | ||
| 267 | - application/json | ||
| 268 | responses: | ||
| 269 | "200": | ||
| 270 | description: OK | ||
| 271 | schema: | ||
| 272 | allOf: | ||
| 273 | - $ref: '#/definitions/models.Response' | ||
| 274 | - properties: | ||
| 275 | data: | ||
| 276 | items: | ||
| 277 | $ref: '#/definitions/models.Game' | ||
| 278 | type: array | ||
| 279 | type: object | ||
| 280 | "400": | ||
| 281 | description: Bad Request | ||
| 282 | schema: | ||
| 283 | $ref: '#/definitions/models.Response' | ||
| 284 | summary: Get games from the leaderboards. | ||
| 285 | tags: | ||
| 286 | - games | ||
| 189 | /login: | 287 | /login: |
| 190 | get: | 288 | get: |
| 191 | consumes: | 289 | consumes: |
| @@ -209,10 +307,37 @@ paths: | |||
| 209 | summary: Get (redirect) login page for Steam auth. | 307 | summary: Get (redirect) login page for Steam auth. |
| 210 | tags: | 308 | tags: |
| 211 | - login | 309 | - login |
| 212 | /maps/{id}/leaderboards: | 310 | /maps/{id}: |
| 213 | get: | 311 | get: |
| 214 | consumes: | 312 | parameters: |
| 313 | - description: Chapter ID | ||
| 314 | in: path | ||
| 315 | name: id | ||
| 316 | required: true | ||
| 317 | type: integer | ||
| 318 | produces: | ||
| 215 | - application/json | 319 | - application/json |
| 320 | responses: | ||
| 321 | "200": | ||
| 322 | description: OK | ||
| 323 | schema: | ||
| 324 | allOf: | ||
| 325 | - $ref: '#/definitions/models.Response' | ||
| 326 | - properties: | ||
| 327 | data: | ||
| 328 | items: | ||
| 329 | $ref: '#/definitions/models.MapShort' | ||
| 330 | type: array | ||
| 331 | type: object | ||
| 332 | "400": | ||
| 333 | description: Bad Request | ||
| 334 | schema: | ||
| 335 | $ref: '#/definitions/models.Response' | ||
| 336 | summary: Get maps from the specified chapter id. | ||
| 337 | tags: | ||
| 338 | - maps | ||
| 339 | /maps/{id}/leaderboards: | ||
| 340 | get: | ||
| 216 | parameters: | 341 | parameters: |
| 217 | - description: Map ID | 342 | - description: Map ID |
| 218 | in: path | 343 | in: path |
| @@ -305,8 +430,6 @@ paths: | |||
| 305 | - maps | 430 | - maps |
| 306 | /maps/{id}/summary: | 431 | /maps/{id}/summary: |
| 307 | get: | 432 | get: |
| 308 | consumes: | ||
| 309 | - application/json | ||
| 310 | parameters: | 433 | parameters: |
| 311 | - description: Map ID | 434 | - description: Map ID |
| 312 | in: path | 435 | in: path |
| @@ -447,7 +570,12 @@ paths: | |||
| 447 | "200": | 570 | "200": |
| 448 | description: OK | 571 | description: OK |
| 449 | schema: | 572 | schema: |
| 450 | $ref: '#/definitions/models.Response' | 573 | allOf: |
| 574 | - $ref: '#/definitions/models.Response' | ||
| 575 | - properties: | ||
| 576 | data: | ||
| 577 | $ref: '#/definitions/models.SearchResponse' | ||
| 578 | type: object | ||
| 451 | "400": | 579 | "400": |
| 452 | description: Bad Request | 580 | description: Bad Request |
| 453 | schema: | 581 | schema: |