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 /backend/handlers/user.go | |
| 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
Diffstat (limited to 'backend/handlers/user.go')
| -rw-r--r-- | backend/handlers/user.go | 68 |
1 files changed, 34 insertions, 34 deletions
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) |