aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/api/routes.go2
-rw-r--r--backend/handlers/map.go40
-rw-r--r--docs/docs.go43
-rw-r--r--docs/swagger.json43
-rw-r--r--docs/swagger.yaml25
5 files changed, 153 insertions, 0 deletions
diff --git a/backend/api/routes.go b/backend/api/routes.go
index 9e703f6..2581a75 100644
--- a/backend/api/routes.go
+++ b/backend/api/routes.go
@@ -28,6 +28,7 @@ const (
28 searchPath string = "/search" 28 searchPath string = "/search"
29 gamesPath string = "/games" 29 gamesPath string = "/games"
30 chaptersPath string = "/games/:gameid" 30 chaptersPath string = "/games/:gameid"
31 gameMapsPath string = "/games/:gameid/maps"
31 chapterMapsPath string = "/chapters/:chapterid" 32 chapterMapsPath string = "/chapters/:chapterid"
32 scoreLogsPath string = "/logs/score" 33 scoreLogsPath string = "/logs/score"
33 modLogsPath string = "/logs/mod" 34 modLogsPath string = "/logs/mod"
@@ -76,6 +77,7 @@ func InitRoutes(router *gin.Engine) {
76 v1.GET(gamesPath, handlers.FetchGames) 77 v1.GET(gamesPath, handlers.FetchGames)
77 v1.GET(chaptersPath, handlers.FetchChapters) 78 v1.GET(chaptersPath, handlers.FetchChapters)
78 v1.GET(chapterMapsPath, handlers.FetchChapterMaps) 79 v1.GET(chapterMapsPath, handlers.FetchChapterMaps)
80 v1.GET(gameMapsPath, handlers.FetchMaps)
79 // Logs 81 // Logs
80 v1.GET(scoreLogsPath, handlers.ScoreLogs) 82 v1.GET(scoreLogsPath, handlers.ScoreLogs)
81 v1.GET(modLogsPath, CheckAuth, handlers.ModLogs) 83 v1.GET(modLogsPath, CheckAuth, handlers.ModLogs)
diff --git a/backend/handlers/map.go b/backend/handlers/map.go
index 28457ce..d8f2ff0 100644
--- a/backend/handlers/map.go
+++ b/backend/handlers/map.go
@@ -31,6 +31,11 @@ type ChapterMapsResponse struct {
31 Maps []models.MapShort `json:"maps"` 31 Maps []models.MapShort `json:"maps"`
32} 32}
33 33
34type GameMapsResponse struct {
35 Game models.Game `json:"game"`
36 Maps []models.MapShort `json:"maps"`
37}
38
34type RecordSingleplayer struct { 39type RecordSingleplayer struct {
35 Placement int `json:"placement"` 40 Placement int `json:"placement"`
36 RecordID int `json:"record_id"` 41 RecordID int `json:"record_id"`
@@ -385,6 +390,41 @@ func FetchChapters(c *gin.Context) {
385 }) 390 })
386} 391}
387 392
393// GET Maps of a Game
394//
395// @Description Get maps from the specified game id.
396// @Tags games & chapters
397// @Produce json
398// @Param gameid path int true "Game ID"
399// @Success 200 {object} models.Response{data=ChaptersResponse}
400// @Router /games/{gameid}/maps [get]
401func FetchMaps(c *gin.Context) {
402 gameID, err := strconv.Atoi(c.Param("gameid"))
403 if err != nil {
404 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
405 return
406 }
407 var response GameMapsResponse
408 rows, err := database.DB.Query(`SELECT g.id, g.name, g.is_coop, m.id, m."name", m.is_disabled FROM games g INNER JOIN maps m ON g.id = m.game_id WHERE g.id = $1 ORDER BY m.id `, gameID)
409 if err != nil {
410 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
411 return
412 }
413 for rows.Next() {
414 var mapShort models.MapShort
415 if err := rows.Scan(&response.Game.ID, &response.Game.Name, &response.Game.IsCoop, &mapShort.ID, &mapShort.Name, &mapShort.IsDisabled); err != nil {
416 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
417 return
418 }
419 response.Maps = append(response.Maps, mapShort)
420 }
421 c.JSON(http.StatusOK, models.Response{
422 Success: true,
423 Message: "Successfully retrieved maps.",
424 Data: response,
425 })
426}
427
388// GET Maps of a Chapter 428// GET Maps of a Chapter
389// 429//
390// @Description Get maps from the specified chapter id. 430// @Description Get maps from the specified chapter id.
diff --git a/docs/docs.go b/docs/docs.go
index 83d3a5c..d1643c3 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -177,6 +177,46 @@ const docTemplate = `{
177 } 177 }
178 } 178 }
179 }, 179 },
180 "/games/{gameid}/maps": {
181 "get": {
182 "description": "Get maps from the specified game id.",
183 "produces": [
184 "application/json"
185 ],
186 "tags": [
187 "games \u0026 chapters"
188 ],
189 "parameters": [
190 {
191 "type": "integer",
192 "description": "Game ID",
193 "name": "gameid",
194 "in": "path",
195 "required": true
196 }
197 ],
198 "responses": {
199 "200": {
200 "description": "OK",
201 "schema": {
202 "allOf": [
203 {
204 "$ref": "#/definitions/models.Response"
205 },
206 {
207 "type": "object",
208 "properties": {
209 "data": {
210 "$ref": "#/definitions/handlers.ChaptersResponse"
211 }
212 }
213 }
214 ]
215 }
216 }
217 }
218 }
219 },
180 "/login": { 220 "/login": {
181 "get": { 221 "get": {
182 "description": "Get (redirect) login page for Steam auth.", 222 "description": "Get (redirect) login page for Steam auth.",
@@ -1884,6 +1924,9 @@ const docTemplate = `{
1884 "id": { 1924 "id": {
1885 "type": "integer" 1925 "type": "integer"
1886 }, 1926 },
1927 "is_disabled": {
1928 "type": "boolean"
1929 },
1887 "name": { 1930 "name": {
1888 "type": "string" 1931 "type": "string"
1889 } 1932 }
diff --git a/docs/swagger.json b/docs/swagger.json
index 48e337f..3f7deed 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -170,6 +170,46 @@
170 } 170 }
171 } 171 }
172 }, 172 },
173 "/games/{gameid}/maps": {
174 "get": {
175 "description": "Get maps from the specified game id.",
176 "produces": [
177 "application/json"
178 ],
179 "tags": [
180 "games \u0026 chapters"
181 ],
182 "parameters": [
183 {
184 "type": "integer",
185 "description": "Game ID",
186 "name": "gameid",
187 "in": "path",
188 "required": true
189 }
190 ],
191 "responses": {
192 "200": {
193 "description": "OK",
194 "schema": {
195 "allOf": [
196 {
197 "$ref": "#/definitions/models.Response"
198 },
199 {
200 "type": "object",
201 "properties": {
202 "data": {
203 "$ref": "#/definitions/handlers.ChaptersResponse"
204 }
205 }
206 }
207 ]
208 }
209 }
210 }
211 }
212 },
173 "/login": { 213 "/login": {
174 "get": { 214 "get": {
175 "description": "Get (redirect) login page for Steam auth.", 215 "description": "Get (redirect) login page for Steam auth.",
@@ -1877,6 +1917,9 @@
1877 "id": { 1917 "id": {
1878 "type": "integer" 1918 "type": "integer"
1879 }, 1919 },
1920 "is_disabled": {
1921 "type": "boolean"
1922 },
1880 "name": { 1923 "name": {
1881 "type": "string" 1924 "type": "string"
1882 } 1925 }
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index b34a80c..d40b847 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -409,6 +409,8 @@ definitions:
409 properties: 409 properties:
410 id: 410 id:
411 type: integer 411 type: integer
412 is_disabled:
413 type: boolean
412 name: 414 name:
413 type: string 415 type: string
414 type: object 416 type: object
@@ -573,6 +575,29 @@ paths:
573 type: object 575 type: object
574 tags: 576 tags:
575 - games & chapters 577 - games & chapters
578 /games/{gameid}/maps:
579 get:
580 description: Get maps from the specified game id.
581 parameters:
582 - description: Game ID
583 in: path
584 name: gameid
585 required: true
586 type: integer
587 produces:
588 - application/json
589 responses:
590 "200":
591 description: OK
592 schema:
593 allOf:
594 - $ref: '#/definitions/models.Response'
595 - properties:
596 data:
597 $ref: '#/definitions/handlers.ChaptersResponse'
598 type: object
599 tags:
600 - games & chapters
576 /login: 601 /login:
577 get: 602 get:
578 consumes: 603 consumes: