aboutsummaryrefslogtreecommitdiff
path: root/backend/controllers/mapController.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--backend/controllers/mapController.go27
1 files changed, 21 insertions, 6 deletions
diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go
index ebd65dd..0a324d6 100644
--- a/backend/controllers/mapController.go
+++ b/backend/controllers/mapController.go
@@ -9,18 +9,33 @@ import (
9 "github.com/pektezol/leastportalshub/backend/models" 9 "github.com/pektezol/leastportalshub/backend/models"
10) 10)
11 11
12type MapSummaryResponse struct {
13 Map models.Map `json:"map"`
14 Summary models.MapSummary `json:"summary"`
15}
16
17type ChaptersResponse struct {
18 Game models.Game `json:"game"`
19 Chapters []models.Chapter `json:"chapters"`
20}
21
22type ChapterMapsResponse struct {
23 Chapter models.Chapter `json:"chapter"`
24 Maps []models.MapShort `json:"maps"`
25}
26
12// GET Map Summary 27// GET Map Summary
13// 28//
14// @Description Get map summary with specified id. 29// @Description Get map summary with specified id.
15// @Tags maps 30// @Tags maps
16// @Produce json 31// @Produce json
17// @Param id path int true "Map ID" 32// @Param id path int true "Map ID"
18// @Success 200 {object} models.Response{data=models.MapSummaryResponse} 33// @Success 200 {object} models.Response{data=MapSummaryResponse}
19// @Failure 400 {object} models.Response 34// @Failure 400 {object} models.Response
20// @Router /maps/{id}/summary [get] 35// @Router /maps/{id}/summary [get]
21func FetchMapSummary(c *gin.Context) { 36func FetchMapSummary(c *gin.Context) {
22 id := c.Param("id") 37 id := c.Param("id")
23 response := models.MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{Routes: []models.MapRoute{}}} 38 response := MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{Routes: []models.MapRoute{}}}
24 intID, err := strconv.Atoi(id) 39 intID, err := strconv.Atoi(id)
25 if err != nil { 40 if err != nil {
26 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 41 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
@@ -220,7 +235,7 @@ func FetchGames(c *gin.Context) {
220// @Tags games & chapters 235// @Tags games & chapters
221// @Produce json 236// @Produce json
222// @Param id path int true "Game ID" 237// @Param id path int true "Game ID"
223// @Success 200 {object} models.Response{data=models.ChaptersResponse} 238// @Success 200 {object} models.Response{data=ChaptersResponse}
224// @Failure 400 {object} models.Response 239// @Failure 400 {object} models.Response
225// @Router /games/{id} [get] 240// @Router /games/{id} [get]
226func FetchChapters(c *gin.Context) { 241func FetchChapters(c *gin.Context) {
@@ -230,7 +245,7 @@ func FetchChapters(c *gin.Context) {
230 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 245 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
231 return 246 return
232 } 247 }
233 var response models.ChaptersResponse 248 var response ChaptersResponse
234 rows, err := database.DB.Query(`SELECT c.id, c.name, g.name FROM chapters c INNER JOIN games g ON c.game_id = g.id WHERE game_id = $1`, gameID) 249 rows, err := database.DB.Query(`SELECT c.id, c.name, g.name FROM chapters c INNER JOIN games g ON c.game_id = g.id WHERE game_id = $1`, gameID)
235 if err != nil { 250 if err != nil {
236 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 251 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
@@ -262,7 +277,7 @@ func FetchChapters(c *gin.Context) {
262// @Tags games & chapters 277// @Tags games & chapters
263// @Produce json 278// @Produce json
264// @Param id path int true "Chapter ID" 279// @Param id path int true "Chapter ID"
265// @Success 200 {object} models.Response{data=models.ChapterMapsResponse} 280// @Success 200 {object} models.Response{data=ChapterMapsResponse}
266// @Failure 400 {object} models.Response 281// @Failure 400 {object} models.Response
267// @Router /chapters/{id} [get] 282// @Router /chapters/{id} [get]
268func FetchChapterMaps(c *gin.Context) { 283func FetchChapterMaps(c *gin.Context) {
@@ -272,7 +287,7 @@ func FetchChapterMaps(c *gin.Context) {
272 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 287 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))
273 return 288 return
274 } 289 }
275 var response models.ChapterMapsResponse 290 var response ChapterMapsResponse
276 rows, err := database.DB.Query(`SELECT m.id, m.name, c.name FROM maps m INNER JOIN chapters c ON m.chapter_id = c.id WHERE chapter_id = $1`, chapterID) 291 rows, err := database.DB.Query(`SELECT m.id, m.name, c.name FROM maps m INNER JOIN chapters c ON m.chapter_id = c.id WHERE chapter_id = $1`, chapterID)
277 if err != nil { 292 if err != nil {
278 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) 293 c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error()))