diff options
Diffstat (limited to '')
| -rw-r--r-- | backend/controllers/homeController.go | 10 | ||||
| -rw-r--r-- | backend/controllers/mapController.go | 22 | ||||
| -rw-r--r-- | backend/controllers/recordController.go | 12 | ||||
| -rw-r--r-- | backend/controllers/userController.go | 14 | ||||
| -rw-r--r-- | backend/middleware/auth.go | 2 | ||||
| -rw-r--r-- | backend/routes/routes.go | 4 | ||||
| -rw-r--r-- | docs/docs.go | 67 | ||||
| -rw-r--r-- | docs/swagger.json | 67 | ||||
| -rw-r--r-- | docs/swagger.yaml | 53 |
9 files changed, 140 insertions, 111 deletions
diff --git a/backend/controllers/homeController.go b/backend/controllers/homeController.go index 206e3ae..edb770f 100644 --- a/backend/controllers/homeController.go +++ b/backend/controllers/homeController.go | |||
| @@ -29,7 +29,7 @@ func Home(c *gin.Context) { | |||
| 29 | // @Failure 400 {object} models.Response | 29 | // @Failure 400 {object} models.Response |
| 30 | // @Router /demo [get] | 30 | // @Router /demo [get] |
| 31 | func Rankings(c *gin.Context) { | 31 | func Rankings(c *gin.Context) { |
| 32 | rows, err := database.DB.Query(`SELECT steam_id, user_name FROM users;`) | 32 | rows, err := database.DB.Query(`SELECT steam_id, user_name FROM users`) |
| 33 | if err != nil { | 33 | if err != nil { |
| 34 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 34 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 35 | return | 35 | return |
| @@ -46,7 +46,7 @@ func Rankings(c *gin.Context) { | |||
| 46 | // Getting all sp records for each user | 46 | // Getting all sp records for each user |
| 47 | var uniqueSingleUserRecords, totalSingleMaps int | 47 | var uniqueSingleUserRecords, totalSingleMaps int |
| 48 | sql := `SELECT COUNT(DISTINCT map_id), (SELECT COUNT(map_name) FROM maps | 48 | sql := `SELECT COUNT(DISTINCT map_id), (SELECT COUNT(map_name) FROM maps |
| 49 | WHERE is_coop = FALSE AND is_disabled = false) FROM records_sp WHERE user_id = $1;` | 49 | WHERE is_coop = FALSE AND is_disabled = false) FROM records_sp WHERE user_id = $1` |
| 50 | err = database.DB.QueryRow(sql, userID).Scan(&uniqueSingleUserRecords, &totalSingleMaps) | 50 | err = database.DB.QueryRow(sql, userID).Scan(&uniqueSingleUserRecords, &totalSingleMaps) |
| 51 | if err != nil { | 51 | if err != nil { |
| 52 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 52 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -57,7 +57,7 @@ func Rankings(c *gin.Context) { | |||
| 57 | var ranking models.UserRanking | 57 | var ranking models.UserRanking |
| 58 | ranking.UserID = userID | 58 | ranking.UserID = userID |
| 59 | ranking.UserName = username | 59 | ranking.UserName = username |
| 60 | sql := `SELECT DISTINCT map_id, score_count FROM records_sp WHERE user_id = $1 ORDER BY map_id, score_count;` | 60 | sql := `SELECT DISTINCT map_id, score_count FROM records_sp WHERE user_id = $1 ORDER BY map_id, score_count` |
| 61 | rows, err := database.DB.Query(sql, userID) | 61 | rows, err := database.DB.Query(sql, userID) |
| 62 | if err != nil { | 62 | if err != nil { |
| 63 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 63 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -80,7 +80,7 @@ func Rankings(c *gin.Context) { | |||
| 80 | // Getting all mp records for each user | 80 | // Getting all mp records for each user |
| 81 | var uniqueMultiUserRecords, totalMultiMaps int | 81 | var uniqueMultiUserRecords, totalMultiMaps int |
| 82 | sql = `SELECT COUNT(DISTINCT map_id), (SELECT COUNT(map_name) FROM maps | 82 | sql = `SELECT COUNT(DISTINCT map_id), (SELECT COUNT(map_name) FROM maps |
| 83 | WHERE is_coop = TRUE AND is_disabled = false) FROM records_mp WHERE host_id = $1 OR partner_id = $2;` | 83 | WHERE is_coop = TRUE AND is_disabled = false) FROM records_mp WHERE host_id = $1 OR partner_id = $2` |
| 84 | err = database.DB.QueryRow(sql, userID, userID).Scan(&uniqueMultiUserRecords, &totalMultiMaps) | 84 | err = database.DB.QueryRow(sql, userID, userID).Scan(&uniqueMultiUserRecords, &totalMultiMaps) |
| 85 | if err != nil { | 85 | if err != nil { |
| 86 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 86 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -91,7 +91,7 @@ func Rankings(c *gin.Context) { | |||
| 91 | var ranking models.UserRanking | 91 | var ranking models.UserRanking |
| 92 | ranking.UserID = userID | 92 | ranking.UserID = userID |
| 93 | ranking.UserName = username | 93 | ranking.UserName = username |
| 94 | sql := `SELECT DISTINCT map_id, score_count FROM records_mp WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id, score_count;` | 94 | sql := `SELECT DISTINCT map_id, score_count FROM records_mp WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id, score_count` |
| 95 | rows, err := database.DB.Query(sql, userID, userID) | 95 | rows, err := database.DB.Query(sql, userID, userID) |
| 96 | if err != nil { | 96 | if err != nil { |
| 97 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 97 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index 506daa2..d8783b7 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go | |||
| @@ -56,7 +56,7 @@ func FetchMapSummary(c *gin.Context) { | |||
| 56 | FROM maps m | 56 | FROM maps m |
| 57 | INNER JOIN games g ON m.game_id = g.id | 57 | INNER JOIN games g ON m.game_id = g.id |
| 58 | INNER JOIN chapters c ON m.chapter_id = c.id | 58 | INNER JOIN chapters c ON m.chapter_id = c.id |
| 59 | WHERE m.id = $1;` | 59 | WHERE m.id = $1` |
| 60 | // TODO: CategoryScores | 60 | // TODO: CategoryScores |
| 61 | err = database.DB.QueryRow(sql, id).Scan(&mapData.GameName, &mapData.ChapterName, &mapData.MapName, &mapSummaryData.Description, &mapSummaryData.Showcase, &routers, &mapSummaryData.Rating) | 61 | err = database.DB.QueryRow(sql, id).Scan(&mapData.GameName, &mapData.ChapterName, &mapData.MapName, &mapSummaryData.Description, &mapSummaryData.Showcase, &routers, &mapSummaryData.Rating) |
| 62 | if err != nil { | 62 | if err != nil { |
| @@ -68,7 +68,7 @@ func FetchMapSummary(c *gin.Context) { | |||
| 68 | var historyDates pq.StringArray | 68 | var historyDates pq.StringArray |
| 69 | sql = `SELECT array_agg(user_name), array_agg(score_count), array_agg(record_date) | 69 | sql = `SELECT array_agg(user_name), array_agg(score_count), array_agg(record_date) |
| 70 | FROM map_history | 70 | FROM map_history |
| 71 | WHERE map_id = $1;` | 71 | WHERE map_id = $1` |
| 72 | err = database.DB.QueryRow(sql, id).Scan(&historyNames, &historyScores, &historyDates) | 72 | err = database.DB.QueryRow(sql, id).Scan(&historyNames, &historyScores, &historyDates) |
| 73 | if err != nil { | 73 | if err != nil { |
| 74 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 74 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -123,7 +123,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 123 | FROM maps m | 123 | FROM maps m |
| 124 | INNER JOIN games g ON m.game_id = g.id | 124 | INNER JOIN games g ON m.game_id = g.id |
| 125 | INNER JOIN chapters c ON m.chapter_id = c.id | 125 | INNER JOIN chapters c ON m.chapter_id = c.id |
| 126 | WHERE m.id = $1;` | 126 | WHERE m.id = $1` |
| 127 | err = database.DB.QueryRow(sql, id).Scan(&mapData.GameName, &mapData.ChapterName, &mapData.MapName, &isDisabled) | 127 | err = database.DB.QueryRow(sql, id).Scan(&mapData.GameName, &mapData.ChapterName, &mapData.MapName, &isDisabled) |
| 128 | if err != nil { | 128 | if err != nil { |
| 129 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 129 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -144,7 +144,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 144 | FROM records_mp | 144 | FROM records_mp |
| 145 | WHERE map_id = $1 | 145 | WHERE map_id = $1 |
| 146 | ) sub | 146 | ) sub |
| 147 | WHERE rn = 1;` | 147 | WHERE rn = 1` |
| 148 | rows, err := database.DB.Query(sql, id) | 148 | rows, err := database.DB.Query(sql, id) |
| 149 | if err != nil { | 149 | if err != nil { |
| 150 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 150 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -179,7 +179,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 179 | WHERE map_id = $1 | 179 | WHERE map_id = $1 |
| 180 | ) sub | 180 | ) sub |
| 181 | INNER JOIN users ON user_id = users.steam_id | 181 | INNER JOIN users ON user_id = users.steam_id |
| 182 | WHERE rn = 1;` | 182 | WHERE rn = 1` |
| 183 | rows, err := database.DB.Query(sql, id) | 183 | rows, err := database.DB.Query(sql, id) |
| 184 | if err != nil { | 184 | if err != nil { |
| 185 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 185 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -217,7 +217,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 217 | // GET Games | 217 | // GET Games |
| 218 | // | 218 | // |
| 219 | // @Summary Get games from the leaderboards. | 219 | // @Summary Get games from the leaderboards. |
| 220 | // @Tags games | 220 | // @Tags games & chapters |
| 221 | // @Produce json | 221 | // @Produce json |
| 222 | // @Success 200 {object} models.Response{data=[]models.Game} | 222 | // @Success 200 {object} models.Response{data=[]models.Game} |
| 223 | // @Failure 400 {object} models.Response | 223 | // @Failure 400 {object} models.Response |
| @@ -247,12 +247,12 @@ func FetchGames(c *gin.Context) { | |||
| 247 | // GET Chapters of a Game | 247 | // GET Chapters of a Game |
| 248 | // | 248 | // |
| 249 | // @Summary Get chapters from the specified game id. | 249 | // @Summary Get chapters from the specified game id. |
| 250 | // @Tags chapters | 250 | // @Tags games & chapters |
| 251 | // @Produce json | 251 | // @Produce json |
| 252 | // @Param id path int true "Game ID" | 252 | // @Param id path int true "Game ID" |
| 253 | // @Success 200 {object} models.Response{data=models.ChaptersResponse} | 253 | // @Success 200 {object} models.Response{data=models.ChaptersResponse} |
| 254 | // @Failure 400 {object} models.Response | 254 | // @Failure 400 {object} models.Response |
| 255 | // @Router /chapters/{id} [get] | 255 | // @Router /games/{id} [get] |
| 256 | func FetchChapters(c *gin.Context) { | 256 | func FetchChapters(c *gin.Context) { |
| 257 | gameID := c.Param("id") | 257 | gameID := c.Param("id") |
| 258 | intID, err := strconv.Atoi(gameID) | 258 | intID, err := strconv.Atoi(gameID) |
| @@ -289,12 +289,12 @@ func FetchChapters(c *gin.Context) { | |||
| 289 | // GET Maps of a Chapter | 289 | // GET Maps of a Chapter |
| 290 | // | 290 | // |
| 291 | // @Summary Get maps from the specified chapter id. | 291 | // @Summary Get maps from the specified chapter id. |
| 292 | // @Tags maps | 292 | // @Tags games & chapters |
| 293 | // @Produce json | 293 | // @Produce json |
| 294 | // @Param id path int true "Chapter ID" | 294 | // @Param id path int true "Chapter ID" |
| 295 | // @Success 200 {object} models.Response{data=[]models.MapShort} | 295 | // @Success 200 {object} models.Response{data=models.ChapterMapsResponse} |
| 296 | // @Failure 400 {object} models.Response | 296 | // @Failure 400 {object} models.Response |
| 297 | // @Router /maps/{id} [get] | 297 | // @Router /chapters/{id} [get] |
| 298 | func FetchChapterMaps(c *gin.Context) { | 298 | func FetchChapterMaps(c *gin.Context) { |
| 299 | chapterID := c.Param("id") | 299 | chapterID := c.Param("id") |
| 300 | intID, err := strconv.Atoi(chapterID) | 300 | intID, err := strconv.Atoi(chapterID) |
diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index bafa844..627be57 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go | |||
| @@ -46,7 +46,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 46 | var gameID int | 46 | var gameID int |
| 47 | var isCoop bool | 47 | var isCoop bool |
| 48 | var isDisabled bool | 48 | var isDisabled bool |
| 49 | sql := `SELECT game_id, is_disabled FROM maps WHERE id = $1;` | 49 | sql := `SELECT game_id, is_disabled FROM maps WHERE id = $1` |
| 50 | err := database.DB.QueryRow(sql, mapId).Scan(&gameID, &isDisabled) | 50 | err := database.DB.QueryRow(sql, mapId).Scan(&gameID, &isDisabled) |
| 51 | if err != nil { | 51 | if err != nil { |
| 52 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 52 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -153,7 +153,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 153 | // Insert into records | 153 | // Insert into records |
| 154 | if isCoop { | 154 | if isCoop { |
| 155 | sql := `INSERT INTO records_mp(map_id,score_count,score_time,host_id,partner_id,host_demo_id,partner_demo_id) | 155 | sql := `INSERT INTO records_mp(map_id,score_count,score_time,host_id,partner_id,host_demo_id,partner_demo_id) |
| 156 | VALUES($1, $2, $3, $4, $5, $6, $7);` | 156 | VALUES($1, $2, $3, $4, $5, $6, $7)` |
| 157 | var hostID string | 157 | var hostID string |
| 158 | var partnerID string | 158 | var partnerID string |
| 159 | if record.IsPartnerOrange { | 159 | if record.IsPartnerOrange { |
| @@ -171,7 +171,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 171 | } | 171 | } |
| 172 | // If a new world record based on portal count | 172 | // If a new world record based on portal count |
| 173 | // if record.ScoreCount < wrScore { | 173 | // if record.ScoreCount < wrScore { |
| 174 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) | 174 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) |
| 175 | // if err != nil { | 175 | // if err != nil { |
| 176 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 176 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 177 | // return | 177 | // return |
| @@ -179,7 +179,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 179 | // } | 179 | // } |
| 180 | } else { | 180 | } else { |
| 181 | sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) | 181 | sql := `INSERT INTO records_sp(map_id,score_count,score_time,user_id,demo_id) |
| 182 | VALUES($1, $2, $3, $4, $5);` | 182 | VALUES($1, $2, $3, $4, $5)` |
| 183 | _, err := tx.Exec(sql, mapId, record.ScoreCount, record.ScoreTime, user.(models.User).SteamID, hostDemoUUID) | 183 | _, err := tx.Exec(sql, mapId, record.ScoreCount, record.ScoreTime, user.(models.User).SteamID, hostDemoUUID) |
| 184 | if err != nil { | 184 | if err != nil { |
| 185 | deleteFile(srv, fileID) | 185 | deleteFile(srv, fileID) |
| @@ -188,7 +188,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 188 | } | 188 | } |
| 189 | // If a new world record based on portal count | 189 | // If a new world record based on portal count |
| 190 | // if record.ScoreCount < wrScore { | 190 | // if record.ScoreCount < wrScore { |
| 191 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3;`, record.ScoreCount, record.ScoreTime, mapId) | 191 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) |
| 192 | // if err != nil { | 192 | // if err != nil { |
| 193 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 193 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 194 | // return | 194 | // return |
| @@ -224,7 +224,7 @@ func DownloadDemoWithID(c *gin.Context) { | |||
| 224 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid id given.")) | 224 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid id given.")) |
| 225 | return | 225 | return |
| 226 | } | 226 | } |
| 227 | err := database.DB.QueryRow(`SELECT location_id FROM demos WHERE id = $1;`, uuid).Scan(&locationID) | 227 | err := database.DB.QueryRow(`SELECT location_id FROM demos WHERE id = $1`, uuid).Scan(&locationID) |
| 228 | if err != nil { | 228 | if err != nil { |
| 229 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 229 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 230 | return | 230 | return |
diff --git a/backend/controllers/userController.go b/backend/controllers/userController.go index 5ad800d..adf936b 100644 --- a/backend/controllers/userController.go +++ b/backend/controllers/userController.go | |||
| @@ -31,7 +31,7 @@ func Profile(c *gin.Context) { | |||
| 31 | } | 31 | } |
| 32 | // Retrieve singleplayer records | 32 | // Retrieve singleplayer records |
| 33 | var scoresSP []models.ScoreResponse | 33 | var scoresSP []models.ScoreResponse |
| 34 | sql := `SELECT id, map_id, score_count, score_time, demo_id, record_date FROM records_sp WHERE user_id = $1 ORDER BY map_id;` | 34 | sql := `SELECT id, map_id, score_count, score_time, demo_id, record_date FROM records_sp WHERE user_id = $1 ORDER BY map_id` |
| 35 | rows, err := database.DB.Query(sql, user.(models.User).SteamID) | 35 | rows, err := database.DB.Query(sql, user.(models.User).SteamID) |
| 36 | if err != nil { | 36 | if err != nil { |
| 37 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 37 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -58,7 +58,7 @@ func Profile(c *gin.Context) { | |||
| 58 | // Retrieve multiplayer records | 58 | // Retrieve multiplayer records |
| 59 | var scoresMP []models.ScoreResponse | 59 | var scoresMP []models.ScoreResponse |
| 60 | sql = `SELECT id, map_id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date FROM records_mp | 60 | sql = `SELECT id, map_id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date FROM records_mp |
| 61 | WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id;` | 61 | WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id` |
| 62 | rows, err = database.DB.Query(sql, user.(models.User).SteamID, user.(models.User).SteamID) | 62 | rows, err = database.DB.Query(sql, user.(models.User).SteamID, user.(models.User).SteamID) |
| 63 | if err != nil { | 63 | if err != nil { |
| 64 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 64 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -119,7 +119,7 @@ func FetchUser(c *gin.Context) { | |||
| 119 | } | 119 | } |
| 120 | // Check if user exists | 120 | // Check if user exists |
| 121 | var user models.User | 121 | var user models.User |
| 122 | err := database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, id).Scan( | 122 | err := database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1`, id).Scan( |
| 123 | &user.SteamID, &user.UserName, &user.AvatarLink, &user.CountryCode, | 123 | &user.SteamID, &user.UserName, &user.AvatarLink, &user.CountryCode, |
| 124 | &user.CreatedAt, &user.UpdatedAt) | 124 | &user.CreatedAt, &user.UpdatedAt) |
| 125 | if user.SteamID == "" { | 125 | if user.SteamID == "" { |
| @@ -133,7 +133,7 @@ func FetchUser(c *gin.Context) { | |||
| 133 | } | 133 | } |
| 134 | // Retrieve singleplayer records | 134 | // Retrieve singleplayer records |
| 135 | var scoresSP []models.ScoreResponse | 135 | var scoresSP []models.ScoreResponse |
| 136 | sql := `SELECT id, map_id, score_count, score_time, demo_id, record_date FROM records_sp WHERE user_id = $1 ORDER BY map_id;` | 136 | sql := `SELECT id, map_id, score_count, score_time, demo_id, record_date FROM records_sp WHERE user_id = $1 ORDER BY map_id` |
| 137 | rows, err := database.DB.Query(sql, user.SteamID) | 137 | rows, err := database.DB.Query(sql, user.SteamID) |
| 138 | if err != nil { | 138 | if err != nil { |
| 139 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 139 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -160,7 +160,7 @@ func FetchUser(c *gin.Context) { | |||
| 160 | // Retrieve multiplayer records | 160 | // Retrieve multiplayer records |
| 161 | var scoresMP []models.ScoreResponse | 161 | var scoresMP []models.ScoreResponse |
| 162 | sql = `SELECT id, map_id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date FROM records_mp | 162 | sql = `SELECT id, map_id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date FROM records_mp |
| 163 | WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id;` | 163 | WHERE host_id = $1 OR partner_id = $2 ORDER BY map_id` |
| 164 | rows, err = database.DB.Query(sql, user.SteamID, user.SteamID) | 164 | rows, err = database.DB.Query(sql, user.SteamID, user.SteamID) |
| 165 | if err != nil { | 165 | if err != nil { |
| 166 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 166 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -225,7 +225,7 @@ func UpdateUser(c *gin.Context) { | |||
| 225 | } | 225 | } |
| 226 | // Update profile | 226 | // Update profile |
| 227 | _, err = database.DB.Exec(`UPDATE users SET username = $1, avatar_link = $2, country_code = $3, updated_at = $4 | 227 | _, err = database.DB.Exec(`UPDATE users SET username = $1, avatar_link = $2, country_code = $3, updated_at = $4 |
| 228 | WHERE steam_id = $5;`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) | 228 | WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) |
| 229 | if err != nil { | 229 | if err != nil { |
| 230 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 230 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 231 | return | 231 | return |
| @@ -268,7 +268,7 @@ func UpdateCountryCode(c *gin.Context) { | |||
| 268 | return | 268 | return |
| 269 | } | 269 | } |
| 270 | var validCode string | 270 | var validCode string |
| 271 | err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1;`, code).Scan(&validCode) | 271 | err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1`, code).Scan(&validCode) |
| 272 | if err != nil { | 272 | if err != nil { |
| 273 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) | 273 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) |
| 274 | return | 274 | return |
diff --git a/backend/middleware/auth.go b/backend/middleware/auth.go index cd00a30..14a0b78 100644 --- a/backend/middleware/auth.go +++ b/backend/middleware/auth.go | |||
| @@ -36,7 +36,7 @@ func CheckAuth(c *gin.Context) { | |||
| 36 | } | 36 | } |
| 37 | // Get user from DB | 37 | // Get user from DB |
| 38 | var user models.User | 38 | var user models.User |
| 39 | database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1;`, claims["sub"]).Scan( | 39 | database.DB.QueryRow(`SELECT * FROM users WHERE steam_id = $1`, claims["sub"]).Scan( |
| 40 | &user.SteamID, &user.UserName, &user.AvatarLink, | 40 | &user.SteamID, &user.UserName, &user.AvatarLink, |
| 41 | &user.CountryCode, &user.CreatedAt, &user.UpdatedAt) | 41 | &user.CountryCode, &user.CreatedAt, &user.UpdatedAt) |
| 42 | if user.SteamID == "" { | 42 | if user.SteamID == "" { |
diff --git a/backend/routes/routes.go b/backend/routes/routes.go index 2741208..2554fa4 100644 --- a/backend/routes/routes.go +++ b/backend/routes/routes.go | |||
| @@ -26,10 +26,10 @@ func InitRoutes(router *gin.Engine) { | |||
| 26 | v1.GET("/maps/:id/summary", middleware.CheckAuth, controllers.FetchMapSummary) | 26 | v1.GET("/maps/:id/summary", middleware.CheckAuth, controllers.FetchMapSummary) |
| 27 | v1.GET("/maps/:id/leaderboards", middleware.CheckAuth, controllers.FetchMapLeaderboards) | 27 | v1.GET("/maps/:id/leaderboards", middleware.CheckAuth, controllers.FetchMapLeaderboards) |
| 28 | v1.POST("/maps/:id/record", middleware.CheckAuth, controllers.CreateRecordWithDemo) | 28 | v1.POST("/maps/:id/record", middleware.CheckAuth, controllers.CreateRecordWithDemo) |
| 29 | v1.GET("/maps/:id", controllers.FetchChapterMaps) | ||
| 30 | v1.GET("/rankings", middleware.CheckAuth, controllers.Rankings) | 29 | v1.GET("/rankings", middleware.CheckAuth, controllers.Rankings) |
| 31 | v1.GET("/search", controllers.Search) | 30 | v1.GET("/search", controllers.Search) |
| 32 | v1.GET("/games", controllers.FetchGames) | 31 | v1.GET("/games", controllers.FetchGames) |
| 33 | v1.GET("/chapters/:id", controllers.FetchChapters) | 32 | v1.GET("/games/:id", controllers.FetchChapters) |
| 33 | v1.GET("/chapters/:id", controllers.FetchChapterMaps) | ||
| 34 | } | 34 | } |
| 35 | } | 35 | } |
diff --git a/docs/docs.go b/docs/docs.go index 164db20..cd129f0 100644 --- a/docs/docs.go +++ b/docs/docs.go | |||
| @@ -26,13 +26,13 @@ const docTemplate = `{ | |||
| 26 | "application/json" | 26 | "application/json" |
| 27 | ], | 27 | ], |
| 28 | "tags": [ | 28 | "tags": [ |
| 29 | "chapters" | 29 | "games \u0026 chapters" |
| 30 | ], | 30 | ], |
| 31 | "summary": "Get chapters from the specified game id.", | 31 | "summary": "Get maps from the specified chapter id.", |
| 32 | "parameters": [ | 32 | "parameters": [ |
| 33 | { | 33 | { |
| 34 | "type": "integer", | 34 | "type": "integer", |
| 35 | "description": "Game ID", | 35 | "description": "Chapter ID", |
| 36 | "name": "id", | 36 | "name": "id", |
| 37 | "in": "path", | 37 | "in": "path", |
| 38 | "required": true | 38 | "required": true |
| @@ -50,7 +50,7 @@ const docTemplate = `{ | |||
| 50 | "type": "object", | 50 | "type": "object", |
| 51 | "properties": { | 51 | "properties": { |
| 52 | "data": { | 52 | "data": { |
| 53 | "$ref": "#/definitions/models.ChaptersResponse" | 53 | "$ref": "#/definitions/models.ChapterMapsResponse" |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| @@ -146,7 +146,7 @@ const docTemplate = `{ | |||
| 146 | "application/json" | 146 | "application/json" |
| 147 | ], | 147 | ], |
| 148 | "tags": [ | 148 | "tags": [ |
| 149 | "games" | 149 | "games \u0026 chapters" |
| 150 | ], | 150 | ], |
| 151 | "summary": "Get games from the leaderboards.", | 151 | "summary": "Get games from the leaderboards.", |
| 152 | "responses": { | 152 | "responses": { |
| @@ -180,18 +180,24 @@ const docTemplate = `{ | |||
| 180 | } | 180 | } |
| 181 | } | 181 | } |
| 182 | }, | 182 | }, |
| 183 | "/login": { | 183 | "/games/{id}": { |
| 184 | "get": { | 184 | "get": { |
| 185 | "consumes": [ | ||
| 186 | "application/json" | ||
| 187 | ], | ||
| 188 | "produces": [ | 185 | "produces": [ |
| 189 | "application/json" | 186 | "application/json" |
| 190 | ], | 187 | ], |
| 191 | "tags": [ | 188 | "tags": [ |
| 192 | "login" | 189 | "games \u0026 chapters" |
| 190 | ], | ||
| 191 | "summary": "Get chapters from the specified game id.", | ||
| 192 | "parameters": [ | ||
| 193 | { | ||
| 194 | "type": "integer", | ||
| 195 | "description": "Game ID", | ||
| 196 | "name": "id", | ||
| 197 | "in": "path", | ||
| 198 | "required": true | ||
| 199 | } | ||
| 193 | ], | 200 | ], |
| 194 | "summary": "Get (redirect) login page for Steam auth.", | ||
| 195 | "responses": { | 201 | "responses": { |
| 196 | "200": { | 202 | "200": { |
| 197 | "description": "OK", | 203 | "description": "OK", |
| @@ -204,7 +210,7 @@ const docTemplate = `{ | |||
| 204 | "type": "object", | 210 | "type": "object", |
| 205 | "properties": { | 211 | "properties": { |
| 206 | "data": { | 212 | "data": { |
| 207 | "$ref": "#/definitions/models.LoginResponse" | 213 | "$ref": "#/definitions/models.ChaptersResponse" |
| 208 | } | 214 | } |
| 209 | } | 215 | } |
| 210 | } | 216 | } |
| @@ -220,24 +226,18 @@ const docTemplate = `{ | |||
| 220 | } | 226 | } |
| 221 | } | 227 | } |
| 222 | }, | 228 | }, |
| 223 | "/maps/{id}": { | 229 | "/login": { |
| 224 | "get": { | 230 | "get": { |
| 231 | "consumes": [ | ||
| 232 | "application/json" | ||
| 233 | ], | ||
| 225 | "produces": [ | 234 | "produces": [ |
| 226 | "application/json" | 235 | "application/json" |
| 227 | ], | 236 | ], |
| 228 | "tags": [ | 237 | "tags": [ |
| 229 | "maps" | 238 | "login" |
| 230 | ], | ||
| 231 | "summary": "Get maps from the specified chapter id.", | ||
| 232 | "parameters": [ | ||
| 233 | { | ||
| 234 | "type": "integer", | ||
| 235 | "description": "Chapter ID", | ||
| 236 | "name": "id", | ||
| 237 | "in": "path", | ||
| 238 | "required": true | ||
| 239 | } | ||
| 240 | ], | 239 | ], |
| 240 | "summary": "Get (redirect) login page for Steam auth.", | ||
| 241 | "responses": { | 241 | "responses": { |
| 242 | "200": { | 242 | "200": { |
| 243 | "description": "OK", | 243 | "description": "OK", |
| @@ -250,10 +250,7 @@ const docTemplate = `{ | |||
| 250 | "type": "object", | 250 | "type": "object", |
| 251 | "properties": { | 251 | "properties": { |
| 252 | "data": { | 252 | "data": { |
| 253 | "type": "array", | 253 | "$ref": "#/definitions/models.LoginResponse" |
| 254 | "items": { | ||
| 255 | "$ref": "#/definitions/models.MapShort" | ||
| 256 | } | ||
| 257 | } | 254 | } |
| 258 | } | 255 | } |
| 259 | } | 256 | } |
| @@ -751,6 +748,20 @@ const docTemplate = `{ | |||
| 751 | } | 748 | } |
| 752 | } | 749 | } |
| 753 | }, | 750 | }, |
| 751 | "models.ChapterMapsResponse": { | ||
| 752 | "type": "object", | ||
| 753 | "properties": { | ||
| 754 | "chapter": { | ||
| 755 | "$ref": "#/definitions/models.Chapter" | ||
| 756 | }, | ||
| 757 | "maps": { | ||
| 758 | "type": "array", | ||
| 759 | "items": { | ||
| 760 | "$ref": "#/definitions/models.MapShort" | ||
| 761 | } | ||
| 762 | } | ||
| 763 | } | ||
| 764 | }, | ||
| 754 | "models.ChaptersResponse": { | 765 | "models.ChaptersResponse": { |
| 755 | "type": "object", | 766 | "type": "object", |
| 756 | "properties": { | 767 | "properties": { |
diff --git a/docs/swagger.json b/docs/swagger.json index 653d52f..442745f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json | |||
| @@ -19,13 +19,13 @@ | |||
| 19 | "application/json" | 19 | "application/json" |
| 20 | ], | 20 | ], |
| 21 | "tags": [ | 21 | "tags": [ |
| 22 | "chapters" | 22 | "games \u0026 chapters" |
| 23 | ], | 23 | ], |
| 24 | "summary": "Get chapters from the specified game id.", | 24 | "summary": "Get maps from the specified chapter id.", |
| 25 | "parameters": [ | 25 | "parameters": [ |
| 26 | { | 26 | { |
| 27 | "type": "integer", | 27 | "type": "integer", |
| 28 | "description": "Game ID", | 28 | "description": "Chapter ID", |
| 29 | "name": "id", | 29 | "name": "id", |
| 30 | "in": "path", | 30 | "in": "path", |
| 31 | "required": true | 31 | "required": true |
| @@ -43,7 +43,7 @@ | |||
| 43 | "type": "object", | 43 | "type": "object", |
| 44 | "properties": { | 44 | "properties": { |
| 45 | "data": { | 45 | "data": { |
| 46 | "$ref": "#/definitions/models.ChaptersResponse" | 46 | "$ref": "#/definitions/models.ChapterMapsResponse" |
| 47 | } | 47 | } |
| 48 | } | 48 | } |
| 49 | } | 49 | } |
| @@ -139,7 +139,7 @@ | |||
| 139 | "application/json" | 139 | "application/json" |
| 140 | ], | 140 | ], |
| 141 | "tags": [ | 141 | "tags": [ |
| 142 | "games" | 142 | "games \u0026 chapters" |
| 143 | ], | 143 | ], |
| 144 | "summary": "Get games from the leaderboards.", | 144 | "summary": "Get games from the leaderboards.", |
| 145 | "responses": { | 145 | "responses": { |
| @@ -173,18 +173,24 @@ | |||
| 173 | } | 173 | } |
| 174 | } | 174 | } |
| 175 | }, | 175 | }, |
| 176 | "/login": { | 176 | "/games/{id}": { |
| 177 | "get": { | 177 | "get": { |
| 178 | "consumes": [ | ||
| 179 | "application/json" | ||
| 180 | ], | ||
| 181 | "produces": [ | 178 | "produces": [ |
| 182 | "application/json" | 179 | "application/json" |
| 183 | ], | 180 | ], |
| 184 | "tags": [ | 181 | "tags": [ |
| 185 | "login" | 182 | "games \u0026 chapters" |
| 183 | ], | ||
| 184 | "summary": "Get chapters from the specified game id.", | ||
| 185 | "parameters": [ | ||
| 186 | { | ||
| 187 | "type": "integer", | ||
| 188 | "description": "Game ID", | ||
| 189 | "name": "id", | ||
| 190 | "in": "path", | ||
| 191 | "required": true | ||
| 192 | } | ||
| 186 | ], | 193 | ], |
| 187 | "summary": "Get (redirect) login page for Steam auth.", | ||
| 188 | "responses": { | 194 | "responses": { |
| 189 | "200": { | 195 | "200": { |
| 190 | "description": "OK", | 196 | "description": "OK", |
| @@ -197,7 +203,7 @@ | |||
| 197 | "type": "object", | 203 | "type": "object", |
| 198 | "properties": { | 204 | "properties": { |
| 199 | "data": { | 205 | "data": { |
| 200 | "$ref": "#/definitions/models.LoginResponse" | 206 | "$ref": "#/definitions/models.ChaptersResponse" |
| 201 | } | 207 | } |
| 202 | } | 208 | } |
| 203 | } | 209 | } |
| @@ -213,24 +219,18 @@ | |||
| 213 | } | 219 | } |
| 214 | } | 220 | } |
| 215 | }, | 221 | }, |
| 216 | "/maps/{id}": { | 222 | "/login": { |
| 217 | "get": { | 223 | "get": { |
| 224 | "consumes": [ | ||
| 225 | "application/json" | ||
| 226 | ], | ||
| 218 | "produces": [ | 227 | "produces": [ |
| 219 | "application/json" | 228 | "application/json" |
| 220 | ], | 229 | ], |
| 221 | "tags": [ | 230 | "tags": [ |
| 222 | "maps" | 231 | "login" |
| 223 | ], | ||
| 224 | "summary": "Get maps from the specified chapter id.", | ||
| 225 | "parameters": [ | ||
| 226 | { | ||
| 227 | "type": "integer", | ||
| 228 | "description": "Chapter ID", | ||
| 229 | "name": "id", | ||
| 230 | "in": "path", | ||
| 231 | "required": true | ||
| 232 | } | ||
| 233 | ], | 232 | ], |
| 233 | "summary": "Get (redirect) login page for Steam auth.", | ||
| 234 | "responses": { | 234 | "responses": { |
| 235 | "200": { | 235 | "200": { |
| 236 | "description": "OK", | 236 | "description": "OK", |
| @@ -243,10 +243,7 @@ | |||
| 243 | "type": "object", | 243 | "type": "object", |
| 244 | "properties": { | 244 | "properties": { |
| 245 | "data": { | 245 | "data": { |
| 246 | "type": "array", | 246 | "$ref": "#/definitions/models.LoginResponse" |
| 247 | "items": { | ||
| 248 | "$ref": "#/definitions/models.MapShort" | ||
| 249 | } | ||
| 250 | } | 247 | } |
| 251 | } | 248 | } |
| 252 | } | 249 | } |
| @@ -744,6 +741,20 @@ | |||
| 744 | } | 741 | } |
| 745 | } | 742 | } |
| 746 | }, | 743 | }, |
| 744 | "models.ChapterMapsResponse": { | ||
| 745 | "type": "object", | ||
| 746 | "properties": { | ||
| 747 | "chapter": { | ||
| 748 | "$ref": "#/definitions/models.Chapter" | ||
| 749 | }, | ||
| 750 | "maps": { | ||
| 751 | "type": "array", | ||
| 752 | "items": { | ||
| 753 | "$ref": "#/definitions/models.MapShort" | ||
| 754 | } | ||
| 755 | } | ||
| 756 | } | ||
| 757 | }, | ||
| 747 | "models.ChaptersResponse": { | 758 | "models.ChaptersResponse": { |
| 748 | "type": "object", | 759 | "type": "object", |
| 749 | "properties": { | 760 | "properties": { |
diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 88f2d7f..fa1a26d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml | |||
| @@ -7,6 +7,15 @@ definitions: | |||
| 7 | name: | 7 | name: |
| 8 | type: string | 8 | type: string |
| 9 | type: object | 9 | type: object |
| 10 | models.ChapterMapsResponse: | ||
| 11 | properties: | ||
| 12 | chapter: | ||
| 13 | $ref: '#/definitions/models.Chapter' | ||
| 14 | maps: | ||
| 15 | items: | ||
| 16 | $ref: '#/definitions/models.MapShort' | ||
| 17 | type: array | ||
| 18 | type: object | ||
| 10 | models.ChaptersResponse: | 19 | models.ChaptersResponse: |
| 11 | properties: | 20 | properties: |
| 12 | chapters: | 21 | chapters: |
| @@ -195,7 +204,7 @@ paths: | |||
| 195 | /chapters/{id}: | 204 | /chapters/{id}: |
| 196 | get: | 205 | get: |
| 197 | parameters: | 206 | parameters: |
| 198 | - description: Game ID | 207 | - description: Chapter ID |
| 199 | in: path | 208 | in: path |
| 200 | name: id | 209 | name: id |
| 201 | required: true | 210 | required: true |
| @@ -210,15 +219,15 @@ paths: | |||
| 210 | - $ref: '#/definitions/models.Response' | 219 | - $ref: '#/definitions/models.Response' |
| 211 | - properties: | 220 | - properties: |
| 212 | data: | 221 | data: |
| 213 | $ref: '#/definitions/models.ChaptersResponse' | 222 | $ref: '#/definitions/models.ChapterMapsResponse' |
| 214 | type: object | 223 | type: object |
| 215 | "400": | 224 | "400": |
| 216 | description: Bad Request | 225 | description: Bad Request |
| 217 | schema: | 226 | schema: |
| 218 | $ref: '#/definitions/models.Response' | 227 | $ref: '#/definitions/models.Response' |
| 219 | summary: Get chapters from the specified game id. | 228 | summary: Get maps from the specified chapter id. |
| 220 | tags: | 229 | tags: |
| 221 | - chapters | 230 | - games & chapters |
| 222 | /demo: | 231 | /demo: |
| 223 | get: | 232 | get: |
| 224 | produces: | 233 | produces: |
| @@ -286,11 +295,15 @@ paths: | |||
| 286 | $ref: '#/definitions/models.Response' | 295 | $ref: '#/definitions/models.Response' |
| 287 | summary: Get games from the leaderboards. | 296 | summary: Get games from the leaderboards. |
| 288 | tags: | 297 | tags: |
| 289 | - games | 298 | - games & chapters |
| 290 | /login: | 299 | /games/{id}: |
| 291 | get: | 300 | get: |
| 292 | consumes: | 301 | parameters: |
| 293 | - application/json | 302 | - description: Game ID |
| 303 | in: path | ||
| 304 | name: id | ||
| 305 | required: true | ||
| 306 | type: integer | ||
| 294 | produces: | 307 | produces: |
| 295 | - application/json | 308 | - application/json |
| 296 | responses: | 309 | responses: |
| @@ -301,23 +314,19 @@ paths: | |||
| 301 | - $ref: '#/definitions/models.Response' | 314 | - $ref: '#/definitions/models.Response' |
| 302 | - properties: | 315 | - properties: |
| 303 | data: | 316 | data: |
| 304 | $ref: '#/definitions/models.LoginResponse' | 317 | $ref: '#/definitions/models.ChaptersResponse' |
| 305 | type: object | 318 | type: object |
| 306 | "400": | 319 | "400": |
| 307 | description: Bad Request | 320 | description: Bad Request |
| 308 | schema: | 321 | schema: |
| 309 | $ref: '#/definitions/models.Response' | 322 | $ref: '#/definitions/models.Response' |
| 310 | summary: Get (redirect) login page for Steam auth. | 323 | summary: Get chapters from the specified game id. |
| 311 | tags: | 324 | tags: |
| 312 | - login | 325 | - games & chapters |
| 313 | /maps/{id}: | 326 | /login: |
| 314 | get: | 327 | get: |
| 315 | parameters: | 328 | consumes: |
| 316 | - description: Chapter ID | 329 | - application/json |
| 317 | in: path | ||
| 318 | name: id | ||
| 319 | required: true | ||
| 320 | type: integer | ||
| 321 | produces: | 330 | produces: |
| 322 | - application/json | 331 | - application/json |
| 323 | responses: | 332 | responses: |
| @@ -328,17 +337,15 @@ paths: | |||
| 328 | - $ref: '#/definitions/models.Response' | 337 | - $ref: '#/definitions/models.Response' |
| 329 | - properties: | 338 | - properties: |
| 330 | data: | 339 | data: |
| 331 | items: | 340 | $ref: '#/definitions/models.LoginResponse' |
| 332 | $ref: '#/definitions/models.MapShort' | ||
| 333 | type: array | ||
| 334 | type: object | 341 | type: object |
| 335 | "400": | 342 | "400": |
| 336 | description: Bad Request | 343 | description: Bad Request |
| 337 | schema: | 344 | schema: |
| 338 | $ref: '#/definitions/models.Response' | 345 | $ref: '#/definitions/models.Response' |
| 339 | summary: Get maps from the specified chapter id. | 346 | summary: Get (redirect) login page for Steam auth. |
| 340 | tags: | 347 | tags: |
| 341 | - maps | 348 | - login |
| 342 | /maps/{id}/leaderboards: | 349 | /maps/{id}/leaderboards: |
| 343 | get: | 350 | get: |
| 344 | parameters: | 351 | parameters: |