aboutsummaryrefslogtreecommitdiff
path: root/backend/controllers/userController.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/controllers/userController.go')
-rw-r--r--backend/controllers/userController.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/backend/controllers/userController.go b/backend/controllers/userController.go
index b23a303..ab29e32 100644
--- a/backend/controllers/userController.go
+++ b/backend/controllers/userController.go
@@ -67,3 +67,33 @@ func FetchUser(c *gin.Context) {
67 }) 67 })
68 return 68 return
69} 69}
70
71func UpdateCountryCode(c *gin.Context) {
72 // Check if user exists
73 user, exists := c.Get("user")
74 if !exists {
75 c.JSON(http.StatusUnauthorized, models.ErrorResponse("User not logged in."))
76 return
77 }
78 code := c.Query("country_code")
79 if code == "" {
80 c.JSON(http.StatusNotFound, models.ErrorResponse("Enter a valid country code."))
81 return
82 }
83 var validCode string
84 err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1;`, code).Scan(&validCode)
85 if err != nil {
86 c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error()))
87 return
88 }
89 // Valid code, update profile
90 _, err = database.DB.Exec(`UPDATE users SET country_code = $1 WHERE steam_id = $2`, validCode, user.(models.User).SteamID)
91 if err != nil {
92 c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error()))
93 return
94 }
95 c.JSON(http.StatusOK, models.Response{
96 Success: true,
97 Message: "Successfully updated country code.",
98 })
99}