diff options
Diffstat (limited to '')
| -rw-r--r-- | backend/controllers/homeController.go | 6 | ||||
| -rw-r--r-- | backend/controllers/loginController.go | 2 | ||||
| -rw-r--r-- | backend/controllers/mapController.go | 130 | ||||
| -rw-r--r-- | backend/controllers/recordController.go | 59 | ||||
| -rw-r--r-- | backend/controllers/userController.go | 10 |
5 files changed, 158 insertions, 49 deletions
diff --git a/backend/controllers/homeController.go b/backend/controllers/homeController.go index 539d2c4..577f61a 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, username 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 |
| @@ -56,7 +56,7 @@ func Rankings(c *gin.Context) { | |||
| 56 | if uniqueSingleUserRecords == totalSingleMaps { | 56 | if uniqueSingleUserRecords == totalSingleMaps { |
| 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 { |
| @@ -90,7 +90,7 @@ func Rankings(c *gin.Context) { | |||
| 90 | if uniqueMultiUserRecords == totalMultiMaps { | 90 | if uniqueMultiUserRecords == totalMultiMaps { |
| 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 { |
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index 6c0453b..4de4c00 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go | |||
| @@ -56,7 +56,7 @@ func Login(c *gin.Context) { | |||
| 56 | user.LocCountryCode = "XX" | 56 | user.LocCountryCode = "XX" |
| 57 | } | 57 | } |
| 58 | // Insert new user to database | 58 | // Insert new user to database |
| 59 | database.DB.Exec(`INSERT INTO users (steam_id, username, avatar_link, country_code) | 59 | database.DB.Exec(`INSERT INTO users (steam_id, user_name, avatar_link, country_code) |
| 60 | VALUES ($1, $2, $3, $4)`, steamID, user.PersonaName, user.AvatarFull, user.LocCountryCode) | 60 | VALUES ($1, $2, $3, $4)`, steamID, user.PersonaName, user.AvatarFull, user.LocCountryCode) |
| 61 | } | 61 | } |
| 62 | // Generate JWT token | 62 | // Generate JWT token |
diff --git a/backend/controllers/mapController.go b/backend/controllers/mapController.go index 16dd669..bd85a97 100644 --- a/backend/controllers/mapController.go +++ b/backend/controllers/mapController.go | |||
| @@ -3,26 +3,117 @@ package controllers | |||
| 3 | import ( | 3 | import ( |
| 4 | "net/http" | 4 | "net/http" |
| 5 | "strconv" | 5 | "strconv" |
| 6 | "time" | ||
| 6 | 7 | ||
| 7 | "github.com/gin-gonic/gin" | 8 | "github.com/gin-gonic/gin" |
| 9 | "github.com/lib/pq" | ||
| 8 | "github.com/pektezol/leastportals/backend/database" | 10 | "github.com/pektezol/leastportals/backend/database" |
| 9 | "github.com/pektezol/leastportals/backend/models" | 11 | "github.com/pektezol/leastportals/backend/models" |
| 10 | ) | 12 | ) |
| 11 | 13 | ||
| 12 | // GET Map | 14 | // GET Map Summary |
| 13 | // | 15 | // |
| 14 | // @Summary Get map page with specified id. | 16 | // @Summary Get map summary with specified id. |
| 15 | // @Tags maps | 17 | // @Tags maps |
| 16 | // @Accept json | 18 | // @Accept json |
| 17 | // @Produce json | 19 | // @Produce json |
| 18 | // @Param id path int true "Map ID" | 20 | // @Param id path int true "Map ID" |
| 19 | // @Success 200 {object} models.Response{data=models.Map} | 21 | // @Success 200 {object} models.Response{data=models.Map{data=models.MapSummary}} |
| 20 | // @Failure 400 {object} models.Response | 22 | // @Failure 400 {object} models.Response |
| 21 | // @Router /maps/{id} [get] | 23 | // @Router /maps/{id}/summary [get] |
| 22 | func FetchMap(c *gin.Context) { | 24 | func FetchMapSummary(c *gin.Context) { |
| 23 | id := c.Param("id") | 25 | id := c.Param("id") |
| 24 | // Get map data | 26 | // Get map data |
| 25 | var mapData models.Map | 27 | var mapData models.Map |
| 28 | var mapSummaryData models.MapSummary | ||
| 29 | var mapHistoryData []models.MapHistory | ||
| 30 | intID, err := strconv.Atoi(id) | ||
| 31 | if err != nil { | ||
| 32 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 33 | return | ||
| 34 | } | ||
| 35 | mapData.ID = intID | ||
| 36 | var routers pq.StringArray | ||
| 37 | sql := `SELECT g.name, c.name, m.name, m.description, m.showcase, | ||
| 38 | ( | ||
| 39 | SELECT array_agg(user_name) | ||
| 40 | FROM map_routers | ||
| 41 | WHERE map_id = $1 | ||
| 42 | AND score_count = ( | ||
| 43 | SELECT score_count | ||
| 44 | FROM map_history | ||
| 45 | WHERE map_id = $1 | ||
| 46 | ORDER BY score_count | ||
| 47 | LIMIT 1 | ||
| 48 | ) | ||
| 49 | GROUP BY map_routers.user_name | ||
| 50 | ORDER BY user_name | ||
| 51 | ), | ||
| 52 | ( | ||
| 53 | SELECT COALESCE(avg(rating), 0.0) | ||
| 54 | FROM map_ratings | ||
| 55 | WHERE map_id = $1 | ||
| 56 | ) | ||
| 57 | FROM maps m | ||
| 58 | INNER JOIN games g ON m.game_id = g.id | ||
| 59 | INNER JOIN chapters c ON m.chapter_id = c.id | ||
| 60 | WHERE m.id = $1;` | ||
| 61 | // TODO: CategoryScores | ||
| 62 | err = database.DB.QueryRow(sql, id).Scan(&mapData.GameName, &mapData.ChapterName, &mapData.MapName, &mapSummaryData.Description, &mapSummaryData.Showcase, &routers, &mapSummaryData.Rating) | ||
| 63 | if err != nil { | ||
| 64 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 65 | return | ||
| 66 | } | ||
| 67 | var historyNames pq.StringArray | ||
| 68 | var historyScores pq.Int32Array | ||
| 69 | var historyDates pq.StringArray | ||
| 70 | sql = `SELECT array_agg(user_name), array_agg(score_count), array_agg(record_date) | ||
| 71 | FROM map_history | ||
| 72 | WHERE map_id = $1;` | ||
| 73 | err = database.DB.QueryRow(sql, id).Scan(&historyNames, &historyScores, &historyDates) | ||
| 74 | if err != nil { | ||
| 75 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 76 | return | ||
| 77 | } | ||
| 78 | for i := 0; i < len(historyNames); i++ { | ||
| 79 | var history models.MapHistory | ||
| 80 | history.RunnerName = historyNames[i] | ||
| 81 | history.ScoreCount = int(historyScores[i]) | ||
| 82 | layout := "2006-01-02 15:04:05" | ||
| 83 | date, err := time.Parse(layout, historyDates[i]) | ||
| 84 | if err != nil { | ||
| 85 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | ||
| 86 | return | ||
| 87 | } | ||
| 88 | history.Date = date | ||
| 89 | mapHistoryData = append(mapHistoryData, history) | ||
| 90 | } | ||
| 91 | mapSummaryData.History = mapHistoryData | ||
| 92 | mapSummaryData.Routers = routers | ||
| 93 | mapData.Data = mapSummaryData | ||
| 94 | // Return response | ||
| 95 | c.JSON(http.StatusOK, models.Response{ | ||
| 96 | Success: true, | ||
| 97 | Message: "Successfully retrieved map summary.", | ||
| 98 | Data: mapData, | ||
| 99 | }) | ||
| 100 | } | ||
| 101 | |||
| 102 | // GET Map Leaderboards | ||
| 103 | // | ||
| 104 | // @Summary Get map leaderboards with specified id. | ||
| 105 | // @Tags maps | ||
| 106 | // @Accept json | ||
| 107 | // @Produce json | ||
| 108 | // @Param id path int true "Map ID" | ||
| 109 | // @Success 200 {object} models.Response{data=models.Map{data=models.MapRecords}} | ||
| 110 | // @Failure 400 {object} models.Response | ||
| 111 | // @Router /maps/{id}/leaderboards [get] | ||
| 112 | func FetchMapLeaderboards(c *gin.Context) { | ||
| 113 | id := c.Param("id") | ||
| 114 | // Get map data | ||
| 115 | var mapData models.Map | ||
| 116 | var mapRecordsData models.MapRecords | ||
| 26 | var isDisabled bool | 117 | var isDisabled bool |
| 27 | intID, err := strconv.Atoi(id) | 118 | intID, err := strconv.Atoi(id) |
| 28 | if err != nil { | 119 | if err != nil { |
| @@ -30,8 +121,12 @@ func FetchMap(c *gin.Context) { | |||
| 30 | return | 121 | return |
| 31 | } | 122 | } |
| 32 | mapData.ID = intID | 123 | mapData.ID = intID |
| 33 | sql := `SELECT map_name, wr_score, wr_time, is_coop, is_disabled FROM maps WHERE id = $1;` | 124 | sql := `SELECT g.name, c.name, m.name, is_disabled |
| 34 | err = database.DB.QueryRow(sql, id).Scan(&mapData.Name, &mapData.ScoreWR, &mapData.TimeWR, &mapData.IsCoop, &isDisabled) | 125 | FROM maps m |
| 126 | INNER JOIN games g ON m.game_id = g.id | ||
| 127 | INNER JOIN chapters c ON m.chapter_id = c.id | ||
| 128 | WHERE m.id = $1;` | ||
| 129 | err = database.DB.QueryRow(sql, id).Scan(&mapData.GameName, &mapData.ChapterName, &mapData.MapName, &isDisabled) | ||
| 35 | if err != nil { | 130 | if err != nil { |
| 36 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 131 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 37 | return | 132 | return |
| @@ -40,13 +135,14 @@ func FetchMap(c *gin.Context) { | |||
| 40 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) | 135 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) |
| 41 | return | 136 | return |
| 42 | } | 137 | } |
| 138 | // TODO: avatar and names for host & partner | ||
| 43 | // Get records from the map | 139 | // Get records from the map |
| 44 | if mapData.IsCoop { | 140 | if mapData.GameName == "Portal 2 - Cooperative" { |
| 45 | var records []models.RecordMP | 141 | var records []models.RecordMP |
| 46 | sql = `SELECT id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date | 142 | sql = `SELECT id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date |
| 47 | FROM ( | 143 | FROM ( |
| 48 | SELECT id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date, | 144 | SELECT id, host_id, partner_id, score_count, score_time, host_demo_id, partner_demo_id, record_date, |
| 49 | ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY score_count, score_time) AS rn | 145 | ROW_NUMBER() OVER (PARTITION BY host_id, partner_id ORDER BY score_count, score_time) AS rn |
| 50 | FROM records_mp | 146 | FROM records_mp |
| 51 | WHERE map_id = $1 | 147 | WHERE map_id = $1 |
| 52 | ) sub | 148 | ) sub |
| @@ -74,16 +170,17 @@ func FetchMap(c *gin.Context) { | |||
| 74 | records = append(records, record) | 170 | records = append(records, record) |
| 75 | placement++ | 171 | placement++ |
| 76 | } | 172 | } |
| 77 | mapData.Records = records | 173 | mapRecordsData.Records = records |
| 78 | } else { | 174 | } else { |
| 79 | var records []models.RecordSP | 175 | var records []models.RecordSP |
| 80 | sql = `SELECT id, user_id, score_count, score_time, demo_id, record_date | 176 | sql = `SELECT id, user_id, users.user_name, users.avatar_link, score_count, score_time, demo_id, record_date |
| 81 | FROM ( | 177 | FROM ( |
| 82 | SELECT id, user_id, score_count, score_time, demo_id, record_date, | 178 | SELECT id, user_id, score_count, score_time, demo_id, record_date, |
| 83 | ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY score_count, score_time) AS rn | 179 | ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY score_count, score_time) AS rn |
| 84 | FROM records_sp | 180 | FROM records_sp |
| 85 | WHERE map_id = $1 | 181 | WHERE map_id = $1 |
| 86 | ) sub | 182 | ) sub |
| 183 | INNER JOIN users ON user_id = users.steam_id | ||
| 87 | WHERE rn = 1;` | 184 | WHERE rn = 1;` |
| 88 | rows, err := database.DB.Query(sql, id) | 185 | rows, err := database.DB.Query(sql, id) |
| 89 | if err != nil { | 186 | if err != nil { |
| @@ -94,7 +191,7 @@ func FetchMap(c *gin.Context) { | |||
| 94 | ties := 0 | 191 | ties := 0 |
| 95 | for rows.Next() { | 192 | for rows.Next() { |
| 96 | var record models.RecordSP | 193 | var record models.RecordSP |
| 97 | err := rows.Scan(&record.RecordID, &record.UserID, &record.ScoreCount, &record.ScoreTime, &record.DemoID, &record.RecordDate) | 194 | err := rows.Scan(&record.RecordID, &record.UserID, &record.UserName, &record.UserAvatar, &record.ScoreCount, &record.ScoreTime, &record.DemoID, &record.RecordDate) |
| 98 | if err != nil { | 195 | if err != nil { |
| 99 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 196 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 100 | return | 197 | return |
| @@ -108,16 +205,13 @@ func FetchMap(c *gin.Context) { | |||
| 108 | records = append(records, record) | 205 | records = append(records, record) |
| 109 | placement++ | 206 | placement++ |
| 110 | } | 207 | } |
| 111 | mapData.Records = records | 208 | mapRecordsData.Records = records |
| 112 | } | 209 | } |
| 210 | mapData.Data = mapRecordsData | ||
| 113 | // Return response | 211 | // Return response |
| 114 | c.JSON(http.StatusOK, models.Response{ | 212 | c.JSON(http.StatusOK, models.Response{ |
| 115 | Success: true, | 213 | Success: true, |
| 116 | Message: "Successfully retrieved map data.", | 214 | Message: "Successfully retrieved map leaderboards.", |
| 117 | Data: mapData, | 215 | Data: mapData, |
| 118 | }) | 216 | }) |
| 119 | } | 217 | } |
| 120 | |||
| 121 | func CreateMapCommunity(c *gin.Context) { | ||
| 122 | |||
| 123 | } | ||
diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index 3b4bdc7..bafa844 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go | |||
| @@ -43,11 +43,11 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 43 | return | 43 | return |
| 44 | } | 44 | } |
| 45 | // Check if map is sp or mp | 45 | // Check if map is sp or mp |
| 46 | var wrScore int | 46 | var gameID int |
| 47 | var wrTime int | ||
| 48 | var isCoop bool | 47 | var isCoop bool |
| 49 | var isDisabled bool | 48 | var isDisabled bool |
| 50 | err := database.DB.QueryRow(`SELECT wr_score, wr_time, is_coop, is_disabled FROM maps WHERE id = $1;`, mapId).Scan(&wrScore, &wrTime, &isCoop, &isDisabled) | 49 | sql := `SELECT game_id, is_disabled FROM maps WHERE id = $1;` |
| 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())) |
| 53 | return | 53 | return |
| @@ -56,6 +56,9 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 56 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) | 56 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) |
| 57 | return | 57 | return |
| 58 | } | 58 | } |
| 59 | if gameID == 2 { | ||
| 60 | isCoop = true | ||
| 61 | } | ||
| 59 | // Get record request | 62 | // Get record request |
| 60 | var record models.RecordRequest | 63 | var record models.RecordRequest |
| 61 | score_count, err := strconv.Atoi(c.PostForm("score_count")) | 64 | score_count, err := strconv.Atoi(c.PostForm("score_count")) |
| @@ -104,6 +107,14 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 104 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 107 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 105 | return | 108 | return |
| 106 | } | 109 | } |
| 110 | // Create database transaction for inserts | ||
| 111 | tx, err := database.DB.Begin() | ||
| 112 | if err != nil { | ||
| 113 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | ||
| 114 | return | ||
| 115 | } | ||
| 116 | // Defer to a rollback in case anything fails | ||
| 117 | defer tx.Rollback() | ||
| 107 | fileID := "" | 118 | fileID := "" |
| 108 | for i, header := range files { | 119 | for i, header := range files { |
| 109 | uuid := uuid.New().String() | 120 | uuid := uuid.New().String() |
| @@ -131,7 +142,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 131 | if i == 1 { | 142 | if i == 1 { |
| 132 | partnerDemoUUID = uuid | 143 | partnerDemoUUID = uuid |
| 133 | } | 144 | } |
| 134 | _, err = database.DB.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) | 145 | _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) |
| 135 | if err != nil { | 146 | if err != nil { |
| 136 | deleteFile(srv, file.Id) | 147 | deleteFile(srv, file.Id) |
| 137 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 148 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| @@ -152,37 +163,41 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 152 | partnerID = user.(models.User).SteamID | 163 | partnerID = user.(models.User).SteamID |
| 153 | hostID = record.PartnerID | 164 | hostID = record.PartnerID |
| 154 | } | 165 | } |
| 155 | _, err := database.DB.Exec(sql, mapId, record.ScoreCount, record.ScoreTime, hostID, partnerID, hostDemoUUID, partnerDemoUUID) | 166 | _, err := tx.Exec(sql, mapId, record.ScoreCount, record.ScoreTime, hostID, partnerID, hostDemoUUID, partnerDemoUUID) |
| 156 | if err != nil { | 167 | if err != nil { |
| 157 | deleteFile(srv, fileID) | 168 | deleteFile(srv, fileID) |
| 158 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 169 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 159 | return | 170 | return |
| 160 | } | 171 | } |
| 161 | // If a new world record based on portal count | 172 | // If a new world record based on portal count |
| 162 | if record.ScoreCount < wrScore { | 173 | // if record.ScoreCount < wrScore { |
| 163 | _, err := database.DB.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) |
| 164 | if err != nil { | 175 | // if err != nil { |
| 165 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 176 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 166 | return | 177 | // return |
| 167 | } | 178 | // } |
| 168 | } | 179 | // } |
| 169 | } else { | 180 | } else { |
| 170 | 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) |
| 171 | VALUES($1, $2, $3, $4, $5);` | 182 | VALUES($1, $2, $3, $4, $5);` |
| 172 | _, err := database.DB.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) |
| 173 | if err != nil { | 184 | if err != nil { |
| 174 | deleteFile(srv, fileID) | 185 | deleteFile(srv, fileID) |
| 175 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 186 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 176 | return | 187 | return |
| 177 | } | 188 | } |
| 178 | // If a new world record based on portal count | 189 | // If a new world record based on portal count |
| 179 | if record.ScoreCount < wrScore { | 190 | // if record.ScoreCount < wrScore { |
| 180 | _, err := database.DB.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) |
| 181 | if err != nil { | 192 | // if err != nil { |
| 182 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 193 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 183 | return | 194 | // return |
| 184 | } | 195 | // } |
| 185 | } | 196 | // } |
| 197 | } | ||
| 198 | if err = tx.Commit(); err != nil { | ||
| 199 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | ||
| 200 | return | ||
| 186 | } | 201 | } |
| 187 | c.JSON(http.StatusOK, models.Response{ | 202 | c.JSON(http.StatusOK, models.Response{ |
| 188 | Success: true, | 203 | Success: true, |
| @@ -198,10 +213,10 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 198 | // @Tags demo | 213 | // @Tags demo |
| 199 | // @Accept json | 214 | // @Accept json |
| 200 | // @Produce octet-stream | 215 | // @Produce octet-stream |
| 201 | // @Param uuid path int true "Demo UUID" | 216 | // @Param uuid query int true "Demo UUID" |
| 202 | // @Success 200 {file} binary "Demo File" | 217 | // @Success 200 {file} binary "Demo File" |
| 203 | // @Failure 400 {object} models.Response | 218 | // @Failure 400 {object} models.Response |
| 204 | // @Router /demo [get] | 219 | // @Router /demos [get] |
| 205 | func DownloadDemoWithID(c *gin.Context) { | 220 | func DownloadDemoWithID(c *gin.Context) { |
| 206 | uuid := c.Query("uuid") | 221 | uuid := c.Query("uuid") |
| 207 | var locationID string | 222 | var locationID string |
diff --git a/backend/controllers/userController.go b/backend/controllers/userController.go index c86a739..5ad800d 100644 --- a/backend/controllers/userController.go +++ b/backend/controllers/userController.go | |||
| @@ -88,7 +88,7 @@ func Profile(c *gin.Context) { | |||
| 88 | Data: models.ProfileResponse{ | 88 | Data: models.ProfileResponse{ |
| 89 | Profile: true, | 89 | Profile: true, |
| 90 | SteamID: user.(models.User).SteamID, | 90 | SteamID: user.(models.User).SteamID, |
| 91 | Username: user.(models.User).Username, | 91 | UserName: user.(models.User).UserName, |
| 92 | AvatarLink: user.(models.User).AvatarLink, | 92 | AvatarLink: user.(models.User).AvatarLink, |
| 93 | CountryCode: user.(models.User).CountryCode, | 93 | CountryCode: user.(models.User).CountryCode, |
| 94 | ScoresSP: scoresSP, | 94 | ScoresSP: scoresSP, |
| @@ -108,7 +108,7 @@ func Profile(c *gin.Context) { | |||
| 108 | // @Success 200 {object} models.Response{data=models.ProfileResponse} | 108 | // @Success 200 {object} models.Response{data=models.ProfileResponse} |
| 109 | // @Failure 400 {object} models.Response | 109 | // @Failure 400 {object} models.Response |
| 110 | // @Failure 404 {object} models.Response | 110 | // @Failure 404 {object} models.Response |
| 111 | // @Router /user/{id} [get] | 111 | // @Router /users/{id} [get] |
| 112 | func FetchUser(c *gin.Context) { | 112 | func FetchUser(c *gin.Context) { |
| 113 | id := c.Param("id") | 113 | id := c.Param("id") |
| 114 | // Check if id is all numbers and 17 length | 114 | // Check if id is all numbers and 17 length |
| @@ -120,7 +120,7 @@ func FetchUser(c *gin.Context) { | |||
| 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 == "" { |
| 126 | // User does not exist | 126 | // User does not exist |
| @@ -190,7 +190,7 @@ func FetchUser(c *gin.Context) { | |||
| 190 | Data: models.ProfileResponse{ | 190 | Data: models.ProfileResponse{ |
| 191 | Profile: true, | 191 | Profile: true, |
| 192 | SteamID: user.SteamID, | 192 | SteamID: user.SteamID, |
| 193 | Username: user.Username, | 193 | UserName: user.UserName, |
| 194 | AvatarLink: user.AvatarLink, | 194 | AvatarLink: user.AvatarLink, |
| 195 | CountryCode: user.CountryCode, | 195 | CountryCode: user.CountryCode, |
| 196 | ScoresSP: scoresSP, | 196 | ScoresSP: scoresSP, |
| @@ -236,7 +236,7 @@ func UpdateUser(c *gin.Context) { | |||
| 236 | Data: models.ProfileResponse{ | 236 | Data: models.ProfileResponse{ |
| 237 | Profile: true, | 237 | Profile: true, |
| 238 | SteamID: user.(models.User).SteamID, | 238 | SteamID: user.(models.User).SteamID, |
| 239 | Username: profile.PersonaName, | 239 | UserName: profile.PersonaName, |
| 240 | AvatarLink: profile.AvatarFull, | 240 | AvatarLink: profile.AvatarFull, |
| 241 | CountryCode: profile.LocCountryCode, | 241 | CountryCode: profile.LocCountryCode, |
| 242 | }, | 242 | }, |