From 3cda2073cc29317d6251e7b88102b70659aed6d6 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:48:43 +0300 Subject: fix: change all status codes to 200 (#66) Former-commit-id: ae632415e3f6f79a462240f151ada2e428318c6b --- backend/handlers/home.go | 10 +++---- backend/handlers/login.go | 10 +++---- backend/handlers/logs.go | 10 +++---- backend/handlers/map.go | 46 ++++++++++++++--------------- backend/handlers/mod.go | 72 +++++++++++++++++++++++----------------------- backend/handlers/record.go | 46 ++++++++++++++--------------- backend/handlers/user.go | 68 +++++++++++++++++++++---------------------- 7 files changed, 131 insertions(+), 131 deletions(-) (limited to 'backend') 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) { FROM records_sp sp JOIN users u ON u.steam_id = sp.user_id GROUP BY u.steam_id, u.user_name` rows, err := database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -59,7 +59,7 @@ func Rankings(c *gin.Context) { var totalCount int err = rows.Scan(&ranking.User.SteamID, &ranking.User.UserName, ¤tCount, &totalCount, &ranking.TotalScore) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if currentCount != totalCount { @@ -82,7 +82,7 @@ func Rankings(c *gin.Context) { 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` rows, err = database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -91,7 +91,7 @@ func Rankings(c *gin.Context) { var totalCount int err = rows.Scan(&ranking.User.SteamID, &ranking.User.UserName, ¤tCount, &totalCount, &ranking.TotalScore) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if currentCount != totalCount { @@ -273,7 +273,7 @@ func SearchWithQuery(c *gin.Context) { for rows.Next() { var user models.UserShort if err := rows.Scan(&user.SteamID, &user.UserName); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } 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) { steamID, err := openID.ValidateAndGetId() if err != nil { CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailValidate) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Create user if new @@ -50,7 +50,7 @@ func Login(c *gin.Context) { user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) if err != nil { CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailSummary) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Empty country code check @@ -80,7 +80,7 @@ func Login(c *gin.Context) { tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) if err != nil { CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailToken) - c.JSON(http.StatusBadRequest, models.ErrorResponse("Failed to generate token.")) + c.JSON(http.StatusOK, models.ErrorResponse("Failed to generate token.")) return } c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true) @@ -109,7 +109,7 @@ func Login(c *gin.Context) { func GetCookie(c *gin.Context) { cookie, err := c.Cookie("token") if err != nil { - c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found.")) + c.JSON(http.StatusOK, models.ErrorResponse("No token cookie found.")) return } c.JSON(http.StatusOK, models.Response{ @@ -133,7 +133,7 @@ func GetCookie(c *gin.Context) { func DeleteCookie(c *gin.Context) { cookie, err := c.Cookie("token") if err != nil { - c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found.")) + c.JSON(http.StatusOK, models.ErrorResponse("No token cookie found.")) return } 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 { func ModLogs(c *gin.Context) { mod, exists := c.Get("mod") if !exists || !mod.(bool) { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) + c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) return } response := LogsResponse{Logs: []LogsResponseDetails{}} @@ -92,14 +92,14 @@ func ModLogs(c *gin.Context) { ORDER BY l.date DESC LIMIT 100;` rows, err := database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { log := Log{} err = rows.Scan(&log.User.UserName, &log.User.SteamID, &log.Type, &log.Description, &log.Date) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } detail := fmt.Sprintf("%s.%s", log.Type, log.Description) @@ -160,14 +160,14 @@ func ScoreLogs(c *gin.Context) { ORDER BY rs.record_date DESC LIMIT 100;` rows, err := database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { score := ScoreLogsResponseDetails{} 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) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } 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) { response := MapSummaryResponse{Map: models.Map{}, Summary: models.MapSummary{Routes: []models.MapRoute{}}} intID, err := strconv.Atoi(id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Get map data @@ -79,7 +79,7 @@ func FetchMapSummary(c *gin.Context) { WHERE m.id = $1` 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) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Get map routes and histories @@ -91,14 +91,14 @@ func FetchMapSummary(c *gin.Context) { ORDER BY h.record_date ASC;` rows, err := database.DB.Query(sql, id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { route := models.MapRoute{Category: models.Category{}, History: models.MapHistory{}} err = rows.Scan(&route.RouteID, &route.Category.ID, &route.Category.Name, &route.History.RunnerName, &route.History.ScoreCount, &route.History.Date, &route.Description, &route.Showcase, &route.Rating) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Get completion count @@ -109,7 +109,7 @@ func FetchMapSummary(c *gin.Context) { ) sub WHERE sub.rn = 1 AND score_count = $2` err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } } else { @@ -119,7 +119,7 @@ func FetchMapSummary(c *gin.Context) { ) sub WHERE rn = 1 AND score_count = $2` err = database.DB.QueryRow(sql, response.Map.ID, route.History.ScoreCount).Scan(&route.CompletionCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } } @@ -159,7 +159,7 @@ func FetchMapLeaderboards(c *gin.Context) { var isDisabled bool intID, err := strconv.Atoi(id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } response.Map.ID = intID @@ -170,11 +170,11 @@ func FetchMapLeaderboards(c *gin.Context) { WHERE m.id = $1` err = database.DB.QueryRow(sql, id).Scan(&response.Map.GameName, &response.Map.ChapterName, &response.Map.MapName, &isDisabled, &response.Map.Image, &response.Map.IsCoop) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if isDisabled { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) + c.JSON(http.StatusOK, models.ErrorResponse("Map is not available for competitive boards.")) return } totalRecords := 0 @@ -214,7 +214,7 @@ func FetchMapLeaderboards(c *gin.Context) { ORDER BY score_count, score_time` rows, err := database.DB.Query(sql, id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } placement := 1 @@ -223,7 +223,7 @@ func FetchMapLeaderboards(c *gin.Context) { var record RecordMultiplayer 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) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } 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) { if totalRecords != 0 { totalPages = (totalRecords + pageSize - 1) / pageSize if page > totalPages { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid page number.")) + c.JSON(http.StatusOK, models.ErrorResponse("Invalid page number.")) return } startIndex := (page - 1) * pageSize @@ -264,7 +264,7 @@ func FetchMapLeaderboards(c *gin.Context) { ORDER BY score_count, score_time` rows, err := database.DB.Query(sql, id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } placement := 1 @@ -273,7 +273,7 @@ func FetchMapLeaderboards(c *gin.Context) { var record RecordSingleplayer err := rows.Scan(&record.RecordID, &record.User.SteamID, &record.User.UserName, &record.User.AvatarLink, &record.ScoreCount, &record.ScoreTime, &record.DemoID, &record.RecordDate) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } 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) { if totalRecords != 0 { totalPages = (totalRecords + pageSize - 1) / pageSize if page > totalPages { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid page number.")) + c.JSON(http.StatusOK, models.ErrorResponse("Invalid page number.")) return } startIndex := (page - 1) * pageSize @@ -325,14 +325,14 @@ func FetchMapLeaderboards(c *gin.Context) { func FetchGames(c *gin.Context) { rows, err := database.DB.Query(`SELECT id, name, is_coop FROM games`) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var games []models.Game for rows.Next() { var game models.Game if err := rows.Scan(&game.ID, &game.Name, &game.IsCoop); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } games = append(games, game) @@ -357,13 +357,13 @@ func FetchChapters(c *gin.Context) { gameID := c.Param("id") intID, err := strconv.Atoi(gameID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var response ChaptersResponse 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) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var chapters []models.Chapter @@ -371,7 +371,7 @@ func FetchChapters(c *gin.Context) { for rows.Next() { var chapter models.Chapter if err := rows.Scan(&chapter.ID, &chapter.Name, &gameName); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } chapters = append(chapters, chapter) @@ -399,13 +399,13 @@ func FetchChapterMaps(c *gin.Context) { chapterID := c.Param("id") intID, err := strconv.Atoi(chapterID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var response ChapterMapsResponse 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) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var maps []models.MapShort @@ -413,7 +413,7 @@ func FetchChapterMaps(c *gin.Context) { for rows.Next() { var mapShort models.MapShort if err := rows.Scan(&mapShort.ID, &mapShort.Name, &chapterName); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } 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) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } mod, exists := c.Get("mod") if !exists || !mod.(bool) { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) + c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) return } // Bind parameter and body id := c.Param("id") mapID, err := strconv.Atoi(id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var request CreateMapSummaryRequest if err := c.BindJSON(&request); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Start database transaction tx, err := database.DB.Begin() if err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } defer tx.Rollback() @@ -83,11 +83,11 @@ func CreateMapSummary(c *gin.Context) { sql := `SELECT m.id FROM maps m WHERE m.id = $1` err = database.DB.QueryRow(sql, mapID).Scan(&checkMapID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if mapID != checkMapID { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Map ID does not exist.")) + c.JSON(http.StatusOK, models.ErrorResponse("Map ID does not exist.")) return } // Update database with new data @@ -95,18 +95,18 @@ func CreateMapSummary(c *gin.Context) { VALUES ($1,$2,$3,$4,$5)` _, err = tx.Exec(sql, mapID, request.CategoryID, request.ScoreCount, request.Description, request.Showcase) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } sql = `INSERT INTO map_history (map_id,category_id,user_name,score_count,record_date) VALUES ($1,$2,$3,$4,$5)` _, err = tx.Exec(sql, mapID, request.CategoryID, request.UserName, request.ScoreCount, request.RecordDate) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if err = tx.Commit(); err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryCreate) @@ -132,30 +132,30 @@ func EditMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } mod, exists := c.Get("mod") if !exists || !mod.(bool) { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) + c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) return } // Bind parameter and body id := c.Param("id") mapID, err := strconv.Atoi(id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var request EditMapSummaryRequest if err := c.BindJSON(&request); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Start database transaction tx, err := database.DB.Begin() if err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } defer tx.Rollback() @@ -164,30 +164,30 @@ func EditMapSummary(c *gin.Context) { 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` err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&categoryID, &scoreCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } sql = `SELECT mh.id FROM map_history mh WHERE mh.score_count = $1 AND mh.category_id = $2 AND mh.map_id = $3` err = database.DB.QueryRow(sql, scoreCount, categoryID, mapID).Scan(&historyID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Update database with new data sql = `UPDATE map_routes SET score_count = $2, description = $3, showcase = $4 WHERE id = $1` _, err = tx.Exec(sql, request.RouteID, request.ScoreCount, request.Description, request.Showcase) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } sql = `UPDATE map_history SET user_name = $2, score_count = $3, record_date = $4 WHERE id = $1` _, err = tx.Exec(sql, historyID, request.UserName, request.ScoreCount, request.RecordDate) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if err = tx.Commit(); err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryEdit) @@ -213,30 +213,30 @@ func DeleteMapSummary(c *gin.Context) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } mod, exists := c.Get("mod") if !exists || !mod.(bool) { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) + c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) return } // Bind parameter and body id := c.Param("id") mapID, err := strconv.Atoi(id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var request DeleteMapSummaryRequest if err := c.BindJSON(&request); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Start database transaction tx, err := database.DB.Begin() if err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } defer tx.Rollback() @@ -245,34 +245,34 @@ func DeleteMapSummary(c *gin.Context) { 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` err = database.DB.QueryRow(sql, mapID, request.RouteID).Scan(&checkMapID, &scoreCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if mapID != checkMapID { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Map ID does not exist.")) + c.JSON(http.StatusOK, models.ErrorResponse("Map ID does not exist.")) return } 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` err = database.DB.QueryRow(sql, mapID, request.RouteID, scoreCount).Scan(&mapHistoryID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Update database with new data sql = `DELETE FROM map_routes mr WHERE mr.id = $1 ` _, err = tx.Exec(sql, request.RouteID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } sql = `DELETE FROM map_history mh WHERE mh.id = $1` _, err = tx.Exec(sql, mapHistoryID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if err = tx.Commit(); err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } CreateLog(user.(models.User).SteamID, LogTypeMod, LogDescriptionMapSummaryDelete) @@ -298,31 +298,31 @@ func EditMapImage(c *gin.Context) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } mod, exists := c.Get("mod") if !exists || !mod.(bool) { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("Insufficient permissions.")) + c.JSON(http.StatusOK, models.ErrorResponse("Insufficient permissions.")) return } // Bind parameter and body id := c.Param("id") mapID, err := strconv.Atoi(id) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } var request EditMapImageRequest if err := c.BindJSON(&request); err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Update database with new data sql := `UPDATE maps SET image = $2 WHERE id = $1` _, err = database.DB.Exec(sql, mapID, request.Image) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } 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) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } // Check if map is sp or mp @@ -62,12 +62,12 @@ func CreateRecordWithDemo(c *gin.Context) { sql := `SELECT g.name, m.is_disabled FROM maps m INNER JOIN games g ON m.game_id=g.id WHERE m.id = $1` err := database.DB.QueryRow(sql, mapId).Scan(&gameName, &isDisabled) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if isDisabled { CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) - c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) + c.JSON(http.StatusOK, models.ErrorResponse("Map is not available for competitive boards.")) return } if gameName == "Portal 2 - Cooperative" { @@ -77,12 +77,12 @@ func CreateRecordWithDemo(c *gin.Context) { var record RecordRequest if err := c.ShouldBind(&record); err != nil { CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) - c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid entry for coop record submission.")) + c.JSON(http.StatusOK, models.ErrorResponse("Invalid entry for coop record submission.")) return } // Demo files @@ -95,13 +95,13 @@ func CreateRecordWithDemo(c *gin.Context) { client := serviceAccount() srv, err := drive.New(client) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Create database transaction for inserts tx, err := database.DB.Begin() if err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Defer to a rollback in case anything fails @@ -112,27 +112,27 @@ func CreateRecordWithDemo(c *gin.Context) { err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") if err != nil { CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailSaveDemo) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } defer os.Remove("backend/parser/" + uuid + ".dem") f, err := os.Open("backend/parser/" + uuid + ".dem") if err != nil { CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailOpenDemo) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } defer f.Close() file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) if err != nil { CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailCreateDemo) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") if err != nil { CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailProcessDemo) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if i == 0 { @@ -146,7 +146,7 @@ func CreateRecordWithDemo(c *gin.Context) { if err != nil { deleteFile(srv, file.Id) CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertDemo) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } } @@ -168,14 +168,14 @@ func CreateRecordWithDemo(c *gin.Context) { deleteFile(srv, hostDemoFileID) deleteFile(srv, partnerDemoFileID) CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // If a new world record based on portal count // if record.ScoreCount < wrScore { // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) // if err != nil { - // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) // return // } // } @@ -186,20 +186,20 @@ func CreateRecordWithDemo(c *gin.Context) { if err != nil { deleteFile(srv, hostDemoFileID) CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // If a new world record based on portal count // if record.ScoreCount < wrScore { // _, err := tx.Exec(`UPDATE maps SET wr_score = $1, wr_time = $2 WHERE id = $3`, record.ScoreCount, record.ScoreTime, mapId) // if err != nil { - // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) // return // } // } } if err = tx.Commit(); err != nil { - c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordSuccess) @@ -224,36 +224,36 @@ func DownloadDemoWithID(c *gin.Context) { uuid := c.Query("uuid") var locationID string if uuid == "" { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid id given.")) + c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) return } err := database.DB.QueryRow(`SELECT location_id FROM demos WHERE id = $1`, uuid).Scan(&locationID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if locationID == "" { - c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid id given.")) + c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) return } url := "https://drive.google.com/uc?export=download&id=" + locationID fileName := uuid + ".dem" output, err := os.Create(fileName) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } defer os.Remove(fileName) defer output.Close() response, err := http.Get(url) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } defer response.Body.Close() _, err = io.Copy(output, response.Body) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // 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) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } // Get user links @@ -78,7 +78,7 @@ func Profile(c *gin.Context) { sql := `SELECT u.p2sr, u.steam, u.youtube, u.twitch FROM users u WHERE u.steam_id = $1` err := database.DB.QueryRow(sql, user.(models.User).SteamID).Scan(&links.P2SR, &links.Steam, &links.YouTube, &links.Twitch) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Get rankings (all maps done in one game) @@ -91,7 +91,7 @@ func Profile(c *gin.Context) { 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;` err = database.DB.QueryRow(sql).Scan(&rankings.Singleplayer.CompletionTotal, &rankings.Cooperative.CompletionTotal) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } rankings.Overall.CompletionTotal = rankings.Singleplayer.CompletionTotal + rankings.Cooperative.CompletionTotal @@ -111,7 +111,7 @@ func Profile(c *gin.Context) { WHERE rm.host_id = $1 OR rm.partner_id = $1;` rows, err := database.DB.Query(sql, user.(models.User).SteamID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -119,7 +119,7 @@ func Profile(c *gin.Context) { var completionCount int err = rows.Scan(&tableName, &completionCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if tableName == "records_sp" { @@ -142,7 +142,7 @@ func Profile(c *gin.Context) { ORDER BY total_min_score_count ASC;` rows, err = database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } placement := 1 @@ -153,7 +153,7 @@ func Profile(c *gin.Context) { var userPortalCount int err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if completionCount != totalCount { @@ -176,7 +176,7 @@ func Profile(c *gin.Context) { ORDER BY total_min_score_count ASC;` rows, err = database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } placement = 1 @@ -187,7 +187,7 @@ func Profile(c *gin.Context) { var userPortalCount int err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if completionCount != totalCount { @@ -232,7 +232,7 @@ func Profile(c *gin.Context) { // GROUP BY steam_id ORDER BY total_score ASC;` // rows, err = database.DB.Query(sql) // if err != nil { - // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) // return // } // placement = 1 @@ -241,7 +241,7 @@ func Profile(c *gin.Context) { // var userPortalCount int // err = rows.Scan(&steamID, &userPortalCount) // if err != nil { - // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) // return // } // if completionCount != totalCount { @@ -261,7 +261,7 @@ func Profile(c *gin.Context) { 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;` rows, err = database.DB.Query(sql, user.(models.User).SteamID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -293,7 +293,7 @@ func Profile(c *gin.Context) { 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;` rows, err = database.DB.Query(sql, user.(models.User).SteamID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -353,7 +353,7 @@ func FetchUser(c *gin.Context) { // Check if id is all numbers and 17 length match, _ := regexp.MatchString("^[0-9]{17}$", id) if !match { - c.JSON(http.StatusNotFound, models.ErrorResponse("User not found.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not found.")) return } // Check if user exists @@ -362,12 +362,12 @@ func FetchUser(c *gin.Context) { 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` 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) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if user.SteamID == "" { // User does not exist - c.JSON(http.StatusNotFound, models.ErrorResponse("User not found.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not found.")) return } // Get rankings (all maps done in one game) @@ -380,7 +380,7 @@ func FetchUser(c *gin.Context) { 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;` err = database.DB.QueryRow(sql).Scan(&rankings.Singleplayer.CompletionTotal, &rankings.Cooperative.CompletionTotal) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } rankings.Overall.CompletionTotal = rankings.Singleplayer.CompletionTotal + rankings.Cooperative.CompletionTotal @@ -400,7 +400,7 @@ func FetchUser(c *gin.Context) { WHERE rm.host_id = $1 OR rm.partner_id = $1;` rows, err := database.DB.Query(sql, user.SteamID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -408,7 +408,7 @@ func FetchUser(c *gin.Context) { var completionCount int err = rows.Scan(&tableName, &completionCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if tableName == "records_sp" { @@ -431,7 +431,7 @@ func FetchUser(c *gin.Context) { ORDER BY total_min_score_count ASC;` rows, err = database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } placement := 1 @@ -442,7 +442,7 @@ func FetchUser(c *gin.Context) { var userPortalCount int err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if completionCount != totalCount { @@ -465,7 +465,7 @@ func FetchUser(c *gin.Context) { ORDER BY total_min_score_count ASC;` rows, err = database.DB.Query(sql) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } placement = 1 @@ -476,7 +476,7 @@ func FetchUser(c *gin.Context) { var userPortalCount int err = rows.Scan(&steamID, &completionCount, &totalCount, &userPortalCount) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } if completionCount != totalCount { @@ -521,7 +521,7 @@ func FetchUser(c *gin.Context) { // GROUP BY steam_id ORDER BY total_score ASC;` // rows, err = database.DB.Query(sql) // if err != nil { - // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) // return // } // placement = 1 @@ -530,7 +530,7 @@ func FetchUser(c *gin.Context) { // var userPortalCount int // err = rows.Scan(&steamID, &userPortalCount) // if err != nil { - // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + // c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) // return // } // if completionCount != totalCount { @@ -550,7 +550,7 @@ func FetchUser(c *gin.Context) { 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;` rows, err = database.DB.Query(sql, user.SteamID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -582,7 +582,7 @@ func FetchUser(c *gin.Context) { 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;` rows, err = database.DB.Query(sql, user.SteamID) if err != nil { - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } for rows.Next() { @@ -641,13 +641,13 @@ func UpdateUser(c *gin.Context) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } profile, err := GetPlayerSummaries(user.(models.User).SteamID, os.Getenv("API_KEY")) if err != nil { CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSummaryFail) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Update profile @@ -655,7 +655,7 @@ func UpdateUser(c *gin.Context) { WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) if err != nil { CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateFail) - c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSuccess) @@ -688,27 +688,27 @@ func UpdateCountryCode(c *gin.Context) { // Check if user exists user, exists := c.Get("user") if !exists { - c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in.")) + c.JSON(http.StatusOK, models.ErrorResponse("User not logged in.")) return } code := c.Query("country_code") if code == "" { CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) - c.JSON(http.StatusNotFound, models.ErrorResponse("Enter a valid country code.")) + c.JSON(http.StatusOK, models.ErrorResponse("Enter a valid country code.")) return } var validCode string err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1`, code).Scan(&validCode) if err != nil { CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) - c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } // Valid code, update profile _, err = database.DB.Exec(`UPDATE users SET country_code = $1 WHERE steam_id = $2`, validCode, user.(models.User).SteamID) if err != nil { CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) - c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountrySuccess) -- cgit v1.2.3