diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-22 17:48:43 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-22 17:48:43 +0300 |
| commit | 3cda2073cc29317d6251e7b88102b70659aed6d6 (patch) | |
| tree | ec96bc99b6bc5d4a1f3a45efcfe6cb2e8514b7fa | |
| parent | feat: completion count on summary for each cm entry (#63) (diff) | |
| download | lphub-3cda2073cc29317d6251e7b88102b70659aed6d6.tar.gz lphub-3cda2073cc29317d6251e7b88102b70659aed6d6.tar.bz2 lphub-3cda2073cc29317d6251e7b88102b70659aed6d6.zip | |
fix: change all status codes to 200 (#66)
Former-commit-id: ae632415e3f6f79a462240f151ada2e428318c6b
| -rw-r--r-- | backend/handlers/home.go | 10 | ||||
| -rw-r--r-- | backend/handlers/login.go | 10 | ||||
| -rw-r--r-- | backend/handlers/logs.go | 10 | ||||
| -rw-r--r-- | backend/handlers/map.go | 46 | ||||
| -rw-r--r-- | backend/handlers/mod.go | 72 | ||||
| -rw-r--r-- | backend/handlers/record.go | 46 | ||||
| -rw-r--r-- | backend/handlers/user.go | 68 |
7 files changed, 131 insertions, 131 deletions
diff --git a/backend/handlers/home.go b/backend/handlers/home.go index 2095a74..a2b7113 100644 --- a/backend/handlers/home.go +++ b/backend/handlers/home.go | |||
| @@ -50,7 +50,7 @@ func Rankings(c *gin.Context) { | |||
| 50 | FROM records_sp sp JOIN users u ON u.steam_id = sp.user_id GROUP BY u.steam_id, u.user_name` | 50 | FROM records_sp sp JOIN users u ON u.steam_id = sp.user_id GROUP BY u.steam_id, u.user_name` |
| 51 | rows, err := database.DB.Query(sql) | 51 | rows, err := database.DB.Query(sql) |
| 52 | if err != nil { | 52 | if err != nil { |
| 53 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 53 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 54 | return | 54 | return |
| 55 | } | 55 | } |
| 56 | for rows.Next() { | 56 | for rows.Next() { |
| @@ -59,7 +59,7 @@ func Rankings(c *gin.Context) { | |||
| 59 | var totalCount int | 59 | var totalCount int |
| 60 | err = rows.Scan(&ranking.User.SteamID, &ranking.User.UserName, ¤tCount, &totalCount, &ranking.TotalScore) | 60 | err = rows.Scan(&ranking.User.SteamID, &ranking.User.UserName, ¤tCount, &totalCount, &ranking.TotalScore) |
| 61 | if err != nil { | 61 | if err != nil { |
| 62 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 62 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 63 | return | 63 | return |
| 64 | } | 64 | } |
| 65 | if currentCount != totalCount { | 65 | if currentCount != totalCount { |
| @@ -82,7 +82,7 @@ func Rankings(c *gin.Context) { | |||
| 82 | FROM records_mp mp JOIN users u ON u.steam_id = mp.host_id OR u.steam_id = mp.partner_id GROUP BY u.steam_id, u.user_name` | 82 | FROM records_mp mp JOIN users u ON u.steam_id = mp.host_id OR u.steam_id = mp.partner_id GROUP BY u.steam_id, u.user_name` |
| 83 | rows, err = database.DB.Query(sql) | 83 | rows, err = database.DB.Query(sql) |
| 84 | if err != nil { | 84 | if err != nil { |
| 85 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 85 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 86 | return | 86 | return |
| 87 | } | 87 | } |
| 88 | for rows.Next() { | 88 | for rows.Next() { |
| @@ -91,7 +91,7 @@ func Rankings(c *gin.Context) { | |||
| 91 | var totalCount int | 91 | var totalCount int |
| 92 | err = rows.Scan(&ranking.User.SteamID, &ranking.User.UserName, ¤tCount, &totalCount, &ranking.TotalScore) | 92 | err = rows.Scan(&ranking.User.SteamID, &ranking.User.UserName, ¤tCount, &totalCount, &ranking.TotalScore) |
| 93 | if err != nil { | 93 | if err != nil { |
| 94 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 94 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 95 | return | 95 | return |
| 96 | } | 96 | } |
| 97 | if currentCount != totalCount { | 97 | if currentCount != totalCount { |
| @@ -273,7 +273,7 @@ func SearchWithQuery(c *gin.Context) { | |||
| 273 | for rows.Next() { | 273 | for rows.Next() { |
| 274 | var user models.UserShort | 274 | var user models.UserShort |
| 275 | if err := rows.Scan(&user.SteamID, &user.UserName); err != nil { | 275 | if err := rows.Scan(&user.SteamID, &user.UserName); err != nil { |
| 276 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 276 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 277 | return | 277 | return |
| 278 | } | 278 | } |
| 279 | response.Players = append(response.Players, user) | 279 | response.Players = append(response.Players, user) |
diff --git a/backend/handlers/login.go b/backend/handlers/login.go index 85ffd63..a7e4379 100644 --- a/backend/handlers/login.go +++ b/backend/handlers/login.go | |||
| @@ -39,7 +39,7 @@ func Login(c *gin.Context) { | |||
| 39 | steamID, err := openID.ValidateAndGetId() | 39 | steamID, err := openID.ValidateAndGetId() |
| 40 | if err != nil { | 40 | if err != nil { |
| 41 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailValidate) | 41 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailValidate) |
| 42 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 42 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 43 | return | 43 | return |
| 44 | } | 44 | } |
| 45 | // Create user if new | 45 | // Create user if new |
| @@ -50,7 +50,7 @@ func Login(c *gin.Context) { | |||
| 50 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) | 50 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) |
| 51 | if err != nil { | 51 | if err != nil { |
| 52 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailSummary) | 52 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailSummary) |
| 53 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 53 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 54 | return | 54 | return |
| 55 | } | 55 | } |
| 56 | // Empty country code check | 56 | // Empty country code check |
| @@ -80,7 +80,7 @@ func Login(c *gin.Context) { | |||
| 80 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) | 80 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) |
| 81 | if err != nil { | 81 | if err != nil { |
| 82 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailToken) | 82 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailToken) |
| 83 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Failed to generate token.")) | 83 | c.JSON(http.StatusOK, models.ErrorResponse("Failed to generate token.")) |
| 84 | return | 84 | return |
| 85 | } | 85 | } |
| 86 | c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true) | 86 | c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true) |
| @@ -109,7 +109,7 @@ func Login(c *gin.Context) { | |||
| 109 | func GetCookie(c *gin.Context) { | 109 | func GetCookie(c *gin.Context) { |
| 110 | cookie, err := c.Cookie("token") | 110 | cookie, err := c.Cookie("token") |
| 111 | if err != nil { | 111 | if err != nil { |
| 112 | c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found.")) | 112 | c.JSON(http.StatusOK, models.ErrorResponse("No token cookie found.")) |
| 113 | return | 113 | return |
| 114 | } | 114 | } |
| 115 | c.JSON(http.StatusOK, models.Response{ | 115 | c.JSON(http.StatusOK, models.Response{ |
| @@ -133,7 +133,7 @@ func GetCookie(c *gin.Context) { | |||
| 133 | func DeleteCookie(c *gin.Context) { | 133 | func DeleteCookie(c *gin.Context) { |
| 134 | cookie, err := c.Cookie("token") | 134 | cookie, err := c.Cookie("token") |
| 135 | if err != nil { | 135 | if err != nil { |
| 136 | c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found.")) | 136 | c.JSON(http.StatusOK, models.ErrorResponse("No token cookie found.")) |
| 137 | return | 137 | return |
| 138 | } | 138 | } |
| 139 | c.SetCookie("token", "", -1, "/", "", true, true) | 139 | c.SetCookie("token", "", -1, "/", "", true, true) |
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index 2b8223a..b6bcef6 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go | |||
| @@ -83,7 +83,7 @@ type ScoreLogsResponseDetails struct { | |||
| 83 | func ModLogs(c *gin.Context) { | 83 | func ModLogs(c *gin.Context) { |
| 84 | mod, exists := c.Get("mod") | 84 | mod, exists := c.Get("mod") |
| 85 | if !exists || !mod.(bool) { | 85 | if !exists || !mod.(bool) { |
| 86 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) | 86 | c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) |
| 87 | return | 87 | return |
| 88 | } | 88 | } |
| 89 | response := LogsResponse{Logs: []LogsResponseDetails{}} | 89 | response := LogsResponse{Logs: []LogsResponseDetails{}} |
| @@ -92,14 +92,14 @@ func ModLogs(c *gin.Context) { | |||
| 92 | ORDER BY l.date DESC LIMIT 100;` | 92 | ORDER BY l.date DESC LIMIT 100;` |
| 93 | rows, err := database.DB.Query(sql) | 93 | rows, err := database.DB.Query(sql) |
| 94 | if err != nil { | 94 | if err != nil { |
| 95 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 95 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 96 | return | 96 | return |
| 97 | } | 97 | } |
| 98 | for rows.Next() { | 98 | for rows.Next() { |
| 99 | log := Log{} | 99 | log := Log{} |
| 100 | err = rows.Scan(&log.User.UserName, &log.User.SteamID, &log.Type, &log.Description, &log.Date) | 100 | err = rows.Scan(&log.User.UserName, &log.User.SteamID, &log.Type, &log.Description, &log.Date) |
| 101 | if err != nil { | 101 | if err != nil { |
| 102 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 102 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 103 | return | 103 | return |
| 104 | } | 104 | } |
| 105 | detail := fmt.Sprintf("%s.%s", log.Type, log.Description) | 105 | detail := fmt.Sprintf("%s.%s", log.Type, log.Description) |
| @@ -160,14 +160,14 @@ func ScoreLogs(c *gin.Context) { | |||
| 160 | ORDER BY rs.record_date DESC LIMIT 100;` | 160 | ORDER BY rs.record_date DESC LIMIT 100;` |
| 161 | rows, err := database.DB.Query(sql) | 161 | rows, err := database.DB.Query(sql) |
| 162 | if err != nil { | 162 | if err != nil { |
| 163 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 163 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 164 | return | 164 | return |
| 165 | } | 165 | } |
| 166 | for rows.Next() { | 166 | for rows.Next() { |
| 167 | score := ScoreLogsResponseDetails{} | 167 | score := ScoreLogsResponseDetails{} |
| 168 | err = rows.Scan(&score.Game.ID, &score.Game.Name, &score.Game.IsCoop, &score.Map.ID, &score.Map.Name, &score.User.SteamID, &score.User.UserName, &score.ScoreCount, &score.ScoreTime, &score.DemoID, &score.Date) | 168 | err = rows.Scan(&score.Game.ID, &score.Game.Name, &score.Game.IsCoop, &score.Map.ID, &score.Map.Name, &score.User.SteamID, &score.User.UserName, &score.ScoreCount, &score.ScoreTime, &score.DemoID, &score.Date) |
| 169 | if err != nil { | 169 | if err != nil { |
| 170 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 170 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 171 | return | 171 | return |
| 172 | } | 172 | } |
| 173 | response.Logs = append(response.Logs, score) | 173 | response.Logs = append(response.Logs, score) |
diff --git a/backend/handlers/map.go b/backend/handlers/map.go index e55dab4..f3198ff 100644 --- a/backend/handlers/map.go +++ b/backend/handlers/map.go | |||
| @@ -67,7 +67,7 @@ func FetchMapSummary(c *gin.Context) { | |||
| 67 | response := MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{Routes: []models.MapRoute{}}} | 67 | response := MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{Routes: []models.MapRoute{}}} |
| 68 | intID, err := strconv.Atoi(id) | 68 | intID, err := strconv.Atoi(id) |
| 69 | if err != nil { | 69 | if err != nil { |
| 70 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 70 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 71 | return | 71 | return |
| 72 | } | 72 | } |
| 73 | // Get map data | 73 | // Get map data |
| @@ -79,7 +79,7 @@ func FetchMapSummary(c *gin.Context) { | |||
| 79 | WHERE m.id = $1` | 79 | WHERE m.id = $1` |
| 80 | err = database.DB.QueryRow(sql, id).Scan(&response.Map.ID, &response.Map.GameName, &response.Map.ChapterName, &response.Map.MapName, &response.Map.Image, &response.Map.IsCoop) | 80 | err = database.DB.QueryRow(sql, id).Scan(&response.Map.ID, &response.Map.GameName, &response.Map.ChapterName, &response.Map.MapName, &response.Map.Image, &response.Map.IsCoop) |
| 81 | if err != nil { | 81 | if err != nil { |
| 82 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 82 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 83 | return | 83 | return |
| 84 | } | 84 | } |
| 85 | // Get map routes and histories | 85 | // Get map routes and histories |
| @@ -91,14 +91,14 @@ func FetchMapSummary(c *gin.Context) { | |||
| 91 | ORDER BY h.record_date ASC;` | 91 | ORDER BY h.record_date ASC;` |
| 92 | rows, err := database.DB.Query(sql, id) | 92 | rows, err := database.DB.Query(sql, id) |
| 93 | if err != nil { | 93 | if err != nil { |
| 94 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 94 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 95 | return | 95 | return |
| 96 | } | 96 | } |
| 97 | for rows.Next() { | 97 | for rows.Next() { |
| 98 | route := models.MapRoute{Category: models.Category{}, History: models.MapHistory{}} | 98 | route := models.MapRoute{Category: models.Category{}, History: models.MapHistory{}} |
| 99 | 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) | 99 | 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) |
| 100 | if err != nil { | 100 | if err != nil { |
| 101 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 101 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 102 | return | 102 | return |
| 103 | } | 103 | } |
| 104 | // Get completion count | 104 | // Get completion count |
| @@ -109,7 +109,7 @@ func FetchMapSummary(c *gin.Context) { | |||
| 109 | ) sub WHERE sub.rn = 1 AND score_count = $2` | 109 | ) sub WHERE sub.rn = 1 AND score_count = $2` |
| 110 | err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount) | 110 | err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount) |
| 111 | if err != nil { | 111 | if err != nil { |
| 112 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 112 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 113 | return | 113 | return |
| 114 | } | 114 | } |
| 115 | } else { | 115 | } else { |
| @@ -119,7 +119,7 @@ func FetchMapSummary(c *gin.Context) { | |||
| 119 | ) sub WHERE rn = 1 AND score_count = $2` | 119 | ) sub WHERE rn = 1 AND score_count = $2` |
| 120 | err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount) | 120 | err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount) |
| 121 | if err != nil { | 121 | if err != nil { |
| 122 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 122 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 123 | return | 123 | return |
| 124 | } | 124 | } |
| 125 | } | 125 | } |
| @@ -159,7 +159,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 159 | var isDisabled bool | 159 | var isDisabled bool |
| 160 | intID, err := strconv.Atoi(id) | 160 | intID, err := strconv.Atoi(id) |
| 161 | if err != nil { | 161 | if err != nil { |
| 162 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 162 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 163 | return | 163 | return |
| 164 | } | 164 | } |
| 165 | response.Map.ID = intID | 165 | response.Map.ID = intID |
| @@ -170,11 +170,11 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 170 | WHERE m.id = $1` | 170 | WHERE m.id = $1` |
| 171 | err = database.DB.QueryRow(sql, id).Scan(&response.Map.GameName, &response.Map.ChapterName, &response.Map.MapName, &isDisabled, &response.Map.Image, &response.Map.IsCoop) | 171 | err = database.DB.QueryRow(sql, id).Scan(&response.Map.GameName, &response.Map.ChapterName, &response.Map.MapName, &isDisabled, &response.Map.Image, &response.Map.IsCoop) |
| 172 | if err != nil { | 172 | if err != nil { |
| 173 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 173 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 174 | return | 174 | return |
| 175 | } | 175 | } |
| 176 | if isDisabled { | 176 | if isDisabled { |
| 177 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) | 177 | c.JSON(http.StatusOK, models.ErrorResponse("Map is not available for competitive boards.")) |
| 178 | return | 178 | return |
| 179 | } | 179 | } |
| 180 | totalRecords := 0 | 180 | totalRecords := 0 |
| @@ -214,7 +214,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 214 | ORDER BY score_count, score_time` | 214 | ORDER BY score_count, score_time` |
| 215 | rows, err := database.DB.Query(sql, id) | 215 | rows, err := database.DB.Query(sql, id) |
| 216 | if err != nil { | 216 | if err != nil { |
| 217 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 217 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 218 | return | 218 | return |
| 219 | } | 219 | } |
| 220 | placement := 1 | 220 | placement := 1 |
| @@ -223,7 +223,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 223 | var record RecordMultiplayer | 223 | var record RecordMultiplayer |
| 224 | err := rows.Scan(&record.RecordID, &record.Host.SteamID, &record.Host.UserName, &record.Host.AvatarLink, &record.Partner.SteamID, &record.Partner.UserName, &record.Partner.AvatarLink, &record.ScoreCount, &record.ScoreTime, &record.HostDemoID, &record.PartnerDemoID, &record.RecordDate) | 224 | err := rows.Scan(&record.RecordID, &record.Host.SteamID, &record.Host.UserName, &record.Host.AvatarLink, &record.Partner.SteamID, &record.Partner.UserName, &record.Partner.AvatarLink, &record.ScoreCount, &record.ScoreTime, &record.HostDemoID, &record.PartnerDemoID, &record.RecordDate) |
| 225 | if err != nil { | 225 | if err != nil { |
| 226 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 226 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 227 | return | 227 | return |
| 228 | } | 228 | } |
| 229 | if len(records) != 0 && records[len(records)-1].ScoreCount == record.ScoreCount && records[len(records)-1].ScoreTime == record.ScoreTime { | 229 | if len(records) != 0 && records[len(records)-1].ScoreCount == record.ScoreCount && records[len(records)-1].ScoreTime == record.ScoreTime { |
| @@ -240,7 +240,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 240 | if totalRecords != 0 { | 240 | if totalRecords != 0 { |
| 241 | totalPages = (totalRecords + pageSize - 1) / pageSize | 241 | totalPages = (totalRecords + pageSize - 1) / pageSize |
| 242 | if page > totalPages { | 242 | if page > totalPages { |
| 243 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid page number.")) | 243 | c.JSON(http.StatusOK, models.ErrorResponse("Invalid page number.")) |
| 244 | return | 244 | return |
| 245 | } | 245 | } |
| 246 | startIndex := (page - 1) * pageSize | 246 | startIndex := (page - 1) * pageSize |
| @@ -264,7 +264,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 264 | ORDER BY score_count, score_time` | 264 | ORDER BY score_count, score_time` |
| 265 | rows, err := database.DB.Query(sql, id) | 265 | rows, err := database.DB.Query(sql, id) |
| 266 | if err != nil { | 266 | if err != nil { |
| 267 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 267 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 268 | return | 268 | return |
| 269 | } | 269 | } |
| 270 | placement := 1 | 270 | placement := 1 |
| @@ -273,7 +273,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 273 | var record RecordSingleplayer | 273 | var record RecordSingleplayer |
| 274 | err := rows.Scan(&record.RecordID, &record.User.SteamID, &record.User.UserName, &record.User.AvatarLink, &record.ScoreCount, &record.ScoreTime, &record.DemoID, &record.RecordDate) | 274 | err := rows.Scan(&record.RecordID, &record.User.SteamID, &record.User.UserName, &record.User.AvatarLink, &record.ScoreCount, &record.ScoreTime, &record.DemoID, &record.RecordDate) |
| 275 | if err != nil { | 275 | if err != nil { |
| 276 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 276 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 277 | return | 277 | return |
| 278 | } | 278 | } |
| 279 | if len(records) != 0 && records[len(records)-1].ScoreCount == record.ScoreCount && records[len(records)-1].ScoreTime == record.ScoreTime { | 279 | if len(records) != 0 && records[len(records)-1].ScoreCount == record.ScoreCount && records[len(records)-1].ScoreTime == record.ScoreTime { |
| @@ -290,7 +290,7 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 290 | if totalRecords != 0 { | 290 | if totalRecords != 0 { |
| 291 | totalPages = (totalRecords + pageSize - 1) / pageSize | 291 | totalPages = (totalRecords + pageSize - 1) / pageSize |
| 292 | if page > totalPages { | 292 | if page > totalPages { |
| 293 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid page number.")) | 293 | c.JSON(http.StatusOK, models.ErrorResponse("Invalid page number.")) |
| 294 | return | 294 | return |
| 295 | } | 295 | } |
| 296 | startIndex := (page - 1) * pageSize | 296 | startIndex := (page - 1) * pageSize |
| @@ -325,14 +325,14 @@ func FetchMapLeaderboards(c *gin.Context) { | |||
| 325 | func FetchGames(c *gin.Context) { | 325 | func FetchGames(c *gin.Context) { |
| 326 | rows, err := database.DB.Query(`SELECT id, name, is_coop FROM games`) | 326 | rows, err := database.DB.Query(`SELECT id, name, is_coop FROM games`) |
| 327 | if err != nil { | 327 | if err != nil { |
| 328 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 328 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 329 | return | 329 | return |
| 330 | } | 330 | } |
| 331 | var games []models.Game | 331 | var games []models.Game |
| 332 | for rows.Next() { | 332 | for rows.Next() { |
| 333 | var game models.Game | 333 | var game models.Game |
| 334 | if err := rows.Scan(&game.ID, &game.Name, &game.IsCoop); err != nil { | 334 | if err := rows.Scan(&game.ID, &game.Name, &game.IsCoop); err != nil { |
| 335 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 335 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 336 | return | 336 | return |
| 337 | } | 337 | } |
| 338 | games = append(games, game) | 338 | games = append(games, game) |
| @@ -357,13 +357,13 @@ func FetchChapters(c *gin.Context) { | |||
| 357 | gameID := c.Param("id") | 357 | gameID := c.Param("id") |
| 358 | intID, err := strconv.Atoi(gameID) | 358 | intID, err := strconv.Atoi(gameID) |
| 359 | if err != nil { | 359 | if err != nil { |
| 360 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 360 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 361 | return | 361 | return |
| 362 | } | 362 | } |
| 363 | var response ChaptersResponse | 363 | var response ChaptersResponse |
| 364 | rows, err := database.DB.Query(`SELECT c.id, c.name, g.name FROM chapters c INNER JOIN games g ON c.game_id = g.id WHERE game_id = $1`, gameID) | 364 | rows, err := database.DB.Query(`SELECT c.id, c.name, g.name FROM chapters c INNER JOIN games g ON c.game_id = g.id WHERE game_id = $1`, gameID) |
| 365 | if err != nil { | 365 | if err != nil { |
| 366 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 366 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 367 | return | 367 | return |
| 368 | } | 368 | } |
| 369 | var chapters []models.Chapter | 369 | var chapters []models.Chapter |
| @@ -371,7 +371,7 @@ func FetchChapters(c *gin.Context) { | |||
| 371 | for rows.Next() { | 371 | for rows.Next() { |
| 372 | var chapter models.Chapter | 372 | var chapter models.Chapter |
| 373 | if err := rows.Scan(&chapter.ID, &chapter.Name, &gameName); err != nil { | 373 | if err := rows.Scan(&chapter.ID, &chapter.Name, &gameName); err != nil { |
| 374 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 374 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 375 | return | 375 | return |
| 376 | } | 376 | } |
| 377 | chapters = append(chapters, chapter) | 377 | chapters = append(chapters, chapter) |
| @@ -399,13 +399,13 @@ func FetchChapterMaps(c *gin.Context) { | |||
| 399 | chapterID := c.Param("id") | 399 | chapterID := c.Param("id") |
| 400 | intID, err := strconv.Atoi(chapterID) | 400 | intID, err := strconv.Atoi(chapterID) |
| 401 | if err != nil { | 401 | if err != nil { |
| 402 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 402 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 403 | return | 403 | return |
| 404 | } | 404 | } |
| 405 | var response ChapterMapsResponse | 405 | var response ChapterMapsResponse |
| 406 | rows, err := database.DB.Query(`SELECT m.id, m.name, c.name FROM maps m INNER JOIN chapters c ON m.chapter_id = c.id WHERE chapter_id = $1`, chapterID) | 406 | rows, err := database.DB.Query(`SELECT m.id, m.name, c.name FROM maps m INNER JOIN chapters c ON m.chapter_id = c.id WHERE chapter_id = $1`, chapterID) |
| 407 | if err != nil { | 407 | if err != nil { |
| 408 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 408 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 409 | return | 409 | return |
| 410 | } | 410 | } |
| 411 | var maps []models.MapShort | 411 | var maps []models.MapShort |
| @@ -413,7 +413,7 @@ func FetchChapterMaps(c *gin.Context) { | |||
| 413 | for rows.Next() { | 413 | for rows.Next() { |
| 414 | var mapShort models.MapShort | 414 | var mapShort models.MapShort |
| 415 | if err := rows.Scan(&mapShort.ID, &mapShort.Name, &chapterName); err != nil { | 415 | if err := rows.Scan(&mapShort.ID, &mapShort.Name, &chapterName); err != nil { |
| 416 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 416 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 417 | return | 417 | return |
| 418 | } | 418 | } |
| 419 | maps = append(maps, mapShort) | 419 | maps = append(maps, mapShort) |
diff --git a/backend/handlers/mod.go b/backend/handlers/mod.go index 9e93395..1d04a96 100644 --- a/backend/handlers/mod.go +++ b/backend/handlers/mod.go | |||
| @@ -51,30 +51,30 @@ func CreateMapSummary(c *gin.Context) { | |||
| 51 | // Check if user exists | 51 | // Check if user exists |
| 52 | user, exists := c.Get("user") | 52 | user, exists := c.Get("user") |
| 53 | if !exists { | 53 | if !exists { |
| 54 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 54 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 55 | return | 55 | return |
| 56 | } | 56 | } |
| 57 | mod, exists := c.Get("mod") | 57 | mod, exists := c.Get("mod") |
| 58 | if !exists || !mod.(bool) { | 58 | if !exists || !mod.(bool) { |
| 59 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) | 59 | c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) |
| 60 | return | 60 | return |
| 61 | } | 61 | } |
| 62 | // Bind parameter and body | 62 | // Bind parameter and body |
| 63 | id := c.Param("id") | 63 | id := c.Param("id") |
| 64 | mapID, err := strconv.Atoi(id) | 64 | mapID, err := strconv.Atoi(id) |
| 65 | if err != nil { | 65 | if err != nil { |
| 66 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 66 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 67 | return | 67 | return |
| 68 | } | 68 | } |
| 69 | var request CreateMapSummaryRequest | 69 | var request CreateMapSummaryRequest |
| 70 | if err := c.BindJSON(&request); err != nil { | 70 | if err := c.BindJSON(&request); err != nil { |
| 71 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 71 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 72 | return | 72 | return |
| 73 | } | 73 | } |
| 74 | // Start database transaction | 74 | // Start database transaction |
| 75 | tx, err := database.DB.Begin() | 75 | tx, err := database.DB.Begin() |
| 76 | if err != nil { | 76 | if err != nil { |
| 77 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 77 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 78 | return | 78 | return |
| 79 | } | 79 | } |
| 80 | defer tx.Rollback() | 80 | defer tx.Rollback() |
| @@ -83,11 +83,11 @@ func CreateMapSummary(c *gin.Context) { | |||
| 83 | sql := `SELECT m.id FROM maps m WHERE m.id = $1` | 83 | sql := `SELECT m.id FROM maps m WHERE m.id = $1` |
| 84 | err = database.DB.QueryRow(sql, mapID).Scan(&checkMapID) | 84 | err = database.DB.QueryRow(sql, mapID).Scan(&checkMapID) |
| 85 | if err != nil { | 85 | if err != nil { |
| 86 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 86 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 87 | return | 87 | return |
| 88 | } | 88 | } |
| 89 | if mapID != checkMapID { | 89 | if mapID != checkMapID { |
| 90 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map ID does not exist.")) | 90 | c.JSON(http.StatusOK, models.ErrorResponse("Map ID does not exist.")) |
| 91 | return | 91 | return |
| 92 | } | 92 | } |
| 93 | // Update database with new data | 93 | // Update database with new data |
| @@ -95,18 +95,18 @@ func CreateMapSummary(c *gin.Context) { | |||
| 95 | VALUES ($1,$2,$3,$4,$5)` | 95 | VALUES ($1,$2,$3,$4,$5)` |
| 96 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) | 96 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) |
| 97 | if err != nil { | 97 | if err != nil { |
| 98 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 98 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 99 | return | 99 | return |
| 100 | } | 100 | } |
| 101 | sql = `INSERT INTO map_history (map_id,category_id,user_name,score_count,record_date) | 101 | sql = `INSERT INTO map_history (map_id,category_id,user_name,score_count,record_date) |
| 102 | VALUES ($1,$2,$3,$4,$5)` | 102 | VALUES ($1,$2,$3,$4,$5)` |
| 103 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate) | 103 | _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate) |
| 104 | if err != nil { | 104 | if err != nil { |
| 105 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 105 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 106 | return | 106 | return |
| 107 | } | 107 | } |
| 108 | if err = tx.Commit(); err != nil { | 108 | if err = tx.Commit(); err != nil { |
| 109 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 109 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 110 | return | 110 | return |
| 111 | } | 111 | } |
| 112 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreate) | 112 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreate) |
| @@ -132,30 +132,30 @@ func EditMapSummary(c *gin.Context) { | |||
| 132 | // Check if user exists | 132 | // Check if user exists |
| 133 | user, exists := c.Get("user") | 133 | user, exists := c.Get("user") |
| 134 | if !exists { | 134 | if !exists { |
| 135 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 135 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 136 | return | 136 | return |
| 137 | } | 137 | } |
| 138 | mod, exists := c.Get("mod") | 138 | mod, exists := c.Get("mod") |
| 139 | if !exists || !mod.(bool) { | 139 | if !exists || !mod.(bool) { |
| 140 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) | 140 | c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) |
| 141 | return | 141 | return |
| 142 | } | 142 | } |
| 143 | // Bind parameter and body | 143 | // Bind parameter and body |
| 144 | id := c.Param("id") | 144 | id := c.Param("id") |
| 145 | mapID, err := strconv.Atoi(id) | 145 | mapID, err := strconv.Atoi(id) |
| 146 | if err != nil { | 146 | if err != nil { |
| 147 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 147 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 148 | return | 148 | return |
| 149 | } | 149 | } |
| 150 | var request EditMapSummaryRequest | 150 | var request EditMapSummaryRequest |
| 151 | if err := c.BindJSON(&request); err != nil { | 151 | if err := c.BindJSON(&request); err != nil { |
| 152 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 152 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 153 | return | 153 | return |
| 154 | } | 154 | } |
| 155 | // Start database transaction | 155 | // Start database transaction |
| 156 | tx, err := database.DB.Begin() | 156 | tx, err := database.DB.Begin() |
| 157 | if err != nil { | 157 | if err != nil { |
| 158 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 158 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 159 | return | 159 | return |
| 160 | } | 160 | } |
| 161 | defer tx.Rollback() | 161 | defer tx.Rollback() |
| @@ -164,30 +164,30 @@ func EditMapSummary(c *gin.Context) { | |||
| 164 | sql := `SELECT mr.category_id, mr.score_count FROM map_routes mr INNER JOIN maps m ON m.id = mr.map_id WHERE m.id = $1 AND mr.id = $2` | 164 | sql := `SELECT mr.category_id, mr.score_count FROM map_routes mr INNER JOIN maps m ON m.id = mr.map_id WHERE m.id = $1 AND mr.id = $2` |
| 165 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) | 165 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) |
| 166 | if err != nil { | 166 | if err != nil { |
| 167 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 167 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 168 | return | 168 | return |
| 169 | } | 169 | } |
| 170 | sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` | 170 | sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` |
| 171 | err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID) | 171 | err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID) |
| 172 | if err != nil { | 172 | if err != nil { |
| 173 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 173 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 174 | return | 174 | return |
| 175 | } | 175 | } |
| 176 | // Update database with new data | 176 | // Update database with new data |
| 177 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` | 177 | sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` |
| 178 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) | 178 | _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) |
| 179 | if err != nil { | 179 | if err != nil { |
| 180 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 180 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 181 | return | 181 | return |
| 182 | } | 182 | } |
| 183 | sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` | 183 | sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` |
| 184 | _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) | 184 | _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) |
| 185 | if err != nil { | 185 | if err != nil { |
| 186 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 186 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 187 | return | 187 | return |
| 188 | } | 188 | } |
| 189 | if err = tx.Commit(); err != nil { | 189 | if err = tx.Commit(); err != nil { |
| 190 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 190 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 191 | return | 191 | return |
| 192 | } | 192 | } |
| 193 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEdit) | 193 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEdit) |
| @@ -213,30 +213,30 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 213 | // Check if user exists | 213 | // Check if user exists |
| 214 | user, exists := c.Get("user") | 214 | user, exists := c.Get("user") |
| 215 | if !exists { | 215 | if !exists { |
| 216 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 216 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 217 | return | 217 | return |
| 218 | } | 218 | } |
| 219 | mod, exists := c.Get("mod") | 219 | mod, exists := c.Get("mod") |
| 220 | if !exists || !mod.(bool) { | 220 | if !exists || !mod.(bool) { |
| 221 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) | 221 | c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) |
| 222 | return | 222 | return |
| 223 | } | 223 | } |
| 224 | // Bind parameter and body | 224 | // Bind parameter and body |
| 225 | id := c.Param("id") | 225 | id := c.Param("id") |
| 226 | mapID, err := strconv.Atoi(id) | 226 | mapID, err := strconv.Atoi(id) |
| 227 | if err != nil { | 227 | if err != nil { |
| 228 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 228 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 229 | return | 229 | return |
| 230 | } | 230 | } |
| 231 | var request DeleteMapSummaryRequest | 231 | var request DeleteMapSummaryRequest |
| 232 | if err := c.BindJSON(&request); err != nil { | 232 | if err := c.BindJSON(&request); err != nil { |
| 233 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 233 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 234 | return | 234 | return |
| 235 | } | 235 | } |
| 236 | // Start database transaction | 236 | // Start database transaction |
| 237 | tx, err := database.DB.Begin() | 237 | tx, err := database.DB.Begin() |
| 238 | if err != nil { | 238 | if err != nil { |
| 239 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 239 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 240 | return | 240 | return |
| 241 | } | 241 | } |
| 242 | defer tx.Rollback() | 242 | defer tx.Rollback() |
| @@ -245,34 +245,34 @@ func DeleteMapSummary(c *gin.Context) { | |||
| 245 | sql := `SELECT m.id, mr.score_count FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2` | 245 | sql := `SELECT m.id, mr.score_count FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id WHERE m.id = $1 AND mr.id = $2` |
| 246 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount) | 246 | err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount) |
| 247 | if err != nil { | 247 | if err != nil { |
| 248 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 248 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 249 | return | 249 | return |
| 250 | } | 250 | } |
| 251 | if mapID != checkMapID { | 251 | if mapID != checkMapID { |
| 252 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map ID does not exist.")) | 252 | c.JSON(http.StatusOK, models.ErrorResponse("Map ID does not exist.")) |
| 253 | return | 253 | return |
| 254 | } | 254 | } |
| 255 | sql = `SELECT mh.id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id INNER JOIN map_history mh ON m.id=mh.map_id WHERE m.id = $1 AND mr.id = $2 AND mh.score_count = $3` | 255 | sql = `SELECT mh.id FROM maps m INNER JOIN map_routes mr ON m.id=mr.map_id INNER JOIN map_history mh ON m.id=mh.map_id WHERE m.id = $1 AND mr.id = $2 AND mh.score_count = $3` |
| 256 | err = database.DB.QueryRow(sql, mapID, request.RouteID, scoreCount).Scan(&mapHistoryID) | 256 | err = database.DB.QueryRow(sql, mapID, request.RouteID, scoreCount).Scan(&mapHistoryID) |
| 257 | if err != nil { | 257 | if err != nil { |
| 258 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 258 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 259 | return | 259 | return |
| 260 | } | 260 | } |
| 261 | // Update database with new data | 261 | // Update database with new data |
| 262 | sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` | 262 | sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` |
| 263 | _, err = tx.Exec(sql, request.RouteID) | 263 | _, err = tx.Exec(sql, request.RouteID) |
| 264 | if err != nil { | 264 | if err != nil { |
| 265 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 265 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 266 | return | 266 | return |
| 267 | } | 267 | } |
| 268 | sql = `DELETE FROM map_history mh WHERE mh.id = $1` | 268 | sql = `DELETE FROM map_history mh WHERE mh.id = $1` |
| 269 | _, err = tx.Exec(sql, mapHistoryID) | 269 | _, err = tx.Exec(sql, mapHistoryID) |
| 270 | if err != nil { | 270 | if err != nil { |
| 271 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 271 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 272 | return | 272 | return |
| 273 | } | 273 | } |
| 274 | if err = tx.Commit(); err != nil { | 274 | if err = tx.Commit(); err != nil { |
| 275 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 275 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 276 | return | 276 | return |
| 277 | } | 277 | } |
| 278 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDelete) | 278 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDelete) |
| @@ -298,31 +298,31 @@ func EditMapImage(c *gin.Context) { | |||
| 298 | // Check if user exists | 298 | // Check if user exists |
| 299 | user, exists := c.Get("user") | 299 | user, exists := c.Get("user") |
| 300 | if !exists { | 300 | if !exists { |
| 301 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 301 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 302 | return | 302 | return |
| 303 | } | 303 | } |
| 304 | mod, exists := c.Get("mod") | 304 | mod, exists := c.Get("mod") |
| 305 | if !exists || !mod.(bool) { | 305 | if !exists || !mod.(bool) { |
| 306 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) | 306 | c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) |
| 307 | return | 307 | return |
| 308 | } | 308 | } |
| 309 | // Bind parameter and body | 309 | // Bind parameter and body |
| 310 | id := c.Param("id") | 310 | id := c.Param("id") |
| 311 | mapID, err := strconv.Atoi(id) | 311 | mapID, err := strconv.Atoi(id) |
| 312 | if err != nil { | 312 | if err != nil { |
| 313 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 313 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 314 | return | 314 | return |
| 315 | } | 315 | } |
| 316 | var request EditMapImageRequest | 316 | var request EditMapImageRequest |
| 317 | if err := c.BindJSON(&request); err != nil { | 317 | if err := c.BindJSON(&request); err != nil { |
| 318 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 318 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 319 | return | 319 | return |
| 320 | } | 320 | } |
| 321 | // Update database with new data | 321 | // Update database with new data |
| 322 | sql := `UPDATE maps SET image = $2 WHERE id = $1` | 322 | sql := `UPDATE maps SET image = $2 WHERE id = $1` |
| 323 | _, err = database.DB.Exec(sql, mapID, request.Image) | 323 | _, err = database.DB.Exec(sql, mapID, request.Image) |
| 324 | if err != nil { | 324 | if err != nil { |
| 325 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 325 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 326 | return | 326 | return |
| 327 | } | 327 | } |
| 328 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditImage) | 328 | CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEditImage) |
diff --git a/backend/handlers/record.go b/backend/handlers/record.go index 3d29eb8..75b5583 100644 --- a/backend/handlers/record.go +++ b/backend/handlers/record.go | |||
| @@ -52,7 +52,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 52 | // Check if user exists | 52 | // Check if user exists |
| 53 | user, exists := c.Get("user") | 53 | user, exists := c.Get("user") |
| 54 | if !exists { | 54 | if !exists { |
| 55 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 55 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 56 | return | 56 | return |
| 57 | } | 57 | } |
| 58 | // Check if map is sp or mp | 58 | // Check if map is sp or mp |
| @@ -62,12 +62,12 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 62 | sql := `SELECT g.name, m.is_disabled FROM maps m INNER JOIN games g ON m.game_id=g.id WHERE m.id = $1` | 62 | sql := `SELECT g.name, m.is_disabled FROM maps m INNER JOIN games g ON m.game_id=g.id WHERE m.id = $1` |
| 63 | err := database.DB.QueryRow(sql, mapId).Scan(&gameName, &isDisabled) | 63 | err := database.DB.QueryRow(sql, mapId).Scan(&gameName, &isDisabled) |
| 64 | if err != nil { | 64 | if err != nil { |
| 65 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 65 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 66 | return | 66 | return |
| 67 | } | 67 | } |
| 68 | if isDisabled { | 68 | if isDisabled { |
| 69 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | 69 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) |
| 70 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) | 70 | c.JSON(http.StatusOK, models.ErrorResponse("Map is not available for competitive boards.")) |
| 71 | return | 71 | return |
| 72 | } | 72 | } |
| 73 | if gameName == "Portal 2 - Cooperative" { | 73 | if gameName == "Portal 2 - Cooperative" { |
| @@ -77,12 +77,12 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 77 | var record RecordRequest | 77 | var record RecordRequest |
| 78 | if err := c.ShouldBind(&record); err != nil { | 78 | if err := c.ShouldBind(&record); err != nil { |
| 79 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | 79 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) |
| 80 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 80 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 81 | return | 81 | return |
| 82 | } | 82 | } |
| 83 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { | 83 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { |
| 84 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | 84 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) |
| 85 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid entry for coop record submission.")) | 85 | c.JSON(http.StatusOK, models.ErrorResponse("Invalid entry for coop record submission.")) |
| 86 | return | 86 | return |
| 87 | } | 87 | } |
| 88 | // Demo files | 88 | // Demo files |
| @@ -95,13 +95,13 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 95 | client := serviceAccount() | 95 | client := serviceAccount() |
| 96 | srv, err := drive.New(client) | 96 | srv, err := drive.New(client) |
| 97 | if err != nil { | 97 | if err != nil { |
| 98 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 98 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 99 | return | 99 | return |
| 100 | } | 100 | } |
| 101 | // Create database transaction for inserts | 101 | // Create database transaction for inserts |
| 102 | tx, err := database.DB.Begin() | 102 | tx, err := database.DB.Begin() |
| 103 | if err != nil { | 103 | if err != nil { |
| 104 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 104 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 105 | return | 105 | return |
| 106 | } | 106 | } |
| 107 | // Defer to a rollback in case anything fails | 107 | // Defer to a rollback in case anything fails |
| @@ -112,27 +112,27 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 112 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") | 112 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") |
| 113 | if err != nil { | 113 | if err != nil { |
| 114 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailSaveDemo) | 114 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailSaveDemo) |
| 115 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 115 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 116 | return | 116 | return |
| 117 | } | 117 | } |
| 118 | defer os.Remove("backend/parser/" + uuid + ".dem") | 118 | defer os.Remove("backend/parser/" + uuid + ".dem") |
| 119 | f, err := os.Open("backend/parser/" + uuid + ".dem") | 119 | f, err := os.Open("backend/parser/" + uuid + ".dem") |
| 120 | if err != nil { | 120 | if err != nil { |
| 121 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailOpenDemo) | 121 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailOpenDemo) |
| 122 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 122 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 123 | return | 123 | return |
| 124 | } | 124 | } |
| 125 | defer f.Close() | 125 | defer f.Close() |
| 126 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) | 126 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) |
| 127 | if err != nil { | 127 | if err != nil { |
| 128 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailCreateDemo) | 128 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailCreateDemo) |
| 129 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 129 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 130 | return | 130 | return |
| 131 | } | 131 | } |
| 132 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") | 132 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") |
| 133 | if err != nil { | 133 | if err != nil { |
| 134 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailProcessDemo) | 134 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailProcessDemo) |
| 135 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 135 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 136 | return | 136 | return |
| 137 | } | 137 | } |
| 138 | if i == 0 { | 138 | if i == 0 { |
| @@ -146,7 +146,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 146 | if err != nil { | 146 | if err != nil { |
| 147 | deleteFile(srv, file.Id) | 147 | deleteFile(srv, file.Id) |
| 148 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertDemo) | 148 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertDemo) |
| 149 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 149 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 150 | return | 150 | return |
| 151 | } | 151 | } |
| 152 | } | 152 | } |
| @@ -168,14 +168,14 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 168 | deleteFile(srv, hostDemoFileID) | 168 | deleteFile(srv, hostDemoFileID) |
| 169 | deleteFile(srv, partnerDemoFileID) | 169 | deleteFile(srv, partnerDemoFileID) |
| 170 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | 170 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) |
| 171 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 171 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 172 | return | 172 | return |
| 173 | } | 173 | } |
| 174 | // If a new world record based on portal count | 174 | // If a new world record based on portal count |
| 175 | // if record.ScoreCount < wrScore { | 175 | // if record.ScoreCount < wrScore { |
| 176 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) | 176 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) |
| 177 | // if err != nil { | 177 | // if err != nil { |
| 178 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 178 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 179 | // return | 179 | // return |
| 180 | // } | 180 | // } |
| 181 | // } | 181 | // } |
| @@ -186,20 +186,20 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 186 | if err != nil { | 186 | if err != nil { |
| 187 | deleteFile(srv, hostDemoFileID) | 187 | deleteFile(srv, hostDemoFileID) |
| 188 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | 188 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) |
| 189 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 189 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 190 | return | 190 | return |
| 191 | } | 191 | } |
| 192 | // If a new world record based on portal count | 192 | // If a new world record based on portal count |
| 193 | // if record.ScoreCount < wrScore { | 193 | // if record.ScoreCount < wrScore { |
| 194 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) | 194 | // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) |
| 195 | // if err != nil { | 195 | // if err != nil { |
| 196 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 196 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 197 | // return | 197 | // return |
| 198 | // } | 198 | // } |
| 199 | // } | 199 | // } |
| 200 | } | 200 | } |
| 201 | if err = tx.Commit(); err != nil { | 201 | if err = tx.Commit(); err != nil { |
| 202 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 202 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 203 | return | 203 | return |
| 204 | } | 204 | } |
| 205 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordSuccess) | 205 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordSuccess) |
| @@ -224,36 +224,36 @@ func DownloadDemoWithID(c *gin.Context) { | |||
| 224 | uuid := c.Query("uuid") | 224 | uuid := c.Query("uuid") |
| 225 | var locationID string | 225 | var locationID string |
| 226 | if uuid == "" { | 226 | if uuid == "" { |
| 227 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid id given.")) | 227 | c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) |
| 228 | return | 228 | return |
| 229 | } | 229 | } |
| 230 | err := database.DB.QueryRow(`SELECT location_id FROM demos WHERE id = $1`, uuid).Scan(&locationID) | 230 | err := database.DB.QueryRow(`SELECT location_id FROM demos WHERE id = $1`, uuid).Scan(&locationID) |
| 231 | if err != nil { | 231 | if err != nil { |
| 232 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 232 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 233 | return | 233 | return |
| 234 | } | 234 | } |
| 235 | if locationID == "" { | 235 | if locationID == "" { |
| 236 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid id given.")) | 236 | c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) |
| 237 | return | 237 | return |
| 238 | } | 238 | } |
| 239 | url := "https://drive.google.com/uc?export=download&id=" + locationID | 239 | url := "https://drive.google.com/uc?export=download&id=" + locationID |
| 240 | fileName := uuid + ".dem" | 240 | fileName := uuid + ".dem" |
| 241 | output, err := os.Create(fileName) | 241 | output, err := os.Create(fileName) |
| 242 | if err != nil { | 242 | if err != nil { |
| 243 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 243 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 244 | return | 244 | return |
| 245 | } | 245 | } |
| 246 | defer os.Remove(fileName) | 246 | defer os.Remove(fileName) |
| 247 | defer output.Close() | 247 | defer output.Close() |
| 248 | response, err := http.Get(url) | 248 | response, err := http.Get(url) |
| 249 | if err != nil { | 249 | if err != nil { |
| 250 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 250 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 251 | return | 251 | return |
| 252 | } | 252 | } |
| 253 | defer response.Body.Close() | 253 | defer response.Body.Close() |
| 254 | _, err = io.Copy(output, response.Body) | 254 | _, err = io.Copy(output, response.Body) |
| 255 | if err != nil { | 255 | if err != nil { |
| 256 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 256 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 257 | return | 257 | return |
| 258 | } | 258 | } |
| 259 | // Downloaded file | 259 | // Downloaded file |
diff --git a/backend/handlers/user.go b/backend/handlers/user.go index 742a57c..2df2040 100644 --- a/backend/handlers/user.go +++ b/backend/handlers/user.go | |||
| @@ -70,7 +70,7 @@ func Profile(c *gin.Context) { | |||
| 70 | // Check if user exists | 70 | // Check if user exists |
| 71 | user, exists := c.Get("user") | 71 | user, exists := c.Get("user") |
| 72 | if !exists { | 72 | if !exists { |
| 73 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 73 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 74 | return | 74 | return |
| 75 | } | 75 | } |
| 76 | // Get user links | 76 | // Get user links |
| @@ -78,7 +78,7 @@ func Profile(c *gin.Context) { | |||
| 78 | sql := `SELECT u.p2sr, u.steam, u.youtube, u.twitch FROM users u WHERE u.steam_id = $1` | 78 | sql := `SELECT u.p2sr, u.steam, u.youtube, u.twitch FROM users u WHERE u.steam_id = $1` |
| 79 | err := database.DB.QueryRow(sql, user.(models.User).SteamID).Scan(&links.P2SR, &links.Steam, &links.YouTube, &links.Twitch) | 79 | err := database.DB.QueryRow(sql, user.(models.User).SteamID).Scan(&links.P2SR, &links.Steam, &links.YouTube, &links.Twitch) |
| 80 | if err != nil { | 80 | if err != nil { |
| 81 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 81 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 82 | return | 82 | return |
| 83 | } | 83 | } |
| 84 | // Get rankings (all maps done in one game) | 84 | // Get rankings (all maps done in one game) |
| @@ -91,7 +91,7 @@ func Profile(c *gin.Context) { | |||
| 91 | sql = `SELECT count(id), (SELECT count(id) FROM maps m WHERE m.game_id = 2 AND m.is_disabled = false) FROM maps m WHERE m.game_id = 1 AND m.is_disabled = false;` | 91 | sql = `SELECT count(id), (SELECT count(id) FROM maps m WHERE m.game_id = 2 AND m.is_disabled = false) FROM maps m WHERE m.game_id = 1 AND m.is_disabled = false;` |
| 92 | err = database.DB.QueryRow(sql).Scan(&rankings.Singleplayer.CompletionTotal, &rankings.Cooperative.CompletionTotal) | 92 | err = database.DB.QueryRow(sql).Scan(&rankings.Singleplayer.CompletionTotal, &rankings.Cooperative.CompletionTotal) |
| 93 | if err != nil { | 93 | if err != nil { |
| 94 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 94 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 95 | return | 95 | return |
| 96 | } | 96 | } |
| 97 | rankings.Overall.CompletionTotal = rankings.Singleplayer.CompletionTotal + rankings.Cooperative.CompletionTotal | 97 | rankings.Overall.CompletionTotal = rankings.Singleplayer.CompletionTotal + rankings.Cooperative.CompletionTotal |
| @@ -111,7 +111,7 @@ func Profile(c *gin.Context) { | |||
| 111 | WHERE rm.host_id = $1 OR rm.partner_id = $1;` | 111 | WHERE rm.host_id = $1 OR rm.partner_id = $1;` |
| 112 | rows, err := database.DB.Query(sql, user.(models.User).SteamID) | 112 | rows, err := database.DB.Query(sql, user.(models.User).SteamID) |
| 113 | if err != nil { | 113 | if err != nil { |
| 114 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 114 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 115 | return | 115 | return |
| 116 | } | 116 | } |
| 117 | for rows.Next() { | 117 | for rows.Next() { |
| @@ -119,7 +119,7 @@ func Profile(c *gin.Context) { | |||
| 119 | var completionCount int | 119 | var completionCount int |
| 120 | err = rows.Scan(&tableName, &completionCount) | 120 | err = rows.Scan(&tableName, &completionCount) |
| 121 | if err != nil { | 121 | if err != nil { |
| 122 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 122 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 123 | return | 123 | return |
| 124 | } | 124 | } |
| 125 | if tableName == "records_sp" { | 125 | if tableName == "records_sp" { |
| @@ -142,7 +142,7 @@ func Profile(c *gin.Context) { | |||
| 142 | ORDER BY total_min_score_count ASC;` | 142 | ORDER BY total_min_score_count ASC;` |
| 143 | rows, err = database.DB.Query(sql) | 143 | rows, err = database.DB.Query(sql) |
| 144 | if err != nil { | 144 | if err != nil { |
| 145 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 145 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 146 | return | 146 | return |
| 147 | } | 147 | } |
| 148 | placement := 1 | 148 | placement := 1 |
| @@ -153,7 +153,7 @@ func Profile(c *gin.Context) { | |||
| 153 | var userPortalCount int | 153 | var userPortalCount int |
| 154 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) | 154 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) |
| 155 | if err != nil { | 155 | if err != nil { |
| 156 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 156 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 157 | return | 157 | return |
| 158 | } | 158 | } |
| 159 | if completionCount != totalCount { | 159 | if completionCount != totalCount { |
| @@ -176,7 +176,7 @@ func Profile(c *gin.Context) { | |||
| 176 | ORDER BY total_min_score_count ASC;` | 176 | ORDER BY total_min_score_count ASC;` |
| 177 | rows, err = database.DB.Query(sql) | 177 | rows, err = database.DB.Query(sql) |
| 178 | if err != nil { | 178 | if err != nil { |
| 179 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 179 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 180 | return | 180 | return |
| 181 | } | 181 | } |
| 182 | placement = 1 | 182 | placement = 1 |
| @@ -187,7 +187,7 @@ func Profile(c *gin.Context) { | |||
| 187 | var userPortalCount int | 187 | var userPortalCount int |
| 188 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) | 188 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) |
| 189 | if err != nil { | 189 | if err != nil { |
| 190 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 190 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 191 | return | 191 | return |
| 192 | } | 192 | } |
| 193 | if completionCount != totalCount { | 193 | if completionCount != totalCount { |
| @@ -232,7 +232,7 @@ func Profile(c *gin.Context) { | |||
| 232 | // GROUP BY steam_id ORDER BY total_score ASC;` | 232 | // GROUP BY steam_id ORDER BY total_score ASC;` |
| 233 | // rows, err = database.DB.Query(sql) | 233 | // rows, err = database.DB.Query(sql) |
| 234 | // if err != nil { | 234 | // if err != nil { |
| 235 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 235 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 236 | // return | 236 | // return |
| 237 | // } | 237 | // } |
| 238 | // placement = 1 | 238 | // placement = 1 |
| @@ -241,7 +241,7 @@ func Profile(c *gin.Context) { | |||
| 241 | // var userPortalCount int | 241 | // var userPortalCount int |
| 242 | // err = rows.Scan(&steamID, &userPortalCount) | 242 | // err = rows.Scan(&steamID, &userPortalCount) |
| 243 | // if err != nil { | 243 | // if err != nil { |
| 244 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 244 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 245 | // return | 245 | // return |
| 246 | // } | 246 | // } |
| 247 | // if completionCount != totalCount { | 247 | // if completionCount != totalCount { |
| @@ -261,7 +261,7 @@ func Profile(c *gin.Context) { | |||
| 261 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 ORDER BY sp.map_id, sp.score_count, sp.score_time;` | 261 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 ORDER BY sp.map_id, sp.score_count, sp.score_time;` |
| 262 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) | 262 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) |
| 263 | if err != nil { | 263 | if err != nil { |
| 264 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 264 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 265 | return | 265 | return |
| 266 | } | 266 | } |
| 267 | for rows.Next() { | 267 | for rows.Next() { |
| @@ -293,7 +293,7 @@ func Profile(c *gin.Context) { | |||
| 293 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE mp.host_id = $1 OR mp.partner_id = $1 ORDER BY mp.map_id, mp.score_count, mp.score_time;` | 293 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE mp.host_id = $1 OR mp.partner_id = $1 ORDER BY mp.map_id, mp.score_count, mp.score_time;` |
| 294 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) | 294 | rows, err = database.DB.Query(sql, user.(models.User).SteamID) |
| 295 | if err != nil { | 295 | if err != nil { |
| 296 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 296 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 297 | return | 297 | return |
| 298 | } | 298 | } |
| 299 | for rows.Next() { | 299 | for rows.Next() { |
| @@ -353,7 +353,7 @@ func FetchUser(c *gin.Context) { | |||
| 353 | // Check if id is all numbers and 17 length | 353 | // Check if id is all numbers and 17 length |
| 354 | match, _ := regexp.MatchString("^[0-9]{17}$", id) | 354 | match, _ := regexp.MatchString("^[0-9]{17}$", id) |
| 355 | if !match { | 355 | if !match { |
| 356 | c.JSON(http.StatusNotFound, models.ErrorResponse("User not found.")) | 356 | c.JSON(http.StatusOK, models.ErrorResponse("User not found.")) |
| 357 | return | 357 | return |
| 358 | } | 358 | } |
| 359 | // Check if user exists | 359 | // Check if user exists |
| @@ -362,12 +362,12 @@ func FetchUser(c *gin.Context) { | |||
| 362 | sql := `SELECT u.steam_id, u.user_name, u.avatar_link, u.country_code, u.created_at, u.updated_at, u.p2sr, u.steam, u.youtube, u.twitch FROM users u WHERE u.steam_id = $1` | 362 | sql := `SELECT u.steam_id, u.user_name, u.avatar_link, u.country_code, u.created_at, u.updated_at, u.p2sr, u.steam, u.youtube, u.twitch FROM users u WHERE u.steam_id = $1` |
| 363 | err := database.DB.QueryRow(sql, id).Scan(&user.SteamID, &user.UserName, &user.AvatarLink, &user.CountryCode, &user.CreatedAt, &user.UpdatedAt, &links.P2SR, &links.Steam, &links.YouTube, &links.Twitch) | 363 | err := database.DB.QueryRow(sql, id).Scan(&user.SteamID, &user.UserName, &user.AvatarLink, &user.CountryCode, &user.CreatedAt, &user.UpdatedAt, &links.P2SR, &links.Steam, &links.YouTube, &links.Twitch) |
| 364 | if err != nil { | 364 | if err != nil { |
| 365 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 365 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 366 | return | 366 | return |
| 367 | } | 367 | } |
| 368 | if user.SteamID == "" { | 368 | if user.SteamID == "" { |
| 369 | // User does not exist | 369 | // User does not exist |
| 370 | c.JSON(http.StatusNotFound, models.ErrorResponse("User not found.")) | 370 | c.JSON(http.StatusOK, models.ErrorResponse("User not found.")) |
| 371 | return | 371 | return |
| 372 | } | 372 | } |
| 373 | // Get rankings (all maps done in one game) | 373 | // Get rankings (all maps done in one game) |
| @@ -380,7 +380,7 @@ func FetchUser(c *gin.Context) { | |||
| 380 | sql = `SELECT count(id), (SELECT count(id) FROM maps m WHERE m.game_id = 2 AND m.is_disabled = false) FROM maps m WHERE m.game_id = 1 AND m.is_disabled = false;` | 380 | sql = `SELECT count(id), (SELECT count(id) FROM maps m WHERE m.game_id = 2 AND m.is_disabled = false) FROM maps m WHERE m.game_id = 1 AND m.is_disabled = false;` |
| 381 | err = database.DB.QueryRow(sql).Scan(&rankings.Singleplayer.CompletionTotal, &rankings.Cooperative.CompletionTotal) | 381 | err = database.DB.QueryRow(sql).Scan(&rankings.Singleplayer.CompletionTotal, &rankings.Cooperative.CompletionTotal) |
| 382 | if err != nil { | 382 | if err != nil { |
| 383 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 383 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 384 | return | 384 | return |
| 385 | } | 385 | } |
| 386 | rankings.Overall.CompletionTotal = rankings.Singleplayer.CompletionTotal + rankings.Cooperative.CompletionTotal | 386 | rankings.Overall.CompletionTotal = rankings.Singleplayer.CompletionTotal + rankings.Cooperative.CompletionTotal |
| @@ -400,7 +400,7 @@ func FetchUser(c *gin.Context) { | |||
| 400 | WHERE rm.host_id = $1 OR rm.partner_id = $1;` | 400 | WHERE rm.host_id = $1 OR rm.partner_id = $1;` |
| 401 | rows, err := database.DB.Query(sql, user.SteamID) | 401 | rows, err := database.DB.Query(sql, user.SteamID) |
| 402 | if err != nil { | 402 | if err != nil { |
| 403 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 403 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 404 | return | 404 | return |
| 405 | } | 405 | } |
| 406 | for rows.Next() { | 406 | for rows.Next() { |
| @@ -408,7 +408,7 @@ func FetchUser(c *gin.Context) { | |||
| 408 | var completionCount int | 408 | var completionCount int |
| 409 | err = rows.Scan(&tableName, &completionCount) | 409 | err = rows.Scan(&tableName, &completionCount) |
| 410 | if err != nil { | 410 | if err != nil { |
| 411 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 411 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 412 | return | 412 | return |
| 413 | } | 413 | } |
| 414 | if tableName == "records_sp" { | 414 | if tableName == "records_sp" { |
| @@ -431,7 +431,7 @@ func FetchUser(c *gin.Context) { | |||
| 431 | ORDER BY total_min_score_count ASC;` | 431 | ORDER BY total_min_score_count ASC;` |
| 432 | rows, err = database.DB.Query(sql) | 432 | rows, err = database.DB.Query(sql) |
| 433 | if err != nil { | 433 | if err != nil { |
| 434 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 434 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 435 | return | 435 | return |
| 436 | } | 436 | } |
| 437 | placement := 1 | 437 | placement := 1 |
| @@ -442,7 +442,7 @@ func FetchUser(c *gin.Context) { | |||
| 442 | var userPortalCount int | 442 | var userPortalCount int |
| 443 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) | 443 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) |
| 444 | if err != nil { | 444 | if err != nil { |
| 445 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 445 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 446 | return | 446 | return |
| 447 | } | 447 | } |
| 448 | if completionCount != totalCount { | 448 | if completionCount != totalCount { |
| @@ -465,7 +465,7 @@ func FetchUser(c *gin.Context) { | |||
| 465 | ORDER BY total_min_score_count ASC;` | 465 | ORDER BY total_min_score_count ASC;` |
| 466 | rows, err = database.DB.Query(sql) | 466 | rows, err = database.DB.Query(sql) |
| 467 | if err != nil { | 467 | if err != nil { |
| 468 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 468 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 469 | return | 469 | return |
| 470 | } | 470 | } |
| 471 | placement = 1 | 471 | placement = 1 |
| @@ -476,7 +476,7 @@ func FetchUser(c *gin.Context) { | |||
| 476 | var userPortalCount int | 476 | var userPortalCount int |
| 477 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) | 477 | err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) |
| 478 | if err != nil { | 478 | if err != nil { |
| 479 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 479 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 480 | return | 480 | return |
| 481 | } | 481 | } |
| 482 | if completionCount != totalCount { | 482 | if completionCount != totalCount { |
| @@ -521,7 +521,7 @@ func FetchUser(c *gin.Context) { | |||
| 521 | // GROUP BY steam_id ORDER BY total_score ASC;` | 521 | // GROUP BY steam_id ORDER BY total_score ASC;` |
| 522 | // rows, err = database.DB.Query(sql) | 522 | // rows, err = database.DB.Query(sql) |
| 523 | // if err != nil { | 523 | // if err != nil { |
| 524 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 524 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 525 | // return | 525 | // return |
| 526 | // } | 526 | // } |
| 527 | // placement = 1 | 527 | // placement = 1 |
| @@ -530,7 +530,7 @@ func FetchUser(c *gin.Context) { | |||
| 530 | // var userPortalCount int | 530 | // var userPortalCount int |
| 531 | // err = rows.Scan(&steamID, &userPortalCount) | 531 | // err = rows.Scan(&steamID, &userPortalCount) |
| 532 | // if err != nil { | 532 | // if err != nil { |
| 533 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 533 | // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 534 | // return | 534 | // return |
| 535 | // } | 535 | // } |
| 536 | // if completionCount != totalCount { | 536 | // if completionCount != totalCount { |
| @@ -550,7 +550,7 @@ func FetchUser(c *gin.Context) { | |||
| 550 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 ORDER BY sp.map_id, sp.score_count, sp.score_time;` | 550 | FROM records_sp sp INNER JOIN maps m ON sp.map_id = m.id WHERE sp.user_id = $1 ORDER BY sp.map_id, sp.score_count, sp.score_time;` |
| 551 | rows, err = database.DB.Query(sql, user.SteamID) | 551 | rows, err = database.DB.Query(sql, user.SteamID) |
| 552 | if err != nil { | 552 | if err != nil { |
| 553 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 553 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 554 | return | 554 | return |
| 555 | } | 555 | } |
| 556 | for rows.Next() { | 556 | for rows.Next() { |
| @@ -582,7 +582,7 @@ func FetchUser(c *gin.Context) { | |||
| 582 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE mp.host_id = $1 OR mp.partner_id = $1 ORDER BY mp.map_id, mp.score_count, mp.score_time;` | 582 | FROM records_mp mp INNER JOIN maps m ON mp.map_id = m.id WHERE mp.host_id = $1 OR mp.partner_id = $1 ORDER BY mp.map_id, mp.score_count, mp.score_time;` |
| 583 | rows, err = database.DB.Query(sql, user.SteamID) | 583 | rows, err = database.DB.Query(sql, user.SteamID) |
| 584 | if err != nil { | 584 | if err != nil { |
| 585 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 585 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 586 | return | 586 | return |
| 587 | } | 587 | } |
| 588 | for rows.Next() { | 588 | for rows.Next() { |
| @@ -641,13 +641,13 @@ func UpdateUser(c *gin.Context) { | |||
| 641 | // Check if user exists | 641 | // Check if user exists |
| 642 | user, exists := c.Get("user") | 642 | user, exists := c.Get("user") |
| 643 | if !exists { | 643 | if !exists { |
| 644 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 644 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 645 | return | 645 | return |
| 646 | } | 646 | } |
| 647 | profile, err := GetPlayerSummaries(user.(models.User).SteamID, os.Getenv("API_KEY")) | 647 | profile, err := GetPlayerSummaries(user.(models.User).SteamID, os.Getenv("API_KEY")) |
| 648 | if err != nil { | 648 | if err != nil { |
| 649 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSummaryFail) | 649 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSummaryFail) |
| 650 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 650 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 651 | return | 651 | return |
| 652 | } | 652 | } |
| 653 | // Update profile | 653 | // Update profile |
| @@ -655,7 +655,7 @@ func UpdateUser(c *gin.Context) { | |||
| 655 | WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) | 655 | WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) |
| 656 | if err != nil { | 656 | if err != nil { |
| 657 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateFail) | 657 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateFail) |
| 658 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 658 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 659 | return | 659 | return |
| 660 | } | 660 | } |
| 661 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSuccess) | 661 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSuccess) |
| @@ -688,27 +688,27 @@ func UpdateCountryCode(c *gin.Context) { | |||
| 688 | // Check if user exists | 688 | // Check if user exists |
| 689 | user, exists := c.Get("user") | 689 | user, exists := c.Get("user") |
| 690 | if !exists { | 690 | if !exists { |
| 691 | c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) | 691 | c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) |
| 692 | return | 692 | return |
| 693 | } | 693 | } |
| 694 | code := c.Query("country_code") | 694 | code := c.Query("country_code") |
| 695 | if code == "" { | 695 | if code == "" { |
| 696 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) | 696 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) |
| 697 | c.JSON(http.StatusNotFound, models.ErrorResponse("Enter a valid country code.")) | 697 | c.JSON(http.StatusOK, models.ErrorResponse("Enter a valid country code.")) |
| 698 | return | 698 | return |
| 699 | } | 699 | } |
| 700 | var validCode string | 700 | var validCode string |
| 701 | err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1`, code).Scan(&validCode) | 701 | err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1`, code).Scan(&validCode) |
| 702 | if err != nil { | 702 | if err != nil { |
| 703 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) | 703 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) |
| 704 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) | 704 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 705 | return | 705 | return |
| 706 | } | 706 | } |
| 707 | // Valid code, update profile | 707 | // Valid code, update profile |
| 708 | _, err = database.DB.Exec(`UPDATE users SET country_code = $1 WHERE steam_id = $2`, validCode, user.(models.User).SteamID) | 708 | _, err = database.DB.Exec(`UPDATE users SET country_code = $1 WHERE steam_id = $2`, validCode, user.(models.User).SteamID) |
| 709 | if err != nil { | 709 | if err != nil { |
| 710 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) | 710 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) |
| 711 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) | 711 | c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) |
| 712 | return | 712 | return |
| 713 | } | 713 | } |
| 714 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountrySuccess) | 714 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountrySuccess) |