aboutsummaryrefslogtreecommitdiff
path: root/backend/controllers/userController.go
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-01-14 17:47:42 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-01-14 17:47:42 +0300
commit92d4926ed163e7c242beb90aeca8b1cf69010179 (patch)
tree7d2ac43058b8214925dff200406663e868ea7935 /backend/controllers/userController.go
parentdelete demo after serving it from local (#24) (diff)
downloadlphub-92d4926ed163e7c242beb90aeca8b1cf69010179.tar.gz
lphub-92d4926ed163e7c242beb90aeca8b1cf69010179.tar.bz2
lphub-92d4926ed163e7c242beb90aeca8b1cf69010179.zip
added countries, update country (#4)
Diffstat (limited to '')
-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}