From 1f47d78a5f82998fe62fefe6d6f076583c101800 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sat, 17 Jun 2023 12:30:25 +0300 Subject: feat: search with query (#40) --- docs/docs.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'docs/docs.go') diff --git a/docs/docs.go b/docs/docs.go index d39fd1c..34aa7f4 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -651,7 +651,15 @@ const docTemplate = `{ "tags": [ "search" ], - "summary": "Get all user and map data.", + "summary": "Get all user and map data matching to the query.", + "parameters": [ + { + "type": "string", + "description": "Search user or map name.", + "name": "q", + "in": "query" + } + ], "responses": { "200": { "description": "OK", -- cgit v1.2.3 From 345fa5d06a47837fca48137163f8a7bdae33cebf Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sun, 18 Jun 2023 17:08:27 +0300 Subject: feat: improved map summary response (#43) --- backend/controllers/mapController.go | 79 ++++++++++------------ backend/models/models.go | 37 +++++----- backend/models/responses.go | 5 ++ docs/docs.go | 127 +++++++++++++++-------------------- docs/swagger.json | 127 +++++++++++++++-------------------- docs/swagger.yaml | 82 +++++++++++----------- 6 files changed, 207 insertions(+), 250 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index d8783b7..37b8e9b 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go @@ -3,10 +3,8 @@ package controllers import ( "net/http" "strconv" - "time" "github.com/gin-gonic/gin" - "github.com/lib/pq" "github.com/pektezol/leastportals/backend/database" "github.com/pektezol/leastportals/backend/models" ) @@ -17,37 +15,20 @@ import ( // @Tags maps // @Produce json // @Param id path int true "Map ID" -// @Success 200 {object} models.Response{data=models.Map{data=models.MapSummary}} +// @Success 200 {object} models.Response{data=models.MapSummaryResponse} // @Failure 400 {object} models.Response // @Router /maps/{id}/summary [get] func FetchMapSummary(c *gin.Context) { id := c.Param("id") // Get map data - var mapData models.Map - var mapSummaryData models.MapSummary - var mapHistoryData []models.MapHistory + response := models.MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{History: []models.MapHistory{}, Routes: []models.MapRoute{}}} intID, err := strconv.Atoi(id) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - mapData.ID = intID - var routers pq.StringArray - sql := `SELECT g.name, c.name, m.name, m.description, m.showcase, - ( - SELECT array_agg(user_name) - FROM map_routers - WHERE map_id = $1 - AND score_count = ( - SELECT score_count - FROM map_history - WHERE map_id = $1 - ORDER BY score_count - LIMIT 1 - ) - GROUP BY map_routers.user_name - ORDER BY user_name - ), + response.Map.ID = intID + sql := `SELECT m.id, g.name, c.name, m.name, ( SELECT COALESCE(avg(rating), 0.0) FROM map_ratings @@ -57,44 +38,53 @@ func FetchMapSummary(c *gin.Context) { INNER JOIN games g ON m.game_id = g.id INNER JOIN chapters c ON m.chapter_id = c.id WHERE m.id = $1` - // TODO: CategoryScores - err = database.DB.QueryRow(sql, id).Scan(&mapData.GameName, &mapData.ChapterName, &mapData.MapName, &mapSummaryData.Description, &mapSummaryData.Showcase, &routers, &mapSummaryData.Rating) + err = database.DB.QueryRow(sql, id).Scan(&response.Map.ID, &response.Map.GameName, &response.Map.ChapterName, &response.Map.MapName, &response.Summary.Rating) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - var historyNames pq.StringArray - var historyScores pq.Int32Array - var historyDates pq.StringArray - sql = `SELECT array_agg(user_name), array_agg(score_count), array_agg(record_date) + sql = `SELECT user_name, score_count, record_date FROM map_history - WHERE map_id = $1` - err = database.DB.QueryRow(sql, id).Scan(&historyNames, &historyScores, &historyDates) + WHERE map_id = $1 + ORDER BY record_date ASC` + rows, err := database.DB.Query(sql, id) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + for rows.Next() { + history := models.MapHistory{} + err = rows.Scan(&history.RunnerName, &history.ScoreCount, &history.Date) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + response.Summary.History = append(response.Summary.History, history) + } + sql = `SELECT c.id, c.name, mr.score_count, mr.description, mr.showcase + FROM map_routes mr + INNER JOIN categories c ON mr.category_id = c.id + WHERE mr.map_id = $1 + ORDER BY mr.score_count DESC` + rows, err = database.DB.Query(sql, id) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - for i := 0; i < len(historyNames); i++ { - var history models.MapHistory - history.RunnerName = historyNames[i] - history.ScoreCount = int(historyScores[i]) - layout := "2006-01-02 15:04:05" - date, err := time.Parse(layout, historyDates[i]) + for rows.Next() { + route := models.MapRoute{} + err = rows.Scan(&route.Category.ID, &route.Category.Name, &route.ScoreCount, &route.Description, &route.Showcase) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - history.Date = date - mapHistoryData = append(mapHistoryData, history) + response.Summary.Routes = append(response.Summary.Routes, route) } - mapSummaryData.History = mapHistoryData - mapSummaryData.Routers = routers - mapData.Data = mapSummaryData // Return response c.JSON(http.StatusOK, models.Response{ Success: true, Message: "Successfully retrieved map summary.", - Data: mapData, + Data: response, }) } @@ -108,6 +98,7 @@ func FetchMapSummary(c *gin.Context) { // @Failure 400 {object} models.Response // @Router /maps/{id}/leaderboards [get] func FetchMapLeaderboards(c *gin.Context) { + // TODO: make new response type id := c.Param("id") // Get map data var mapData models.Map @@ -205,7 +196,7 @@ func FetchMapLeaderboards(c *gin.Context) { } mapRecordsData.Records = records } - mapData.Data = mapRecordsData + // mapData.Data = mapRecordsData // Return response c.JSON(http.StatusOK, models.Response{ Success: true, diff --git a/backend/models/models.go b/backend/models/models.go index 49a4f82..5c9b8f8 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -23,7 +23,6 @@ type Map struct { GameName string `json:"game_name"` ChapterName string `json:"chapter_name"` MapName string `json:"map_name"` - Data any `json:"data"` } type MapShort struct { @@ -32,23 +31,9 @@ type MapShort struct { } type MapSummary struct { - Description string `json:"description"` - Showcase string `json:"showcase"` - CategoryScores MapCategoryScores `json:"category_scores"` - Rating float32 `json:"rating"` - Routers []string `json:"routers"` - History []MapHistory `json:"history"` -} - -type MapCategoryScores struct { - CM int `json:"cm"` - NoSLA int `json:"no_sla"` - InboundsSLA int `json:"inbounds_sla"` - Any int `json:"any"` -} - -type MapRecords struct { - Records any `json:"records"` + Rating float32 `json:"rating"` + History []MapHistory `json:"history"` + Routes []MapRoute `json:"routes"` } type MapHistory struct { @@ -57,6 +42,17 @@ type MapHistory struct { Date time.Time `json:"date"` } +type MapRoute struct { + Category Category `json:"category"` + ScoreCount int `json:"score_count"` + Description string `json:"description"` + Showcase string `json:"showcase"` +} + +type MapRecords struct { + Records any `json:"records"` +} + type UserRanking struct { UserID string `json:"user_id"` UserName string `json:"user_name"` @@ -73,6 +69,11 @@ type Chapter struct { Name string `json:"name"` } +type Category struct { + ID int `json:"id"` + Name string `json:"name"` +} + type RecordSP struct { RecordID int `json:"record_id"` Placement int `json:"placement"` diff --git a/backend/models/responses.go b/backend/models/responses.go index 5a88353..dc554ff 100644 --- a/backend/models/responses.go +++ b/backend/models/responses.go @@ -30,6 +30,11 @@ type ScoreResponse struct { Records any `json:"records"` } +type MapSummaryResponse struct { + Map Map `json:"map"` + Summary MapSummary `json:"summary"` +} + type SearchResponse struct { Players []UserShort `json:"players"` Maps []MapShort `json:"maps"` diff --git a/docs/docs.go b/docs/docs.go index 34aa7f4..cf6c00d 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -447,19 +447,7 @@ const docTemplate = `{ "type": "object", "properties": { "data": { - "allOf": [ - { - "$ref": "#/definitions/models.Map" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.MapSummary" - } - } - } - ] + "$ref": "#/definitions/models.MapSummaryResponse" } } } @@ -560,19 +548,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "allOf": [ - { - "$ref": "#/definitions/models.Response" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.ProfileResponse" - } - } - } - ] + "$ref": "#/definitions/models.Response" } }, "400": { @@ -817,6 +793,17 @@ const docTemplate = `{ } }, "definitions": { + "models.Category": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "models.Chapter": { "type": "object", "properties": { @@ -881,7 +868,6 @@ const docTemplate = `{ "chapter_name": { "type": "string" }, - "data": {}, "game_name": { "type": "string" }, @@ -893,23 +879,6 @@ const docTemplate = `{ } } }, - "models.MapCategoryScores": { - "type": "object", - "properties": { - "any": { - "type": "integer" - }, - "cm": { - "type": "integer" - }, - "inbounds_sla": { - "type": "integer" - }, - "no_sla": { - "type": "integer" - } - } - }, "models.MapHistory": { "type": "object", "properties": { @@ -930,6 +899,23 @@ const docTemplate = `{ "records": {} } }, + "models.MapRoute": { + "type": "object", + "properties": { + "category": { + "$ref": "#/definitions/models.Category" + }, + "description": { + "type": "string" + }, + "score_count": { + "type": "integer" + }, + "showcase": { + "type": "string" + } + } + }, "models.MapShort": { "type": "object", "properties": { @@ -944,12 +930,6 @@ const docTemplate = `{ "models.MapSummary": { "type": "object", "properties": { - "category_scores": { - "$ref": "#/definitions/models.MapCategoryScores" - }, - "description": { - "type": "string" - }, "history": { "type": "array", "items": { @@ -959,14 +939,22 @@ const docTemplate = `{ "rating": { "type": "number" }, - "routers": { + "routes": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/models.MapRoute" } + } + } + }, + "models.MapSummaryResponse": { + "type": "object", + "properties": { + "map": { + "$ref": "#/definitions/models.Map" }, - "showcase": { - "type": "string" + "summary": { + "$ref": "#/definitions/models.MapSummary" } } }, @@ -1069,29 +1057,13 @@ const docTemplate = `{ "maps": { "type": "array", "items": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "name": { - "type": "string" - } - } + "$ref": "#/definitions/models.MapShort" } }, "players": { "type": "array", "items": { - "type": "object", - "properties": { - "steam_id": { - "type": "string" - }, - "user_name": { - "type": "string" - } - } + "$ref": "#/definitions/models.UserShort" } } } @@ -1109,6 +1081,17 @@ const docTemplate = `{ "type": "string" } } + }, + "models.UserShort": { + "type": "object", + "properties": { + "steam_id": { + "type": "string" + }, + "user_name": { + "type": "string" + } + } } } }` diff --git a/docs/swagger.json b/docs/swagger.json index 8491d2e..f2ed3f0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -440,19 +440,7 @@ "type": "object", "properties": { "data": { - "allOf": [ - { - "$ref": "#/definitions/models.Map" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.MapSummary" - } - } - } - ] + "$ref": "#/definitions/models.MapSummaryResponse" } } } @@ -553,19 +541,7 @@ "200": { "description": "OK", "schema": { - "allOf": [ - { - "$ref": "#/definitions/models.Response" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.ProfileResponse" - } - } - } - ] + "$ref": "#/definitions/models.Response" } }, "400": { @@ -810,6 +786,17 @@ } }, "definitions": { + "models.Category": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "models.Chapter": { "type": "object", "properties": { @@ -874,7 +861,6 @@ "chapter_name": { "type": "string" }, - "data": {}, "game_name": { "type": "string" }, @@ -886,23 +872,6 @@ } } }, - "models.MapCategoryScores": { - "type": "object", - "properties": { - "any": { - "type": "integer" - }, - "cm": { - "type": "integer" - }, - "inbounds_sla": { - "type": "integer" - }, - "no_sla": { - "type": "integer" - } - } - }, "models.MapHistory": { "type": "object", "properties": { @@ -923,6 +892,23 @@ "records": {} } }, + "models.MapRoute": { + "type": "object", + "properties": { + "category": { + "$ref": "#/definitions/models.Category" + }, + "description": { + "type": "string" + }, + "score_count": { + "type": "integer" + }, + "showcase": { + "type": "string" + } + } + }, "models.MapShort": { "type": "object", "properties": { @@ -937,12 +923,6 @@ "models.MapSummary": { "type": "object", "properties": { - "category_scores": { - "$ref": "#/definitions/models.MapCategoryScores" - }, - "description": { - "type": "string" - }, "history": { "type": "array", "items": { @@ -952,14 +932,22 @@ "rating": { "type": "number" }, - "routers": { + "routes": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/models.MapRoute" } + } + } + }, + "models.MapSummaryResponse": { + "type": "object", + "properties": { + "map": { + "$ref": "#/definitions/models.Map" }, - "showcase": { - "type": "string" + "summary": { + "$ref": "#/definitions/models.MapSummary" } } }, @@ -1062,29 +1050,13 @@ "maps": { "type": "array", "items": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "name": { - "type": "string" - } - } + "$ref": "#/definitions/models.MapShort" } }, "players": { "type": "array", "items": { - "type": "object", - "properties": { - "steam_id": { - "type": "string" - }, - "user_name": { - "type": "string" - } - } + "$ref": "#/definitions/models.UserShort" } } } @@ -1102,6 +1074,17 @@ "type": "string" } } + }, + "models.UserShort": { + "type": "object", + "properties": { + "steam_id": { + "type": "string" + }, + "user_name": { + "type": "string" + } + } } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 597df9f..61f2ad7 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,5 +1,12 @@ basePath: /v1 definitions: + models.Category: + properties: + id: + type: integer + name: + type: string + type: object models.Chapter: properties: id: @@ -41,7 +48,6 @@ definitions: properties: chapter_name: type: string - data: {} game_name: type: string id: @@ -49,17 +55,6 @@ definitions: map_name: type: string type: object - models.MapCategoryScores: - properties: - any: - type: integer - cm: - type: integer - inbounds_sla: - type: integer - no_sla: - type: integer - type: object models.MapHistory: properties: date: @@ -73,6 +68,17 @@ definitions: properties: records: {} type: object + models.MapRoute: + properties: + category: + $ref: '#/definitions/models.Category' + description: + type: string + score_count: + type: integer + showcase: + type: string + type: object models.MapShort: properties: id: @@ -82,22 +88,23 @@ definitions: type: object models.MapSummary: properties: - category_scores: - $ref: '#/definitions/models.MapCategoryScores' - description: - type: string history: items: $ref: '#/definitions/models.MapHistory' type: array rating: type: number - routers: + routes: items: - type: string + $ref: '#/definitions/models.MapRoute' type: array - showcase: - type: string + type: object + models.MapSummaryResponse: + properties: + map: + $ref: '#/definitions/models.Map' + summary: + $ref: '#/definitions/models.MapSummary' type: object models.ProfileResponse: properties: @@ -165,21 +172,11 @@ definitions: properties: maps: items: - properties: - id: - type: integer - name: - type: string - type: object + $ref: '#/definitions/models.MapShort' type: array players: items: - properties: - steam_id: - type: string - user_name: - type: string - type: object + $ref: '#/definitions/models.UserShort' type: array type: object models.UserRanking: @@ -191,6 +188,13 @@ definitions: user_name: type: string type: object + models.UserShort: + properties: + steam_id: + type: string + user_name: + type: string + type: object host: lp.ardapektezol.com/api info: contact: {} @@ -456,12 +460,7 @@ paths: - $ref: '#/definitions/models.Response' - properties: data: - allOf: - - $ref: '#/definitions/models.Map' - - properties: - data: - $ref: '#/definitions/models.MapSummary' - type: object + $ref: '#/definitions/models.MapSummaryResponse' type: object "400": description: Bad Request @@ -555,12 +554,7 @@ paths: "200": description: OK schema: - allOf: - - $ref: '#/definitions/models.Response' - - properties: - data: - $ref: '#/definitions/models.ProfileResponse' - type: object + $ref: '#/definitions/models.Response' "400": description: Bad Request schema: -- cgit v1.2.3 From 4f9b489186d28055f60e3b5ef39bd27c7a229984 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 20 Jun 2023 20:09:02 +0300 Subject: docs: map summary response (#46) --- docs/docs.go | 15 ++++++--------- docs/swagger.json | 15 ++++++--------- docs/swagger.yaml | 10 ++++------ 3 files changed, 16 insertions(+), 24 deletions(-) (limited to 'docs/docs.go') diff --git a/docs/docs.go b/docs/docs.go index cf6c00d..b7dc7ab 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -908,6 +908,12 @@ const docTemplate = `{ "description": { "type": "string" }, + "history": { + "$ref": "#/definitions/models.MapHistory" + }, + "rating": { + "type": "number" + }, "score_count": { "type": "integer" }, @@ -930,15 +936,6 @@ const docTemplate = `{ "models.MapSummary": { "type": "object", "properties": { - "history": { - "type": "array", - "items": { - "$ref": "#/definitions/models.MapHistory" - } - }, - "rating": { - "type": "number" - }, "routes": { "type": "array", "items": { diff --git a/docs/swagger.json b/docs/swagger.json index f2ed3f0..ffcf55a 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -901,6 +901,12 @@ "description": { "type": "string" }, + "history": { + "$ref": "#/definitions/models.MapHistory" + }, + "rating": { + "type": "number" + }, "score_count": { "type": "integer" }, @@ -923,15 +929,6 @@ "models.MapSummary": { "type": "object", "properties": { - "history": { - "type": "array", - "items": { - "$ref": "#/definitions/models.MapHistory" - } - }, - "rating": { - "type": "number" - }, "routes": { "type": "array", "items": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 61f2ad7..3dfe421 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -74,6 +74,10 @@ definitions: $ref: '#/definitions/models.Category' description: type: string + history: + $ref: '#/definitions/models.MapHistory' + rating: + type: number score_count: type: integer showcase: @@ -88,12 +92,6 @@ definitions: type: object models.MapSummary: properties: - history: - items: - $ref: '#/definitions/models.MapHistory' - type: array - rating: - type: number routes: items: $ref: '#/definitions/models.MapRoute' -- cgit v1.2.3 From 9af2c7d17f02be98998d388b421b3d055a96f83e Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 20 Jun 2023 20:57:10 +0300 Subject: fix: remove duplicate score count in routes (#46) --- backend/controllers/mapController.go | 11 +++-------- backend/models/models.go | 1 - docs/docs.go | 3 --- docs/swagger.json | 3 --- docs/swagger.yaml | 2 -- 5 files changed, 3 insertions(+), 17 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index e46b766..b5984dc 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go @@ -26,11 +26,6 @@ func FetchMapSummary(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - // ( - // SELECT COALESCE(avg(rating), 0.0) - // FROM route_ratings - // WHERE map_id = $1 - // ) // Get map data response.Map.ID = intID sql := `SELECT m.id, g.name, c.name, m.name @@ -44,11 +39,11 @@ func FetchMapSummary(c *gin.Context) { return } // Get map routes and histories - sql = `SELECT c.id, c.name, h.user_name, h.score_count, h.record_date, r.score_count, r.description, r.showcase, COALESCE(avg(rating), 0.0) FROM map_routes r + sql = `SELECT c.id, c.name, h.user_name, h.score_count, h.record_date, r.description, r.showcase, COALESCE(avg(rating), 0.0) FROM map_routes r INNER JOIN categories c ON r.category_id = c.id INNER JOIN map_history h ON r.map_id = h.map_id AND r.category_id = h.category_id LEFT JOIN map_ratings rt ON r.map_id = rt.map_id AND r.category_id = rt.category_id - WHERE r.map_id = $1 AND h.score_count = r.score_count GROUP BY c.id, h.user_name, h.score_count, h.record_date, r.score_count, r.description, r.showcase + WHERE r.map_id = $1 AND h.score_count = r.score_count GROUP BY c.id, h.user_name, h.score_count, h.record_date, r.description, r.showcase ORDER BY h.record_date ASC;` rows, err := database.DB.Query(sql, id) if err != nil { @@ -57,7 +52,7 @@ func FetchMapSummary(c *gin.Context) { } for rows.Next() { route := models.MapRoute{Category: models.Category{}, History: models.MapHistory{}} - err = rows.Scan(&route.Category.ID, &route.Category.Name, &route.History.RunnerName, &route.History.ScoreCount, &route.History.Date, &route.ScoreCount, &route.Description, &route.Showcase, &route.Rating) + err = rows.Scan(&route.Category.ID, &route.Category.Name, &route.History.RunnerName, &route.History.ScoreCount, &route.History.Date, &route.Description, &route.Showcase, &route.Rating) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return diff --git a/backend/models/models.go b/backend/models/models.go index 783c339..0727468 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -44,7 +44,6 @@ type MapRoute struct { Category Category `json:"category"` History MapHistory `json:"history"` Rating float32 `json:"rating"` - ScoreCount int `json:"score_count"` Description string `json:"description"` Showcase string `json:"showcase"` } diff --git a/docs/docs.go b/docs/docs.go index b7dc7ab..a0aad6f 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -914,9 +914,6 @@ const docTemplate = `{ "rating": { "type": "number" }, - "score_count": { - "type": "integer" - }, "showcase": { "type": "string" } diff --git a/docs/swagger.json b/docs/swagger.json index ffcf55a..2279ff6 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -907,9 +907,6 @@ "rating": { "type": "number" }, - "score_count": { - "type": "integer" - }, "showcase": { "type": "string" } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 3dfe421..ba4775a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -78,8 +78,6 @@ definitions: $ref: '#/definitions/models.MapHistory' rating: type: number - score_count: - type: integer showcase: type: string type: object -- cgit v1.2.3 From 7050773414c550b7693c41a9bdd8cb390d7ef647 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 29 Jun 2023 10:45:12 +0300 Subject: fix: record controller Former-commit-id: bff6b62474e02f644d93f49827145cfd92682c6f --- backend/controllers/recordController.go | 87 +++++++++-------------- backend/models/requests.go | 4 +- backend/parser/parser.go | 7 ++ docs/docs.go | 118 ++++++++++++++++++++++++-------- docs/swagger.json | 112 ++++++++++++++++++++++-------- docs/swagger.yaml | 78 +++++++++++++++------ 6 files changed, 269 insertions(+), 137 deletions(-) create mode 100644 backend/parser/parser.go (limited to 'docs/docs.go') diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index 627be57..aec31bb 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go @@ -5,14 +5,15 @@ import ( b64 "encoding/base64" "io" "log" + "mime/multipart" "net/http" "os" - "strconv" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/pektezol/leastportals/backend/database" "github.com/pektezol/leastportals/backend/models" + "github.com/pektezol/leastportals/backend/parser" "golang.org/x/oauth2/google" "golang.org/x/oauth2/jwt" "google.golang.org/api/drive/v3" @@ -25,9 +26,8 @@ import ( // @Accept mpfd // @Produce json // @Param Authorization header string true "JWT Token" -// @Param demos formData []file true "Demos" -// @Param score_count formData int true "Score Count" -// @Param score_time formData int true "Score Time" +// @Param host_demo formData file true "Host Demo" +// @Param partner_demo formData file true "Partner Demo" // @Param is_partner_orange formData boolean true "Is Partner Orange" // @Param partner_id formData string true "Partner ID" // @Success 200 {object} models.Response{data=models.RecordRequest} @@ -43,11 +43,11 @@ func CreateRecordWithDemo(c *gin.Context) { return } // Check if map is sp or mp - var gameID int + var gameName string var isCoop bool var isDisabled bool - sql := `SELECT game_id, is_disabled FROM maps WHERE id = $1` - err := database.DB.QueryRow(sql, mapId).Scan(&gameID, &isDisabled) + sql := `SELECT g.name, m.is_disabled FROM maps m INNER JOIN games g ON m.game_id=g.id WHERE id = $1` + err := database.DB.QueryRow(sql, mapId).Scan(&gameName, &isDisabled) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return @@ -56,51 +56,23 @@ func CreateRecordWithDemo(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) return } - if gameID == 2 { + if gameName == "Portal 2 - Cooperative" { isCoop = true } // Get record request var record models.RecordRequest - score_count, err := strconv.Atoi(c.PostForm("score_count")) - if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) - return - } - score_time, err := strconv.Atoi(c.PostForm("score_time")) - if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) - return - } - is_partner_orange, err := strconv.ParseBool(c.PostForm("is_partner_orange")) - if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) - return - } - record.ScoreCount = score_count - record.ScoreTime = score_time - record.PartnerID = c.PostForm("partner_id") - record.IsPartnerOrange = is_partner_orange - if record.PartnerID == "" { - c.JSON(http.StatusBadRequest, models.ErrorResponse("No partner id given.")) - return - } - // Multipart form - form, err := c.MultipartForm() - if err != nil { + if err := c.ShouldBind(&record); err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - files := form.File["demos"] - if len(files) != 2 && isCoop { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Not enough demos for coop submission.")) - return - } - if len(files) != 1 && !isCoop { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Too many demos for singleplayer submission.")) + if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { + c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid entry for coop record submission.")) return } - var hostDemoUUID string - var partnerDemoUUID string + // Demo files + demoFiles := []*multipart.FileHeader{record.HostDemo, record.PartnerDemo} + var hostDemoUUID, hostDemoFileID, partnerDemoUUID, partnerDemoFileID string + var hostDemoScoreCount, hostDemoScoreTime int client := serviceAccount() srv, err := drive.New(client) if err != nil { @@ -115,16 +87,15 @@ func CreateRecordWithDemo(c *gin.Context) { } // Defer to a rollback in case anything fails defer tx.Rollback() - fileID := "" - for i, header := range files { + for i, header := range demoFiles { uuid := uuid.New().String() // Upload & insert into demos - err = c.SaveUploadedFile(header, "docs/"+header.Filename) + err = c.SaveUploadedFile(header, "parser/demos/"+header.Filename) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - f, err := os.Open("docs/" + header.Filename) + f, err := os.Open("parser/demos/" + header.Filename) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return @@ -135,11 +106,16 @@ func CreateRecordWithDemo(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - fileID = file.Id + hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo(record.HostDemo) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } if i == 0 { + hostDemoFileID = file.Id hostDemoUUID = uuid - } - if i == 1 { + } else if i == 1 { + partnerDemoFileID = file.Id partnerDemoUUID = uuid } _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) @@ -148,7 +124,7 @@ func CreateRecordWithDemo(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - os.Remove("docs/" + header.Filename) + os.Remove("parser/demos/" + header.Filename) } // Insert into records if isCoop { @@ -163,9 +139,10 @@ func CreateRecordWithDemo(c *gin.Context) { partnerID = user.(models.User).SteamID hostID = record.PartnerID } - _, err := tx.Exec(sql, mapId, record.ScoreCount, record.ScoreTime, hostID, partnerID, hostDemoUUID, partnerDemoUUID) + _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, hostID, partnerID, hostDemoUUID, partnerDemoUUID) if err != nil { - deleteFile(srv, fileID) + deleteFile(srv, hostDemoFileID) + deleteFile(srv, partnerDemoFileID) c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } @@ -180,9 +157,9 @@ func CreateRecordWithDemo(c *gin.Context) { } else { sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) VALUES($1, $2, $3, $4, $5)` - _, err := tx.Exec(sql, mapId, record.ScoreCount, record.ScoreTime, user.(models.User).SteamID, hostDemoUUID) + _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, user.(models.User).SteamID, hostDemoUUID) if err != nil { - deleteFile(srv, fileID) + deleteFile(srv, hostDemoFileID) c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } diff --git a/backend/models/requests.go b/backend/models/requests.go index e95eab6..4b4657b 100644 --- a/backend/models/requests.go +++ b/backend/models/requests.go @@ -22,8 +22,8 @@ type CreateMapHistoryRequest struct { } type RecordRequest struct { - HostDemo *multipart.FileHeader `json:"host_demo" form:"host_demo" binding:"required"` - PartnerDemo *multipart.FileHeader `json:"partner_demo" form:"partner_demo"` + HostDemo *multipart.FileHeader `json:"host_demo" form:"host_demo" binding:"required" swaggerignore:"true"` + PartnerDemo *multipart.FileHeader `json:"partner_demo" form:"partner_demo" swaggerignore:"true"` IsPartnerOrange bool `json:"is_partner_orange" form:"is_partner_orange"` PartnerID string `json:"partner_id" form:"partner_id"` } diff --git a/backend/parser/parser.go b/backend/parser/parser.go new file mode 100644 index 0000000..6f9a24f --- /dev/null +++ b/backend/parser/parser.go @@ -0,0 +1,7 @@ +package parser + +import "mime/multipart" + +func ProcessDemo(demo *multipart.FileHeader) (scoreCount int, scoreTime int, err error) { + return 0, 0, nil +} diff --git a/docs/docs.go b/docs/docs.go index a0aad6f..090d3e8 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,5 +1,5 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Code generated by swaggo/swag. DO NOT EDIT. + package docs import "github.com/swaggo/swag" @@ -345,26 +345,16 @@ const docTemplate = `{ "required": true }, { - "type": "array", - "items": { - "type": "file" - }, - "description": "Demos", - "name": "demos", + "type": "file", + "description": "Host Demo", + "name": "host_demo", "in": "formData", "required": true }, { - "type": "integer", - "description": "Score Count", - "name": "score_count", - "in": "formData", - "required": true - }, - { - "type": "integer", - "description": "Score Time", - "name": "score_time", + "type": "file", + "description": "Partner Demo", + "name": "partner_demo", "in": "formData", "required": true }, @@ -461,6 +451,50 @@ const docTemplate = `{ } } } + }, + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "summary": "Edit map summary with specified map id.", + "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.EditMapSummaryRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } } }, "/profile": { @@ -843,6 +877,37 @@ const docTemplate = `{ } } }, + "models.EditMapSummaryRequest": { + "type": "object", + "required": [ + "description", + "record_date", + "route_id", + "score_count", + "showcase", + "user_name" + ], + "properties": { + "description": { + "type": "string" + }, + "record_date": { + "type": "string" + }, + "route_id": { + "type": "integer" + }, + "score_count": { + "type": "integer" + }, + "showcase": { + "type": "string" + }, + "user_name": { + "type": "string" + } + } + }, "models.Game": { "type": "object", "properties": { @@ -874,6 +939,9 @@ const docTemplate = `{ "id": { "type": "integer" }, + "image": { + "type": "string" + }, "map_name": { "type": "string" } @@ -1003,24 +1071,12 @@ const docTemplate = `{ }, "models.RecordRequest": { "type": "object", - "required": [ - "is_partner_orange", - "partner_id", - "score_count", - "score_time" - ], "properties": { "is_partner_orange": { "type": "boolean" }, "partner_id": { "type": "string" - }, - "score_count": { - "type": "integer" - }, - "score_time": { - "type": "integer" } } }, @@ -1100,6 +1156,8 @@ var SwaggerInfo = &swag.Spec{ Description: "Backend API endpoints for the Least Portals Database.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index 2279ff6..62079b1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -338,26 +338,16 @@ "required": true }, { - "type": "array", - "items": { - "type": "file" - }, - "description": "Demos", - "name": "demos", + "type": "file", + "description": "Host Demo", + "name": "host_demo", "in": "formData", "required": true }, { - "type": "integer", - "description": "Score Count", - "name": "score_count", - "in": "formData", - "required": true - }, - { - "type": "integer", - "description": "Score Time", - "name": "score_time", + "type": "file", + "description": "Partner Demo", + "name": "partner_demo", "in": "formData", "required": true }, @@ -454,6 +444,50 @@ } } } + }, + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "summary": "Edit map summary with specified map id.", + "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.EditMapSummaryRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } } }, "/profile": { @@ -836,6 +870,37 @@ } } }, + "models.EditMapSummaryRequest": { + "type": "object", + "required": [ + "description", + "record_date", + "route_id", + "score_count", + "showcase", + "user_name" + ], + "properties": { + "description": { + "type": "string" + }, + "record_date": { + "type": "string" + }, + "route_id": { + "type": "integer" + }, + "score_count": { + "type": "integer" + }, + "showcase": { + "type": "string" + }, + "user_name": { + "type": "string" + } + } + }, "models.Game": { "type": "object", "properties": { @@ -867,6 +932,9 @@ "id": { "type": "integer" }, + "image": { + "type": "string" + }, "map_name": { "type": "string" } @@ -996,24 +1064,12 @@ }, "models.RecordRequest": { "type": "object", - "required": [ - "is_partner_orange", - "partner_id", - "score_count", - "score_time" - ], "properties": { "is_partner_orange": { "type": "boolean" }, "partner_id": { "type": "string" - }, - "score_count": { - "type": "integer" - }, - "score_time": { - "type": "integer" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index ba4775a..9d58620 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -32,6 +32,28 @@ definitions: game: $ref: '#/definitions/models.Game' type: object + models.EditMapSummaryRequest: + properties: + description: + type: string + record_date: + type: string + route_id: + type: integer + score_count: + type: integer + showcase: + type: string + user_name: + type: string + required: + - description + - record_date + - route_id + - score_count + - showcase + - user_name + type: object models.Game: properties: id: @@ -52,6 +74,8 @@ definitions: type: string id: type: integer + image: + type: string map_name: type: string type: object @@ -140,15 +164,6 @@ definitions: type: boolean partner_id: type: string - score_count: - type: integer - score_time: - type: integer - required: - - is_partner_orange - - partner_id - - score_count - - score_time type: object models.Response: properties: @@ -388,23 +403,16 @@ paths: name: Authorization required: true type: string - - description: Demos - in: formData - items: - type: file - name: demos - required: true - type: array - - description: Score Count + - description: Host Demo in: formData - name: score_count + name: host_demo required: true - type: integer - - description: Score Time + type: file + - description: Partner Demo in: formData - name: score_time + name: partner_demo required: true - type: integer + type: file - description: Is Partner Orange in: formData name: is_partner_orange @@ -465,6 +473,32 @@ paths: summary: Get map summary with specified id. tags: - maps + put: + parameters: + - description: Map ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/models.Response' + - properties: + data: + $ref: '#/definitions/models.EditMapSummaryRequest' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/models.Response' + summary: Edit map summary with specified map id. + tags: + - maps /profile: get: consumes: -- cgit v1.2.3 From 85c6da965ec401dabb162df09160b4ce9dc28413 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 29 Jun 2023 11:57:53 +0300 Subject: feat: route id in map summary, update docs Former-commit-id: f8db004d2c17f09f665e51ec4e730418248bfd07 --- backend/controllers/mapController.go | 4 ++-- backend/controllers/modController.go | 7 ++++--- backend/controllers/recordController.go | 5 ++--- backend/models/models.go | 1 + docs/docs.go | 9 +++++++++ docs/swagger.json | 9 +++++++++ docs/swagger.yaml | 6 ++++++ 7 files changed, 33 insertions(+), 8 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index 77f8e10..7dfd2be 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go @@ -39,7 +39,7 @@ func FetchMapSummary(c *gin.Context) { return } // Get map routes and histories - sql = `SELECT c.id, c.name, h.user_name, h.score_count, h.record_date, r.description, r.showcase, COALESCE(avg(rating), 0.0) FROM map_routes r + sql = `SELECT r.id, c.id, c.name, h.user_name, h.score_count, h.record_date, r.description, r.showcase, COALESCE(avg(rating), 0.0) FROM map_routes r INNER JOIN categories c ON r.category_id = c.id INNER JOIN map_history h ON r.map_id = h.map_id AND r.category_id = h.category_id LEFT JOIN map_ratings rt ON r.map_id = rt.map_id AND r.category_id = rt.category_id @@ -52,7 +52,7 @@ func FetchMapSummary(c *gin.Context) { } for rows.Next() { route := models.MapRoute{Category: models.Category{}, History: models.MapHistory{}} - err = rows.Scan(&route.Category.ID, &route.Category.Name, &route.History.RunnerName, &route.History.ScoreCount, &route.History.Date, &route.Description, &route.Showcase, &route.Rating) + err = rows.Scan(&route.RouteID, &route.Category.ID, &route.Category.Name, &route.History.RunnerName, &route.History.ScoreCount, &route.History.Date, &route.Description, &route.Showcase, &route.Rating) if err != nil { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index ebf1cb7..9d14f92 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -14,9 +14,10 @@ import ( // @Summary Edit map summary with specified map id. // @Tags maps // @Produce json -// @Param id path int true "Map ID" -// @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} -// @Failure 400 {object} models.Response +// @Param id path int true "Map ID" +// @Param request body models.EditMapSummaryRequest true "Body" +// @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} +// @Failure 400 {object} models.Response // @Router /maps/{id}/summary [put] func EditMapSummary(c *gin.Context) { // Check if user exists diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index aec31bb..c865bfb 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go @@ -30,7 +30,7 @@ import ( // @Param partner_demo formData file true "Partner Demo" // @Param is_partner_orange formData boolean true "Is Partner Orange" // @Param partner_id formData string true "Partner ID" -// @Success 200 {object} models.Response{data=models.RecordRequest} +// @Success 200 {object} models.Response // @Failure 400 {object} models.Response // @Failure 401 {object} models.Response // @Router /maps/{id}/record [post] @@ -179,9 +179,8 @@ func CreateRecordWithDemo(c *gin.Context) { c.JSON(http.StatusOK, models.Response{ Success: true, Message: "Successfully created record.", - Data: record, + Data: nil, }) - return } // GET Demo diff --git a/backend/models/models.go b/backend/models/models.go index 5355a9f..2524935 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -43,6 +43,7 @@ type MapHistory struct { } type MapRoute struct { + RouteID int `json:"route_id"` Category Category `json:"category"` History MapHistory `json:"history"` Rating float32 `json:"rating"` diff --git a/docs/docs.go b/docs/docs.go index 090d3e8..91f91ef 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -467,6 +467,15 @@ const docTemplate = `{ "name": "id", "in": "path", "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.EditMapSummaryRequest" + } } ], "responses": { diff --git a/docs/swagger.json b/docs/swagger.json index 62079b1..c6bbfbc 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -460,6 +460,15 @@ "name": "id", "in": "path", "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.EditMapSummaryRequest" + } } ], "responses": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9d58620..4291cfc 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -480,6 +480,12 @@ paths: name: id required: true type: integer + - description: Body + in: body + name: request + required: true + schema: + $ref: '#/definitions/models.EditMapSummaryRequest' produces: - application/json responses: -- cgit v1.2.3 From 84346e6006d6e88dfef99550da3c2e80071f0197 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 29 Jun 2023 12:32:28 +0300 Subject: feat: support for multiple route edit, image field Former-commit-id: 3820c1363ece1c6616ec0297e44de851bae410af --- backend/controllers/modController.go | 49 ++++++++++++++++++++---------------- backend/models/requests.go | 5 ++++ docs/docs.go | 45 ++++++++++++++++----------------- docs/swagger.json | 45 ++++++++++++++++----------------- docs/swagger.yaml | 27 ++++++++++---------- 5 files changed, 88 insertions(+), 83 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index 9d14f92..7c258ef 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -48,17 +48,6 @@ func EditMapSummary(c *gin.Context) { c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) return } - // Fetch route category and score count - var categoryID, scoreCount int - sql := `SELECT mr.category_id, mr.score_count - FROM map_routes mr - INNER JOIN maps m - WHERE m.id = $1 AND mr.id = $2` - err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) - if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) - return - } // Start database transaction tx, err := database.DB.Begin() if err != nil { @@ -66,18 +55,34 @@ func EditMapSummary(c *gin.Context) { return } defer tx.Rollback() - // Update database with new data - sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` - _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) - if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) - return + if request.Image != "" { + tx.Exec(`UPDATE maps m SET image = $2 WHERE m.id = $1`, mapID, request.Image) } - sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` - _, err = tx.Exec(sql, mapID, categoryID, request.UserName, request.ScoreCount, request.RecordDate) - if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) - return + for _, route := range request.Routes { + // Fetch route category and score count + var categoryID, scoreCount int + sql := `SELECT mr.category_id, mr.score_count + FROM map_routes mr + INNER JOIN maps m + WHERE m.id = $1 AND mr.id = $2` + err = database.DB.QueryRow(sql, mapID, route.RouteID).Scan(&categoryID, &scoreCount) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + // Update database with new data + sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` + _, err = tx.Exec(sql, route.RouteID, route.ScoreCount, route.Description, route.Showcase) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + sql = `UPDATE map_history SET user_name = $3, score_count = $4, record_date = $5 WHERE map_id = $1 AND category_id = $2` + _, err = tx.Exec(sql, mapID, categoryID, route.UserName, route.ScoreCount, route.RecordDate) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } } if err = tx.Commit(); err != nil { c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) diff --git a/backend/models/requests.go b/backend/models/requests.go index 4b4657b..7a00567 100644 --- a/backend/models/requests.go +++ b/backend/models/requests.go @@ -6,6 +6,11 @@ import ( ) type EditMapSummaryRequest struct { + Image string `json:"image" binding:"required"` + Routes []EditMapSummaryRequestDetails `json:"routes" binding:"dive"` +} + +type EditMapSummaryRequestDetails struct { RouteID int `json:"route_id" binding:"required"` Description string `json:"description" binding:"required"` Showcase string `json:"showcase" binding:"required"` diff --git a/docs/docs.go b/docs/docs.go index 91f91ef..8318e14 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -377,19 +377,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "allOf": [ - { - "$ref": "#/definitions/models.Response" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.RecordRequest" - } - } - } - ] + "$ref": "#/definitions/models.Response" } }, "400": { @@ -887,6 +875,23 @@ const docTemplate = `{ } }, "models.EditMapSummaryRequest": { + "type": "object", + "required": [ + "image" + ], + "properties": { + "image": { + "type": "string" + }, + "routes": { + "type": "array", + "items": { + "$ref": "#/definitions/models.EditMapSummaryRequestDetails" + } + } + } + }, + "models.EditMapSummaryRequestDetails": { "type": "object", "required": [ "description", @@ -991,6 +996,9 @@ const docTemplate = `{ "rating": { "type": "number" }, + "route_id": { + "type": "integer" + }, "showcase": { "type": "string" } @@ -1078,17 +1086,6 @@ const docTemplate = `{ } } }, - "models.RecordRequest": { - "type": "object", - "properties": { - "is_partner_orange": { - "type": "boolean" - }, - "partner_id": { - "type": "string" - } - } - }, "models.Response": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index c6bbfbc..212ebee 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -370,19 +370,7 @@ "200": { "description": "OK", "schema": { - "allOf": [ - { - "$ref": "#/definitions/models.Response" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.RecordRequest" - } - } - } - ] + "$ref": "#/definitions/models.Response" } }, "400": { @@ -880,6 +868,23 @@ } }, "models.EditMapSummaryRequest": { + "type": "object", + "required": [ + "image" + ], + "properties": { + "image": { + "type": "string" + }, + "routes": { + "type": "array", + "items": { + "$ref": "#/definitions/models.EditMapSummaryRequestDetails" + } + } + } + }, + "models.EditMapSummaryRequestDetails": { "type": "object", "required": [ "description", @@ -984,6 +989,9 @@ "rating": { "type": "number" }, + "route_id": { + "type": "integer" + }, "showcase": { "type": "string" } @@ -1071,17 +1079,6 @@ } } }, - "models.RecordRequest": { - "type": "object", - "properties": { - "is_partner_orange": { - "type": "boolean" - }, - "partner_id": { - "type": "string" - } - } - }, "models.Response": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 4291cfc..ba20f6d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -33,6 +33,17 @@ definitions: $ref: '#/definitions/models.Game' type: object models.EditMapSummaryRequest: + properties: + image: + type: string + routes: + items: + $ref: '#/definitions/models.EditMapSummaryRequestDetails' + type: array + required: + - image + type: object + models.EditMapSummaryRequestDetails: properties: description: type: string @@ -102,6 +113,8 @@ definitions: $ref: '#/definitions/models.MapHistory' rating: type: number + route_id: + type: integer showcase: type: string type: object @@ -158,13 +171,6 @@ definitions: $ref: '#/definitions/models.UserRanking' type: array type: object - models.RecordRequest: - properties: - is_partner_orange: - type: boolean - partner_id: - type: string - type: object models.Response: properties: data: {} @@ -429,12 +435,7 @@ paths: "200": description: OK schema: - allOf: - - $ref: '#/definitions/models.Response' - - properties: - data: - $ref: '#/definitions/models.RecordRequest' - type: object + $ref: '#/definitions/models.Response' "400": description: Bad Request schema: -- cgit v1.2.3 From 7d27b7bde11fa117f37ce18e0807ef299b69c700 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 29 Jun 2023 19:35:02 +0300 Subject: docs: updated for add/edit/delete map summary Former-commit-id: 0f2f20f84b5a52d747f18fba771bc88478f8c059 --- docs/docs.go | 96 +++++++++++++++++++++++++++++++++++++++++++++++++------ docs/swagger.json | 96 +++++++++++++++++++++++++++++++++++++++++++++++++------ docs/swagger.yaml | 66 +++++++++++++++++++++++++++++++++----- 3 files changed, 232 insertions(+), 26 deletions(-) (limited to 'docs/docs.go') diff --git a/docs/docs.go b/docs/docs.go index 8318e14..40632e3 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -492,6 +492,59 @@ const docTemplate = `{ } } } + }, + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "summary": "Delete map summary with specified map id.", + "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.DeleteMapSummaryRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.DeleteMapSummaryRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } } }, "/profile": { @@ -874,24 +927,49 @@ const docTemplate = `{ } } }, - "models.EditMapSummaryRequest": { + "models.CreateMapSummaryRequest": { "type": "object", "required": [ - "image" + "category_id", + "description", + "record_date", + "score_count", + "showcase", + "user_name" ], "properties": { - "image": { + "category_id": { + "type": "integer" + }, + "description": { "type": "string" }, - "routes": { - "type": "array", - "items": { - "$ref": "#/definitions/models.EditMapSummaryRequestDetails" - } + "record_date": { + "type": "string" + }, + "score_count": { + "type": "integer" + }, + "showcase": { + "type": "string" + }, + "user_name": { + "type": "string" } } }, - "models.EditMapSummaryRequestDetails": { + "models.DeleteMapSummaryRequest": { + "type": "object", + "required": [ + "route_id" + ], + "properties": { + "route_id": { + "type": "integer" + } + } + }, + "models.EditMapSummaryRequest": { "type": "object", "required": [ "description", diff --git a/docs/swagger.json b/docs/swagger.json index 212ebee..7e251ca 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -485,6 +485,59 @@ } } } + }, + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "summary": "Delete map summary with specified map id.", + "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.DeleteMapSummaryRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.DeleteMapSummaryRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } } }, "/profile": { @@ -867,24 +920,49 @@ } } }, - "models.EditMapSummaryRequest": { + "models.CreateMapSummaryRequest": { "type": "object", "required": [ - "image" + "category_id", + "description", + "record_date", + "score_count", + "showcase", + "user_name" ], "properties": { - "image": { + "category_id": { + "type": "integer" + }, + "description": { "type": "string" }, - "routes": { - "type": "array", - "items": { - "$ref": "#/definitions/models.EditMapSummaryRequestDetails" - } + "record_date": { + "type": "string" + }, + "score_count": { + "type": "integer" + }, + "showcase": { + "type": "string" + }, + "user_name": { + "type": "string" } } }, - "models.EditMapSummaryRequestDetails": { + "models.DeleteMapSummaryRequest": { + "type": "object", + "required": [ + "route_id" + ], + "properties": { + "route_id": { + "type": "integer" + } + } + }, + "models.EditMapSummaryRequest": { "type": "object", "required": [ "description", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index ba20f6d..5309f67 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -32,18 +32,36 @@ definitions: game: $ref: '#/definitions/models.Game' type: object - models.EditMapSummaryRequest: + models.CreateMapSummaryRequest: properties: - image: + category_id: + type: integer + description: type: string - routes: - items: - $ref: '#/definitions/models.EditMapSummaryRequestDetails' - type: array + record_date: + type: string + score_count: + type: integer + showcase: + type: string + user_name: + type: string + required: + - category_id + - description + - record_date + - score_count + - showcase + - user_name + type: object + models.DeleteMapSummaryRequest: + properties: + route_id: + type: integer required: - - image + - route_id type: object - models.EditMapSummaryRequestDetails: + models.EditMapSummaryRequest: properties: description: type: string @@ -474,6 +492,38 @@ paths: summary: Get map summary with specified id. tags: - maps + post: + parameters: + - description: Map ID + in: path + name: id + required: true + type: integer + - description: Body + in: body + name: request + required: true + schema: + $ref: '#/definitions/models.DeleteMapSummaryRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/models.Response' + - properties: + data: + $ref: '#/definitions/models.DeleteMapSummaryRequest' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/models.Response' + summary: Delete map summary with specified map id. + tags: + - maps put: parameters: - description: Map ID -- cgit v1.2.3 From f187bc7df9b25acdbbf07f13063c9ea0111a6a3b Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 29 Jun 2023 19:35:54 +0300 Subject: docs: fix delete map summary Former-commit-id: c94adce2fb9a6210f2732a35075bbe49adebc532 --- backend/controllers/modController.go | 2 +- docs/docs.go | 53 ++++++++++++++++++++++++++++++++++++ docs/swagger.json | 53 ++++++++++++++++++++++++++++++++++++ docs/swagger.yaml | 38 ++++++++++++++++++++++++-- 4 files changed, 142 insertions(+), 4 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index 9398b2c..a8e0786 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -185,7 +185,7 @@ func EditMapSummary(c *gin.Context) { // @Param request body models.DeleteMapSummaryRequest true "Body" // @Success 200 {object} models.Response{data=models.DeleteMapSummaryRequest} // @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [post] +// @Router /maps/{id}/summary [delete] func DeleteMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") diff --git a/docs/docs.go b/docs/docs.go index 40632e3..8affdab 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -494,6 +494,59 @@ const docTemplate = `{ } }, "post": { + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "summary": "Create map summary with specified map id.", + "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.CreateMapSummaryRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.CreateMapSummaryRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + }, + "delete": { "produces": [ "application/json" ], diff --git a/docs/swagger.json b/docs/swagger.json index 7e251ca..af3fa11 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -487,6 +487,59 @@ } }, "post": { + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "summary": "Create map summary with specified map id.", + "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.CreateMapSummaryRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.CreateMapSummaryRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + }, + "delete": { "produces": [ "application/json" ], diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5309f67..0c55964 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -466,6 +466,38 @@ paths: tags: - maps /maps/{id}/summary: + delete: + parameters: + - description: Map ID + in: path + name: id + required: true + type: integer + - description: Body + in: body + name: request + required: true + schema: + $ref: '#/definitions/models.DeleteMapSummaryRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/models.Response' + - properties: + data: + $ref: '#/definitions/models.DeleteMapSummaryRequest' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/models.Response' + summary: Delete map summary with specified map id. + tags: + - maps get: parameters: - description: Map ID @@ -504,7 +536,7 @@ paths: name: request required: true schema: - $ref: '#/definitions/models.DeleteMapSummaryRequest' + $ref: '#/definitions/models.CreateMapSummaryRequest' produces: - application/json responses: @@ -515,13 +547,13 @@ paths: - $ref: '#/definitions/models.Response' - properties: data: - $ref: '#/definitions/models.DeleteMapSummaryRequest' + $ref: '#/definitions/models.CreateMapSummaryRequest' type: object "400": description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Delete map summary with specified map id. + summary: Create map summary with specified map id. tags: - maps put: -- cgit v1.2.3 From f3b4838e255745cdc3dec368ed29e5b321dedc8b Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Thu, 29 Jun 2023 19:40:07 +0300 Subject: docs: add jwt token requirements Former-commit-id: e5b56433686e2180a99293f0ddf339e70b304c67 --- backend/controllers/modController.go | 3 +++ docs/docs.go | 21 +++++++++++++++++++++ docs/swagger.json | 21 +++++++++++++++++++++ docs/swagger.yaml | 15 +++++++++++++++ 4 files changed, 60 insertions(+) (limited to 'docs/docs.go') diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index a8e0786..b26f1ae 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -14,6 +14,7 @@ import ( // @Summary Create map summary with specified map id. // @Tags maps // @Produce json +// @Param Authorization header string true "JWT Token" // @Param id path int true "Map ID" // @Param request body models.CreateMapSummaryRequest true "Body" // @Success 200 {object} models.Response{data=models.CreateMapSummaryRequest} @@ -99,6 +100,7 @@ func CreateMapSummary(c *gin.Context) { // @Summary Edit map summary with specified map id. // @Tags maps // @Produce json +// @Param Authorization header string true "JWT Token" // @Param id path int true "Map ID" // @Param request body models.EditMapSummaryRequest true "Body" // @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} @@ -181,6 +183,7 @@ func EditMapSummary(c *gin.Context) { // @Summary Delete map summary with specified map id. // @Tags maps // @Produce json +// @Param Authorization header string true "JWT Token" // @Param id path int true "Map ID" // @Param request body models.DeleteMapSummaryRequest true "Body" // @Success 200 {object} models.Response{data=models.DeleteMapSummaryRequest} diff --git a/docs/docs.go b/docs/docs.go index 8affdab..9368c2c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -449,6 +449,13 @@ const docTemplate = `{ ], "summary": "Edit map summary with specified map id.", "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Map ID", @@ -502,6 +509,13 @@ const docTemplate = `{ ], "summary": "Create map summary with specified map id.", "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Map ID", @@ -555,6 +569,13 @@ const docTemplate = `{ ], "summary": "Delete map summary with specified map id.", "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Map ID", diff --git a/docs/swagger.json b/docs/swagger.json index af3fa11..3acc883 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -442,6 +442,13 @@ ], "summary": "Edit map summary with specified map id.", "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Map ID", @@ -495,6 +502,13 @@ ], "summary": "Create map summary with specified map id.", "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Map ID", @@ -548,6 +562,13 @@ ], "summary": "Delete map summary with specified map id.", "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, { "type": "integer", "description": "Map ID", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0c55964..6d06e22 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -468,6 +468,11 @@ paths: /maps/{id}/summary: delete: parameters: + - description: JWT Token + in: header + name: Authorization + required: true + type: string - description: Map ID in: path name: id @@ -526,6 +531,11 @@ paths: - maps post: parameters: + - description: JWT Token + in: header + name: Authorization + required: true + type: string - description: Map ID in: path name: id @@ -558,6 +568,11 @@ paths: - maps put: parameters: + - description: JWT Token + in: header + name: Authorization + required: true + type: string - description: Map ID in: path name: id -- cgit v1.2.3 From 57ef0fc54af49052539306c35501a893f24eca18 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:40:43 +0300 Subject: docs: update swagger Former-commit-id: d55150a028f67d5dc8668e2b2384d13511339b46 --- backend/controllers/modController.go | 30 +++++++++++++++--------------- backend/controllers/recordController.go | 6 +++--- docs/docs.go | 15 +++++---------- docs/swagger.json | 9 +++------ docs/swagger.yaml | 3 --- 5 files changed, 26 insertions(+), 37 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index b26f1ae..f1874f7 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -14,11 +14,11 @@ import ( // @Summary Create map summary with specified map id. // @Tags maps // @Produce json -// @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" -// @Param request body models.CreateMapSummaryRequest true "Body" -// @Success 200 {object} models.Response{data=models.CreateMapSummaryRequest} -// @Failure 400 {object} models.Response +// @Param Authorization header string true "JWT Token" +// @Param id path int true "Map ID" +// @Param request body models.CreateMapSummaryRequest true "Body" +// @Success 200 {object} models.Response{data=models.CreateMapSummaryRequest} +// @Failure 400 {object} models.Response // @Router /maps/{id}/summary [post] func CreateMapSummary(c *gin.Context) { // Check if user exists @@ -100,11 +100,11 @@ func CreateMapSummary(c *gin.Context) { // @Summary Edit map summary with specified map id. // @Tags maps // @Produce json -// @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" -// @Param request body models.EditMapSummaryRequest true "Body" -// @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} -// @Failure 400 {object} models.Response +// @Param Authorization header string true "JWT Token" +// @Param id path int true "Map ID" +// @Param request body models.EditMapSummaryRequest true "Body" +// @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} +// @Failure 400 {object} models.Response // @Router /maps/{id}/summary [put] func EditMapSummary(c *gin.Context) { // Check if user exists @@ -183,11 +183,11 @@ func EditMapSummary(c *gin.Context) { // @Summary Delete map summary with specified map id. // @Tags maps // @Produce json -// @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" -// @Param request body models.DeleteMapSummaryRequest true "Body" -// @Success 200 {object} models.Response{data=models.DeleteMapSummaryRequest} -// @Failure 400 {object} models.Response +// @Param Authorization header string true "JWT Token" +// @Param id path int true "Map ID" +// @Param request body models.DeleteMapSummaryRequest true "Body" +// @Success 200 {object} models.Response{data=models.DeleteMapSummaryRequest} +// @Failure 400 {object} models.Response // @Router /maps/{id}/summary [delete] func DeleteMapSummary(c *gin.Context) { // Check if user exists diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index 183ab27..9cc6da6 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go @@ -27,9 +27,9 @@ import ( // @Produce json // @Param Authorization header string true "JWT Token" // @Param host_demo formData file true "Host Demo" -// @Param partner_demo formData file true "Partner Demo" -// @Param is_partner_orange formData boolean true "Is Partner Orange" -// @Param partner_id formData string true "Partner ID" +// @Param partner_demo formData file false "Partner Demo" +// @Param is_partner_orange formData boolean false "Is Partner Orange" +// @Param partner_id formData string false "Partner ID" // @Success 200 {object} models.Response // @Failure 400 {object} models.Response // @Failure 401 {object} models.Response diff --git a/docs/docs.go b/docs/docs.go index 9368c2c..41acab3 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,5 +1,5 @@ -// Code generated by swaggo/swag. DO NOT EDIT. - +// Package docs GENERATED BY SWAG; DO NOT EDIT +// This file was generated by swaggo/swag package docs import "github.com/swaggo/swag" @@ -355,22 +355,19 @@ const docTemplate = `{ "type": "file", "description": "Partner Demo", "name": "partner_demo", - "in": "formData", - "required": true + "in": "formData" }, { "type": "boolean", "description": "Is Partner Orange", "name": "is_partner_orange", - "in": "formData", - "required": true + "in": "formData" }, { "type": "string", "description": "Partner ID", "name": "partner_id", - "in": "formData", - "required": true + "in": "formData" } ], "responses": { @@ -1314,8 +1311,6 @@ var SwaggerInfo = &swag.Spec{ Description: "Backend API endpoints for the Least Portals Database.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index 3acc883..3ec06b6 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -348,22 +348,19 @@ "type": "file", "description": "Partner Demo", "name": "partner_demo", - "in": "formData", - "required": true + "in": "formData" }, { "type": "boolean", "description": "Is Partner Orange", "name": "is_partner_orange", - "in": "formData", - "required": true + "in": "formData" }, { "type": "string", "description": "Partner ID", "name": "partner_id", - "in": "formData", - "required": true + "in": "formData" } ], "responses": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6d06e22..3fe5d66 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -435,17 +435,14 @@ paths: - description: Partner Demo in: formData name: partner_demo - required: true type: file - description: Is Partner Orange in: formData name: is_partner_orange - required: true type: boolean - description: Partner ID in: formData name: partner_id - required: true type: string produces: - application/json -- cgit v1.2.3 From 4a5a3f13a7b644decb804bc1e1507dda14477205 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:52:42 +0300 Subject: docs: add missing field to post record Former-commit-id: 73726de788daf38a82d9663ab2d8f0544b76c3e3 --- backend/controllers/recordController.go | 1 + docs/docs.go | 7 +++++++ docs/swagger.json | 7 +++++++ docs/swagger.yaml | 5 +++++ 4 files changed, 20 insertions(+) (limited to 'docs/docs.go') diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index 101f0e4..6751afc 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go @@ -25,6 +25,7 @@ import ( // @Tags maps // @Accept mpfd // @Produce json +// @Param id path int true "Map ID" // @Param Authorization header string true "JWT Token" // @Param host_demo formData file true "Host Demo" // @Param partner_demo formData file false "Partner Demo" diff --git a/docs/docs.go b/docs/docs.go index 41acab3..bb14382 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -337,6 +337,13 @@ const docTemplate = `{ ], "summary": "Post record with demo of a specific map.", "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, { "type": "string", "description": "JWT Token", diff --git a/docs/swagger.json b/docs/swagger.json index 3ec06b6..3530d2c 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -330,6 +330,13 @@ ], "summary": "Post record with demo of a specific map.", "parameters": [ + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, { "type": "string", "description": "JWT Token", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 3fe5d66..d4420e2 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -422,6 +422,11 @@ paths: consumes: - multipart/form-data parameters: + - description: Map ID + in: path + name: id + required: true + type: integer - description: JWT Token in: header name: Authorization -- cgit v1.2.3 From c071eeca829a18941fc29f4e4eb8b8f93a65b5c4 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:16:42 +0300 Subject: docs: refactor docs Former-commit-id: 3f3833af352d8758ca509a4fe3badedd5250b1ba --- backend/controllers/homeController.go | 26 ++++---- backend/controllers/loginController.go | 38 +++++------ backend/controllers/mapController.go | 68 +++++++++---------- backend/controllers/modController.go | 54 +++++++-------- backend/controllers/recordController.go | 44 ++++++------- backend/controllers/userController.go | 74 ++++++++++----------- docs/docs.go | 112 ++++++++++++++++---------------- docs/swagger.json | 112 ++++++++++++++++---------------- docs/swagger.yaml | 80 +++++++++++------------ 9 files changed, 304 insertions(+), 304 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/homeController.go b/backend/controllers/homeController.go index b5c6b60..2780e63 100644 --- a/backend/controllers/homeController.go +++ b/backend/controllers/homeController.go @@ -23,12 +23,12 @@ func Home(c *gin.Context) { // GET Rankings // -// @Summary Get rankings of every player. -// @Tags rankings -// @Produce json -// @Success 200 {object} models.Response{data=models.RankingsResponse} -// @Failure 400 {object} models.Response -// @Router /demo [get] +// @Description Get rankings of every player. +// @Tags rankings +// @Produce json +// @Success 200 {object} models.Response{data=models.RankingsResponse} +// @Failure 400 {object} models.Response +// @Router /rankings [get] func Rankings(c *gin.Context) { rows, err := database.DB.Query(`SELECT steam_id, user_name FROM users`) if err != nil { @@ -125,13 +125,13 @@ func Rankings(c *gin.Context) { // GET Search With Query // -// @Summary Get all user and map data matching to the query. -// @Tags search -// @Produce json -// @Param q query string false "Search user or map name." -// @Success 200 {object} models.Response{data=models.SearchResponse} -// @Failure 400 {object} models.Response -// @Router /search [get] +// @Description Get all user and map data matching to the query. +// @Tags search +// @Produce json +// @Param q query string false "Search user or map name." +// @Success 200 {object} models.Response{data=models.SearchResponse} +// @Failure 400 {object} models.Response +// @Router /search [get] func SearchWithQuery(c *gin.Context) { query := c.Query("q") query = strings.ToLower(query) diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index b30d26e..ae6e957 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go @@ -17,13 +17,13 @@ import ( // Login // -// @Summary Get (redirect) login page for Steam auth. -// @Tags login -// @Accept json -// @Produce json -// @Success 200 {object} models.Response{data=models.LoginResponse} -// @Failure 400 {object} models.Response -// @Router /login [get] +// @Description Get (redirect) login page for Steam auth. +// @Tags login +// @Accept json +// @Produce json +// @Success 200 {object} models.Response{data=models.LoginResponse} +// @Failure 400 {object} models.Response +// @Router /login [get] func Login(c *gin.Context) { openID := steam_go.NewOpenId(c.Request) switch openID.Mode() { @@ -95,13 +95,13 @@ func Login(c *gin.Context) { // GET Token // -// @Summary Gets the token cookie value from the user. -// @Tags auth -// @Produce json +// @Description Gets the token cookie value from the user. +// @Tags auth +// @Produce json // -// @Success 200 {object} models.Response{data=models.LoginResponse} -// @Failure 404 {object} models.Response -// @Router /token [get] +// @Success 200 {object} models.Response{data=models.LoginResponse} +// @Failure 404 {object} models.Response +// @Router /token [get] func GetCookie(c *gin.Context) { cookie, err := c.Cookie("token") if err != nil { @@ -119,13 +119,13 @@ func GetCookie(c *gin.Context) { // DELETE Token // -// @Summary Deletes the token cookie from the user. -// @Tags auth -// @Produce json +// @Description Deletes the token cookie from the user. +// @Tags auth +// @Produce json // -// @Success 200 {object} models.Response{data=models.LoginResponse} -// @Failure 404 {object} models.Response -// @Router /token [delete] +// @Success 200 {object} models.Response{data=models.LoginResponse} +// @Failure 404 {object} models.Response +// @Router /token [delete] func DeleteCookie(c *gin.Context) { cookie, err := c.Cookie("token") if err != nil { diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index 7a26554..52b6623 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go @@ -11,13 +11,13 @@ import ( // GET Map Summary // -// @Summary Get map summary with specified id. -// @Tags maps -// @Produce json -// @Param id path int true "Map ID" -// @Success 200 {object} models.Response{data=models.MapSummaryResponse} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [get] +// @Description Get map summary with specified id. +// @Tags maps +// @Produce json +// @Param id path int true "Map ID" +// @Success 200 {object} models.Response{data=models.MapSummaryResponse} +// @Failure 400 {object} models.Response +// @Router /maps/{id}/summary [get] func FetchMapSummary(c *gin.Context) { id := c.Param("id") response := models.MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{Routes: []models.MapRoute{}}} @@ -69,13 +69,13 @@ func FetchMapSummary(c *gin.Context) { // GET Map Leaderboards // -// @Summary Get map leaderboards with specified id. -// @Tags maps -// @Produce json -// @Param id path int true "Map ID" -// @Success 200 {object} models.Response{data=models.Map{data=models.MapRecords}} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/leaderboards [get] +// @Description Get map leaderboards with specified id. +// @Tags maps +// @Produce json +// @Param id path int true "Map ID" +// @Success 200 {object} models.Response{data=models.Map{data=models.MapRecords}} +// @Failure 400 {object} models.Response +// @Router /maps/{id}/leaderboards [get] func FetchMapLeaderboards(c *gin.Context) { // TODO: make new response type id := c.Param("id") @@ -186,12 +186,12 @@ func FetchMapLeaderboards(c *gin.Context) { // GET Games // -// @Summary Get games from the leaderboards. -// @Tags games & chapters -// @Produce json -// @Success 200 {object} models.Response{data=[]models.Game} -// @Failure 400 {object} models.Response -// @Router /games [get] +// @Description Get games from the leaderboards. +// @Tags games & chapters +// @Produce json +// @Success 200 {object} models.Response{data=[]models.Game} +// @Failure 400 {object} models.Response +// @Router /games [get] func FetchGames(c *gin.Context) { rows, err := database.DB.Query(`SELECT id, name FROM games`) if err != nil { @@ -216,13 +216,13 @@ func FetchGames(c *gin.Context) { // GET Chapters of a Game // -// @Summary Get chapters from the specified game id. -// @Tags games & chapters -// @Produce json -// @Param id path int true "Game ID" -// @Success 200 {object} models.Response{data=models.ChaptersResponse} -// @Failure 400 {object} models.Response -// @Router /games/{id} [get] +// @Description Get chapters from the specified game id. +// @Tags games & chapters +// @Produce json +// @Param id path int true "Game ID" +// @Success 200 {object} models.Response{data=models.ChaptersResponse} +// @Failure 400 {object} models.Response +// @Router /games/{id} [get] func FetchChapters(c *gin.Context) { gameID := c.Param("id") intID, err := strconv.Atoi(gameID) @@ -258,13 +258,13 @@ func FetchChapters(c *gin.Context) { // GET Maps of a Chapter // -// @Summary Get maps from the specified chapter id. -// @Tags games & chapters -// @Produce json -// @Param id path int true "Chapter ID" -// @Success 200 {object} models.Response{data=models.ChapterMapsResponse} -// @Failure 400 {object} models.Response -// @Router /chapters/{id} [get] +// @Description Get maps from the specified chapter id. +// @Tags games & chapters +// @Produce json +// @Param id path int true "Chapter ID" +// @Success 200 {object} models.Response{data=models.ChapterMapsResponse} +// @Failure 400 {object} models.Response +// @Router /chapters/{id} [get] func FetchChapterMaps(c *gin.Context) { chapterID := c.Param("id") intID, err := strconv.Atoi(chapterID) diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index f1874f7..d6dc4d4 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -11,15 +11,15 @@ import ( // POST Map Summary // -// @Summary Create map summary with specified map id. -// @Tags maps -// @Produce json -// @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" -// @Param request body models.CreateMapSummaryRequest true "Body" -// @Success 200 {object} models.Response{data=models.CreateMapSummaryRequest} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [post] +// @Description Create map summary with specified map id. +// @Tags maps +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param id path int true "Map ID" +// @Param request body models.CreateMapSummaryRequest true "Body" +// @Success 200 {object} models.Response{data=models.CreateMapSummaryRequest} +// @Failure 400 {object} models.Response +// @Router /maps/{id}/summary [post] func CreateMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -97,15 +97,15 @@ func CreateMapSummary(c *gin.Context) { // PUT Map Summary // -// @Summary Edit map summary with specified map id. -// @Tags maps -// @Produce json -// @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" -// @Param request body models.EditMapSummaryRequest true "Body" -// @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [put] +// @Description Edit map summary with specified map id. +// @Tags maps +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param id path int true "Map ID" +// @Param request body models.EditMapSummaryRequest true "Body" +// @Success 200 {object} models.Response{data=models.EditMapSummaryRequest} +// @Failure 400 {object} models.Response +// @Router /maps/{id}/summary [put] func EditMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -180,15 +180,15 @@ func EditMapSummary(c *gin.Context) { // DELETE Map Summary // -// @Summary Delete map summary with specified map id. -// @Tags maps -// @Produce json -// @Param Authorization header string true "JWT Token" -// @Param id path int true "Map ID" -// @Param request body models.DeleteMapSummaryRequest true "Body" -// @Success 200 {object} models.Response{data=models.DeleteMapSummaryRequest} -// @Failure 400 {object} models.Response -// @Router /maps/{id}/summary [delete] +// @Description Delete map summary with specified map id. +// @Tags maps +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param id path int true "Map ID" +// @Param request body models.DeleteMapSummaryRequest true "Body" +// @Success 200 {object} models.Response{data=models.DeleteMapSummaryRequest} +// @Failure 400 {object} models.Response +// @Router /maps/{id}/summary [delete] func DeleteMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index 409a2e7..af8eb63 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go @@ -21,20 +21,20 @@ import ( // POST Record // -// @Summary Post record with demo of a specific map. -// @Tags maps -// @Accept mpfd -// @Produce json -// @Param id path int true "Map ID" -// @Param Authorization header string true "JWT Token" -// @Param host_demo formData file true "Host Demo" -// @Param partner_demo formData file false "Partner Demo" -// @Param is_partner_orange formData boolean false "Is Partner Orange" -// @Param partner_id formData string false "Partner ID" -// @Success 200 {object} models.Response -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response -// @Router /maps/{id}/record [post] +// @Description Post record with demo of a specific map. +// @Tags maps +// @Accept mpfd +// @Produce json +// @Param id path int true "Map ID" +// @Param Authorization header string true "JWT Token" +// @Param host_demo formData file true "Host Demo" +// @Param partner_demo formData file false "Partner Demo" +// @Param is_partner_orange formData boolean false "Is Partner Orange" +// @Param partner_id formData string false "Partner ID" +// @Success 200 {object} models.Response +// @Failure 400 {object} models.Response +// @Failure 401 {object} models.Response +// @Router /maps/{id}/record [post] func CreateRecordWithDemo(c *gin.Context) { mapId := c.Param("id") // Check if user exists @@ -189,14 +189,14 @@ func CreateRecordWithDemo(c *gin.Context) { // GET Demo // -// @Summary Get demo with specified demo uuid. -// @Tags demo -// @Accept json -// @Produce octet-stream -// @Param uuid query int true "Demo UUID" -// @Success 200 {file} binary "Demo File" -// @Failure 400 {object} models.Response -// @Router /demos [get] +// @Description Get demo with specified demo uuid. +// @Tags demo +// @Accept json +// @Produce octet-stream +// @Param uuid query string true "Demo UUID" +// @Success 200 {file} binary "Demo File" +// @Failure 400 {object} models.Response +// @Router /demos [get] func DownloadDemoWithID(c *gin.Context) { uuid := c.Query("uuid") var locationID string diff --git a/backend/controllers/userController.go b/backend/controllers/userController.go index cbce0fe..e73b1fe 100644 --- a/backend/controllers/userController.go +++ b/backend/controllers/userController.go @@ -13,15 +13,15 @@ import ( // GET Profile // -// @Summary Get profile page of session user. -// @Tags users -// @Accept json -// @Produce json -// @Param Authorization header string true "JWT Token" -// @Success 200 {object} models.Response{data=models.ProfileResponse} -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response -// @Router /profile [get] +// @Description Get profile page of session user. +// @Tags users +// @Accept json +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Success 200 {object} models.Response{data=models.ProfileResponse} +// @Failure 400 {object} models.Response +// @Failure 401 {object} models.Response +// @Router /profile [get] func Profile(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -100,15 +100,15 @@ func Profile(c *gin.Context) { // GET User // -// @Summary Get profile page of another user. -// @Tags users -// @Accept json -// @Produce json -// @Param id path int true "User ID" -// @Success 200 {object} models.Response{data=models.ProfileResponse} -// @Failure 400 {object} models.Response -// @Failure 404 {object} models.Response -// @Router /users/{id} [get] +// @Description Get profile page of another user. +// @Tags users +// @Accept json +// @Produce json +// @Param id path int true "User ID" +// @Success 200 {object} models.Response{data=models.ProfileResponse} +// @Failure 400 {object} models.Response +// @Failure 404 {object} models.Response +// @Router /users/{id} [get] func FetchUser(c *gin.Context) { id := c.Param("id") // Check if id is all numbers and 17 length @@ -202,15 +202,15 @@ func FetchUser(c *gin.Context) { // PUT Profile // -// @Summary Update profile page of session user. -// @Tags users -// @Accept json -// @Produce json -// @Param Authorization header string true "JWT Token" -// @Success 200 {object} models.Response{data=models.ProfileResponse} -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response -// @Router /profile [post] +// @Description Update profile page of session user. +// @Tags users +// @Accept json +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Success 200 {object} models.Response{data=models.ProfileResponse} +// @Failure 400 {object} models.Response +// @Failure 401 {object} models.Response +// @Router /profile [post] func UpdateUser(c *gin.Context) { // Check if user exists user, exists := c.Get("user") @@ -245,16 +245,16 @@ func UpdateUser(c *gin.Context) { // PUT Profile/CountryCode // -// @Summary Update country code of session user. -// @Tags users -// @Accept json -// @Produce json -// @Param Authorization header string true "JWT Token" -// @Param country_code query string true "Country Code [XX]" -// @Success 200 {object} models.Response -// @Failure 400 {object} models.Response -// @Failure 401 {object} models.Response -// @Router /profile [put] +// @Description Update country code of session user. +// @Tags users +// @Accept json +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param country_code query string true "Country Code [XX]" +// @Success 200 {object} models.Response +// @Failure 400 {object} models.Response +// @Failure 401 {object} models.Response +// @Router /profile [put] func UpdateCountryCode(c *gin.Context) { // Check if user exists user, exists := c.Get("user") diff --git a/docs/docs.go b/docs/docs.go index bb14382..57984f4 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -22,13 +22,13 @@ const docTemplate = `{ "paths": { "/chapters/{id}": { "get": { + "description": "Get maps from the specified chapter id.", "produces": [ "application/json" ], "tags": [ "games \u0026 chapters" ], - "summary": "Get maps from the specified chapter id.", "parameters": [ { "type": "integer", @@ -66,45 +66,9 @@ const docTemplate = `{ } } }, - "/demo": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "rankings" - ], - "summary": "Get rankings of every player.", - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/models.Response" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.RankingsResponse" - } - } - } - ] - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/models.Response" - } - } - } - } - }, "/demos": { "get": { + "description": "Get demo with specified demo uuid.", "consumes": [ "application/json" ], @@ -114,10 +78,9 @@ const docTemplate = `{ "tags": [ "demo" ], - "summary": "Get demo with specified demo uuid.", "parameters": [ { - "type": "integer", + "type": "string", "description": "Demo UUID", "name": "uuid", "in": "query", @@ -142,13 +105,13 @@ const docTemplate = `{ }, "/games": { "get": { + "description": "Get games from the leaderboards.", "produces": [ "application/json" ], "tags": [ "games \u0026 chapters" ], - "summary": "Get games from the leaderboards.", "responses": { "200": { "description": "OK", @@ -182,13 +145,13 @@ const docTemplate = `{ }, "/games/{id}": { "get": { + "description": "Get chapters from the specified game id.", "produces": [ "application/json" ], "tags": [ "games \u0026 chapters" ], - "summary": "Get chapters from the specified game id.", "parameters": [ { "type": "integer", @@ -228,6 +191,7 @@ const docTemplate = `{ }, "/login": { "get": { + "description": "Get (redirect) login page for Steam auth.", "consumes": [ "application/json" ], @@ -237,7 +201,6 @@ const docTemplate = `{ "tags": [ "login" ], - "summary": "Get (redirect) login page for Steam auth.", "responses": { "200": { "description": "OK", @@ -268,13 +231,13 @@ const docTemplate = `{ }, "/maps/{id}/leaderboards": { "get": { + "description": "Get map leaderboards with specified id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Get map leaderboards with specified id.", "parameters": [ { "type": "integer", @@ -326,6 +289,7 @@ const docTemplate = `{ }, "/maps/{id}/record": { "post": { + "description": "Post record with demo of a specific map.", "consumes": [ "multipart/form-data" ], @@ -335,7 +299,6 @@ const docTemplate = `{ "tags": [ "maps" ], - "summary": "Post record with demo of a specific map.", "parameters": [ { "type": "integer", @@ -401,13 +364,13 @@ const docTemplate = `{ }, "/maps/{id}/summary": { "get": { + "description": "Get map summary with specified id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Get map summary with specified id.", "parameters": [ { "type": "integer", @@ -445,13 +408,13 @@ const docTemplate = `{ } }, "put": { + "description": "Edit map summary with specified map id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Edit map summary with specified map id.", "parameters": [ { "type": "string", @@ -505,13 +468,13 @@ const docTemplate = `{ } }, "post": { + "description": "Create map summary with specified map id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Create map summary with specified map id.", "parameters": [ { "type": "string", @@ -565,13 +528,13 @@ const docTemplate = `{ } }, "delete": { + "description": "Delete map summary with specified map id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Delete map summary with specified map id.", "parameters": [ { "type": "string", @@ -627,6 +590,7 @@ const docTemplate = `{ }, "/profile": { "get": { + "description": "Get profile page of session user.", "consumes": [ "application/json" ], @@ -636,7 +600,6 @@ const docTemplate = `{ "tags": [ "users" ], - "summary": "Get profile page of session user.", "parameters": [ { "type": "string", @@ -680,6 +643,7 @@ const docTemplate = `{ } }, "put": { + "description": "Update country code of session user.", "consumes": [ "application/json" ], @@ -689,7 +653,6 @@ const docTemplate = `{ "tags": [ "users" ], - "summary": "Update country code of session user.", "parameters": [ { "type": "string", @@ -728,6 +691,7 @@ const docTemplate = `{ } }, "post": { + "description": "Update profile page of session user.", "consumes": [ "application/json" ], @@ -737,7 +701,6 @@ const docTemplate = `{ "tags": [ "users" ], - "summary": "Update profile page of session user.", "parameters": [ { "type": "string", @@ -781,15 +744,52 @@ const docTemplate = `{ } } }, + "/rankings": { + "get": { + "description": "Get rankings of every player.", + "produces": [ + "application/json" + ], + "tags": [ + "rankings" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.RankingsResponse" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/search": { "get": { + "description": "Get all user and map data matching to the query.", "produces": [ "application/json" ], "tags": [ "search" ], - "summary": "Get all user and map data matching to the query.", "parameters": [ { "type": "string", @@ -828,13 +828,13 @@ const docTemplate = `{ }, "/token": { "get": { + "description": "Gets the token cookie value from the user.", "produces": [ "application/json" ], "tags": [ "auth" ], - "summary": "Gets the token cookie value from the user.", "responses": { "200": { "description": "OK", @@ -863,13 +863,13 @@ const docTemplate = `{ } }, "delete": { + "description": "Deletes the token cookie from the user.", "produces": [ "application/json" ], "tags": [ "auth" ], - "summary": "Deletes the token cookie from the user.", "responses": { "200": { "description": "OK", @@ -900,6 +900,7 @@ const docTemplate = `{ }, "/users/{id}": { "get": { + "description": "Get profile page of another user.", "consumes": [ "application/json" ], @@ -909,7 +910,6 @@ const docTemplate = `{ "tags": [ "users" ], - "summary": "Get profile page of another user.", "parameters": [ { "type": "integer", diff --git a/docs/swagger.json b/docs/swagger.json index 3530d2c..ef422ab 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -15,13 +15,13 @@ "paths": { "/chapters/{id}": { "get": { + "description": "Get maps from the specified chapter id.", "produces": [ "application/json" ], "tags": [ "games \u0026 chapters" ], - "summary": "Get maps from the specified chapter id.", "parameters": [ { "type": "integer", @@ -59,45 +59,9 @@ } } }, - "/demo": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "rankings" - ], - "summary": "Get rankings of every player.", - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/models.Response" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/models.RankingsResponse" - } - } - } - ] - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/models.Response" - } - } - } - } - }, "/demos": { "get": { + "description": "Get demo with specified demo uuid.", "consumes": [ "application/json" ], @@ -107,10 +71,9 @@ "tags": [ "demo" ], - "summary": "Get demo with specified demo uuid.", "parameters": [ { - "type": "integer", + "type": "string", "description": "Demo UUID", "name": "uuid", "in": "query", @@ -135,13 +98,13 @@ }, "/games": { "get": { + "description": "Get games from the leaderboards.", "produces": [ "application/json" ], "tags": [ "games \u0026 chapters" ], - "summary": "Get games from the leaderboards.", "responses": { "200": { "description": "OK", @@ -175,13 +138,13 @@ }, "/games/{id}": { "get": { + "description": "Get chapters from the specified game id.", "produces": [ "application/json" ], "tags": [ "games \u0026 chapters" ], - "summary": "Get chapters from the specified game id.", "parameters": [ { "type": "integer", @@ -221,6 +184,7 @@ }, "/login": { "get": { + "description": "Get (redirect) login page for Steam auth.", "consumes": [ "application/json" ], @@ -230,7 +194,6 @@ "tags": [ "login" ], - "summary": "Get (redirect) login page for Steam auth.", "responses": { "200": { "description": "OK", @@ -261,13 +224,13 @@ }, "/maps/{id}/leaderboards": { "get": { + "description": "Get map leaderboards with specified id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Get map leaderboards with specified id.", "parameters": [ { "type": "integer", @@ -319,6 +282,7 @@ }, "/maps/{id}/record": { "post": { + "description": "Post record with demo of a specific map.", "consumes": [ "multipart/form-data" ], @@ -328,7 +292,6 @@ "tags": [ "maps" ], - "summary": "Post record with demo of a specific map.", "parameters": [ { "type": "integer", @@ -394,13 +357,13 @@ }, "/maps/{id}/summary": { "get": { + "description": "Get map summary with specified id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Get map summary with specified id.", "parameters": [ { "type": "integer", @@ -438,13 +401,13 @@ } }, "put": { + "description": "Edit map summary with specified map id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Edit map summary with specified map id.", "parameters": [ { "type": "string", @@ -498,13 +461,13 @@ } }, "post": { + "description": "Create map summary with specified map id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Create map summary with specified map id.", "parameters": [ { "type": "string", @@ -558,13 +521,13 @@ } }, "delete": { + "description": "Delete map summary with specified map id.", "produces": [ "application/json" ], "tags": [ "maps" ], - "summary": "Delete map summary with specified map id.", "parameters": [ { "type": "string", @@ -620,6 +583,7 @@ }, "/profile": { "get": { + "description": "Get profile page of session user.", "consumes": [ "application/json" ], @@ -629,7 +593,6 @@ "tags": [ "users" ], - "summary": "Get profile page of session user.", "parameters": [ { "type": "string", @@ -673,6 +636,7 @@ } }, "put": { + "description": "Update country code of session user.", "consumes": [ "application/json" ], @@ -682,7 +646,6 @@ "tags": [ "users" ], - "summary": "Update country code of session user.", "parameters": [ { "type": "string", @@ -721,6 +684,7 @@ } }, "post": { + "description": "Update profile page of session user.", "consumes": [ "application/json" ], @@ -730,7 +694,6 @@ "tags": [ "users" ], - "summary": "Update profile page of session user.", "parameters": [ { "type": "string", @@ -774,15 +737,52 @@ } } }, + "/rankings": { + "get": { + "description": "Get rankings of every player.", + "produces": [ + "application/json" + ], + "tags": [ + "rankings" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.RankingsResponse" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/search": { "get": { + "description": "Get all user and map data matching to the query.", "produces": [ "application/json" ], "tags": [ "search" ], - "summary": "Get all user and map data matching to the query.", "parameters": [ { "type": "string", @@ -821,13 +821,13 @@ }, "/token": { "get": { + "description": "Gets the token cookie value from the user.", "produces": [ "application/json" ], "tags": [ "auth" ], - "summary": "Gets the token cookie value from the user.", "responses": { "200": { "description": "OK", @@ -856,13 +856,13 @@ } }, "delete": { + "description": "Deletes the token cookie from the user.", "produces": [ "application/json" ], "tags": [ "auth" ], - "summary": "Deletes the token cookie from the user.", "responses": { "200": { "description": "OK", @@ -893,6 +893,7 @@ }, "/users/{id}": { "get": { + "description": "Get profile page of another user.", "consumes": [ "application/json" ], @@ -902,7 +903,6 @@ "tags": [ "users" ], - "summary": "Get profile page of another user.", "parameters": [ { "type": "integer", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index d4420e2..2fed413 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -242,6 +242,7 @@ info: paths: /chapters/{id}: get: + description: Get maps from the specified chapter id. parameters: - description: Chapter ID in: path @@ -264,40 +265,19 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get maps from the specified chapter id. tags: - games & chapters - /demo: - get: - produces: - - application/json - responses: - "200": - description: OK - schema: - allOf: - - $ref: '#/definitions/models.Response' - - properties: - data: - $ref: '#/definitions/models.RankingsResponse' - type: object - "400": - description: Bad Request - schema: - $ref: '#/definitions/models.Response' - summary: Get rankings of every player. - tags: - - rankings /demos: get: consumes: - application/json + description: Get demo with specified demo uuid. parameters: - description: Demo UUID in: query name: uuid required: true - type: integer + type: string produces: - application/octet-stream responses: @@ -309,11 +289,11 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get demo with specified demo uuid. tags: - demo /games: get: + description: Get games from the leaderboards. produces: - application/json responses: @@ -332,11 +312,11 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get games from the leaderboards. tags: - games & chapters /games/{id}: get: + description: Get chapters from the specified game id. parameters: - description: Game ID in: path @@ -359,13 +339,13 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get chapters from the specified game id. tags: - games & chapters /login: get: consumes: - application/json + description: Get (redirect) login page for Steam auth. produces: - application/json responses: @@ -382,11 +362,11 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get (redirect) login page for Steam auth. tags: - login /maps/{id}/leaderboards: get: + description: Get map leaderboards with specified id. parameters: - description: Map ID in: path @@ -414,13 +394,13 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get map leaderboards with specified id. tags: - maps /maps/{id}/record: post: consumes: - multipart/form-data + description: Post record with demo of a specific map. parameters: - description: Map ID in: path @@ -464,11 +444,11 @@ paths: description: Unauthorized schema: $ref: '#/definitions/models.Response' - summary: Post record with demo of a specific map. tags: - maps /maps/{id}/summary: delete: + description: Delete map summary with specified map id. parameters: - description: JWT Token in: header @@ -502,10 +482,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Delete map summary with specified map id. tags: - maps get: + description: Get map summary with specified id. parameters: - description: Map ID in: path @@ -528,10 +508,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get map summary with specified id. tags: - maps post: + description: Create map summary with specified map id. parameters: - description: JWT Token in: header @@ -565,10 +545,10 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Create map summary with specified map id. tags: - maps put: + description: Edit map summary with specified map id. parameters: - description: JWT Token in: header @@ -602,13 +582,13 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Edit map summary with specified map id. tags: - maps /profile: get: consumes: - application/json + description: Get profile page of session user. parameters: - description: JWT Token in: header @@ -635,12 +615,12 @@ paths: description: Unauthorized schema: $ref: '#/definitions/models.Response' - summary: Get profile page of session user. tags: - users post: consumes: - application/json + description: Update profile page of session user. parameters: - description: JWT Token in: header @@ -667,12 +647,12 @@ paths: description: Unauthorized schema: $ref: '#/definitions/models.Response' - summary: Update profile page of session user. tags: - users put: consumes: - application/json + description: Update country code of session user. parameters: - description: JWT Token in: header @@ -699,11 +679,32 @@ paths: description: Unauthorized schema: $ref: '#/definitions/models.Response' - summary: Update country code of session user. tags: - users + /rankings: + get: + description: Get rankings of every player. + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/models.Response' + - properties: + data: + $ref: '#/definitions/models.RankingsResponse' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/models.Response' + tags: + - rankings /search: get: + description: Get all user and map data matching to the query. parameters: - description: Search user or map name. in: query @@ -725,11 +726,11 @@ paths: description: Bad Request schema: $ref: '#/definitions/models.Response' - summary: Get all user and map data matching to the query. tags: - search /token: delete: + description: Deletes the token cookie from the user. produces: - application/json responses: @@ -746,10 +747,10 @@ paths: description: Not Found schema: $ref: '#/definitions/models.Response' - summary: Deletes the token cookie from the user. tags: - auth get: + description: Gets the token cookie value from the user. produces: - application/json responses: @@ -766,13 +767,13 @@ paths: description: Not Found schema: $ref: '#/definitions/models.Response' - summary: Gets the token cookie value from the user. tags: - auth /users/{id}: get: consumes: - application/json + description: Get profile page of another user. parameters: - description: User ID in: path @@ -799,7 +800,6 @@ paths: description: Not Found schema: $ref: '#/definitions/models.Response' - summary: Get profile page of another user. tags: - users swagger: "2.0" -- cgit v1.2.3 From 311a039edc8f91666c8d05acd94aabab20833ffe Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Wed, 12 Jul 2023 14:26:24 +0300 Subject: feat: edit map image Former-commit-id: 288e6772dda69a9543a01db85069c95476addd4e --- backend/controllers/modController.go | 55 ++++++++++++++++++ backend/models/requests.go | 4 ++ backend/routes/routes.go | 1 + docs/docs.go | 104 ++++++++++++++++++++++++++++++++++- docs/swagger.json | 104 ++++++++++++++++++++++++++++++++++- docs/swagger.yaml | 63 ++++++++++++++++++++- 6 files changed, 328 insertions(+), 3 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/controllers/modController.go b/backend/controllers/modController.go index ff79e3e..98fb165 100644 --- a/backend/controllers/modController.go +++ b/backend/controllers/modController.go @@ -264,3 +264,58 @@ func DeleteMapSummary(c *gin.Context) { Data: request, }) } + +// PUT Map Image +// +// @Description Edit map image with specified map id. +// @Tags maps +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param id path int true "Map ID" +// @Param request body models.EditMapImageRequest true "Body" +// @Success 200 {object} models.Response{data=models.EditMapImageRequest} +// @Failure 400 {object} models.Response +// @Router /maps/{id}/image [put] +func EditMapImage(c *gin.Context) { + // Check if user exists + user, exists := c.Get("user") + if !exists { + c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + return + } + var moderator bool + for _, title := range user.(models.User).Titles { + if title == "Moderator" { + moderator = true + } + } + if !moderator { + c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) + return + } + // Bind parameter and body + id := c.Param("id") + mapID, err := strconv.Atoi(id) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + var request models.EditMapImageRequest + if err := c.BindJSON(&request); err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + // Update database with new data + sql := `UPDATE maps SET image = $2 WHERE id = $1` + _, err = database.DB.Exec(sql, mapID, request.Image) + if err != nil { + c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + return + } + // Return response + c.JSON(http.StatusOK, models.Response{ + Success: true, + Message: "Successfully updated map image.", + Data: request, + }) +} diff --git a/backend/models/requests.go b/backend/models/requests.go index f275203..fac05b6 100644 --- a/backend/models/requests.go +++ b/backend/models/requests.go @@ -27,6 +27,10 @@ type DeleteMapSummaryRequest struct { RouteID int `json:"route_id" binding:"required"` } +type EditMapImageRequest struct { + Image string `json:"image" binding:"required"` +} + type RecordRequest struct { HostDemo *multipart.FileHeader `json:"host_demo" form:"host_demo" binding:"required" swaggerignore:"true"` PartnerDemo *multipart.FileHeader `json:"partner_demo" form:"partner_demo" swaggerignore:"true"` diff --git a/backend/routes/routes.go b/backend/routes/routes.go index a39c8c4..1377d32 100644 --- a/backend/routes/routes.go +++ b/backend/routes/routes.go @@ -29,6 +29,7 @@ func InitRoutes(router *gin.Engine) { v1.POST("/maps/:id/summary", middleware.CheckAuth, controllers.CreateMapSummary) v1.PUT("/maps/:id/summary", middleware.CheckAuth, controllers.EditMapSummary) v1.DELETE("/maps/:id/summary", middleware.CheckAuth, controllers.DeleteMapSummary) + v1.PUT("/maps/:id/image", middleware.CheckAuth, controllers.EditMapImage) v1.GET("/maps/:id/leaderboards", controllers.FetchMapLeaderboards) v1.POST("/maps/:id/record", middleware.CheckAuth, controllers.CreateRecordWithDemo) v1.GET("/rankings", controllers.Rankings) diff --git a/docs/docs.go b/docs/docs.go index 57984f4..13d4cf6 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -229,6 +229,68 @@ const docTemplate = `{ } } }, + "/maps/{id}/image": { + "put": { + "description": "Edit map image with specified map id.", + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.EditMapImageRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.EditMapImageRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/maps/{id}/leaderboards": { "get": { "description": "Get map leaderboards with specified id.", @@ -344,7 +406,19 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/models.Response" + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.RecordResponse" + } + } + } + ] } }, "400": { @@ -1047,6 +1121,17 @@ const docTemplate = `{ } } }, + "models.EditMapImageRequest": { + "type": "object", + "required": [ + "image" + ], + "properties": { + "image": { + "type": "string" + } + } + }, "models.EditMapSummaryRequest": { "type": "object", "required": [ @@ -1084,6 +1169,9 @@ const docTemplate = `{ "id": { "type": "integer" }, + "is_coop": { + "type": "boolean" + }, "name": { "type": "string" } @@ -1112,6 +1200,9 @@ const docTemplate = `{ "image": { "type": "string" }, + "is_coop": { + "type": "boolean" + }, "map_name": { "type": "string" } @@ -1242,6 +1333,17 @@ const docTemplate = `{ } } }, + "models.RecordResponse": { + "type": "object", + "properties": { + "score_count": { + "type": "integer" + }, + "score_time": { + "type": "integer" + } + } + }, "models.Response": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index ef422ab..f644288 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -222,6 +222,68 @@ } } }, + "/maps/{id}/image": { + "put": { + "description": "Edit map image with specified map id.", + "produces": [ + "application/json" + ], + "tags": [ + "maps" + ], + "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Map ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Body", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.EditMapImageRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.EditMapImageRequest" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/maps/{id}/leaderboards": { "get": { "description": "Get map leaderboards with specified id.", @@ -337,7 +399,19 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/models.Response" + "allOf": [ + { + "$ref": "#/definitions/models.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.RecordResponse" + } + } + } + ] } }, "400": { @@ -1040,6 +1114,17 @@ } } }, + "models.EditMapImageRequest": { + "type": "object", + "required": [ + "image" + ], + "properties": { + "image": { + "type": "string" + } + } + }, "models.EditMapSummaryRequest": { "type": "object", "required": [ @@ -1077,6 +1162,9 @@ "id": { "type": "integer" }, + "is_coop": { + "type": "boolean" + }, "name": { "type": "string" } @@ -1105,6 +1193,9 @@ "image": { "type": "string" }, + "is_coop": { + "type": "boolean" + }, "map_name": { "type": "string" } @@ -1235,6 +1326,17 @@ } } }, + "models.RecordResponse": { + "type": "object", + "properties": { + "score_count": { + "type": "integer" + }, + "score_time": { + "type": "integer" + } + } + }, "models.Response": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 2fed413..3b706ea 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -61,6 +61,13 @@ definitions: required: - route_id type: object + models.EditMapImageRequest: + properties: + image: + type: string + required: + - image + type: object models.EditMapSummaryRequest: properties: description: @@ -87,6 +94,8 @@ definitions: properties: id: type: integer + is_coop: + type: boolean name: type: string type: object @@ -105,6 +114,8 @@ definitions: type: integer image: type: string + is_coop: + type: boolean map_name: type: string type: object @@ -189,6 +200,13 @@ definitions: $ref: '#/definitions/models.UserRanking' type: array type: object + models.RecordResponse: + properties: + score_count: + type: integer + score_time: + type: integer + type: object models.Response: properties: data: {} @@ -364,6 +382,44 @@ paths: $ref: '#/definitions/models.Response' tags: - login + /maps/{id}/image: + put: + description: Edit map image with specified map id. + parameters: + - description: JWT Token + in: header + name: Authorization + required: true + type: string + - description: Map ID + in: path + name: id + required: true + type: integer + - description: Body + in: body + name: request + required: true + schema: + $ref: '#/definitions/models.EditMapImageRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/models.Response' + - properties: + data: + $ref: '#/definitions/models.EditMapImageRequest' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/models.Response' + tags: + - maps /maps/{id}/leaderboards: get: description: Get map leaderboards with specified id. @@ -435,7 +491,12 @@ paths: "200": description: OK schema: - $ref: '#/definitions/models.Response' + allOf: + - $ref: '#/definitions/models.Response' + - properties: + data: + $ref: '#/definitions/models.RecordResponse' + type: object "400": description: Bad Request schema: -- cgit v1.2.3 From 5e8b4791a06c8fa00e56f4d043d25d00ef003c76 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Wed, 12 Jul 2023 18:44:40 +0300 Subject: fix: 0 score count / showcase not required (#47) Former-commit-id: 2a1cea87348e0af8d97512a46093bd38768257ef --- backend/models/requests.go | 8 ++++---- docs/docs.go | 2 -- docs/swagger.json | 2 -- docs/swagger.yaml | 2 -- 4 files changed, 4 insertions(+), 10 deletions(-) (limited to 'docs/docs.go') diff --git a/backend/models/requests.go b/backend/models/requests.go index fac05b6..0113597 100644 --- a/backend/models/requests.go +++ b/backend/models/requests.go @@ -8,18 +8,18 @@ import ( type CreateMapSummaryRequest struct { CategoryID int `json:"category_id" binding:"required"` Description string `json:"description" binding:"required"` - Showcase string `json:"showcase" binding:"required"` + Showcase string `json:"showcase"` UserName string `json:"user_name" binding:"required"` - ScoreCount int `json:"score_count" binding:"required"` + ScoreCount *int `json:"score_count" binding:"required"` RecordDate time.Time `json:"record_date" binding:"required"` } type EditMapSummaryRequest struct { RouteID int `json:"route_id" binding:"required"` Description string `json:"description" binding:"required"` - Showcase string `json:"showcase" binding:"required"` + Showcase string `json:"showcase"` UserName string `json:"user_name" binding:"required"` - ScoreCount int `json:"score_count" binding:"required"` + ScoreCount *int `json:"score_count" binding:"required"` RecordDate time.Time `json:"record_date" binding:"required"` } diff --git a/docs/docs.go b/docs/docs.go index 13d4cf6..423afad 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1086,7 +1086,6 @@ const docTemplate = `{ "description", "record_date", "score_count", - "showcase", "user_name" ], "properties": { @@ -1139,7 +1138,6 @@ const docTemplate = `{ "record_date", "route_id", "score_count", - "showcase", "user_name" ], "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index f644288..2e1a789 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1079,7 +1079,6 @@ "description", "record_date", "score_count", - "showcase", "user_name" ], "properties": { @@ -1132,7 +1131,6 @@ "record_date", "route_id", "score_count", - "showcase", "user_name" ], "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 3b706ea..7571073 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -51,7 +51,6 @@ definitions: - description - record_date - score_count - - showcase - user_name type: object models.DeleteMapSummaryRequest: @@ -87,7 +86,6 @@ definitions: - record_date - route_id - score_count - - showcase - user_name type: object models.Game: -- cgit v1.2.3