diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-04-13 01:28:48 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-04-13 01:28:48 +0300 |
| commit | 3e10a3542f70f23313fc6a43c41aaca518e3d344 (patch) | |
| tree | 2bf813d90aa62336335141c1902b5eb7ec915550 /backend/controllers/userController.go | |
| parent | Merge pull request #32 from Nidboj132/main (diff) | |
| download | lphub-3e10a3542f70f23313fc6a43c41aaca518e3d344.tar.gz lphub-3e10a3542f70f23313fc6a43c41aaca518e3d344.tar.bz2 lphub-3e10a3542f70f23313fc6a43c41aaca518e3d344.zip | |
doc: swagger init for login and user routes (#34)
Diffstat (limited to 'backend/controllers/userController.go')
| -rw-r--r-- | backend/controllers/userController.go | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/backend/controllers/userController.go b/backend/controllers/userController.go index 95b2b52..cb6c15d 100644 --- a/backend/controllers/userController.go +++ b/backend/controllers/userController.go | |||
| @@ -11,6 +11,15 @@ import ( | |||
| 11 | "github.com/pektezol/leastportals/backend/models" | 11 | "github.com/pektezol/leastportals/backend/models" |
| 12 | ) | 12 | ) |
| 13 | 13 | ||
| 14 | // GET Profile | ||
| 15 | // | ||
| 16 | // @Summary Get profile page of session user. | ||
| 17 | // @Accept json | ||
| 18 | // @Produce json | ||
| 19 | // @Success 200 {object} models.Response{data=models.ProfileResponse} | ||
| 20 | // @Failure 400 {object} models.Response | ||
| 21 | // @Failure 401 {object} models.Response | ||
| 22 | // @Router /profile [get] | ||
| 14 | func Profile(c *gin.Context) { | 23 | func Profile(c *gin.Context) { |
| 15 | // Check if user exists | 24 | // Check if user exists |
| 16 | user, exists := c.Get("user") | 25 | user, exists := c.Get("user") |
| @@ -87,6 +96,16 @@ func Profile(c *gin.Context) { | |||
| 87 | return | 96 | return |
| 88 | } | 97 | } |
| 89 | 98 | ||
| 99 | // GET User | ||
| 100 | // | ||
| 101 | // @Summary Get profile page of another user. | ||
| 102 | // @Accept json | ||
| 103 | // @Produce json | ||
| 104 | // @Param id path int true "User ID" | ||
| 105 | // @Success 200 {object} models.Response{data=models.ProfileResponse} | ||
| 106 | // @Failure 400 {object} models.Response | ||
| 107 | // @Failure 404 {object} models.Response | ||
| 108 | // @Router /user/{id} [get] | ||
| 90 | func FetchUser(c *gin.Context) { | 109 | func FetchUser(c *gin.Context) { |
| 91 | id := c.Param("id") | 110 | id := c.Param("id") |
| 92 | // Check if id is all numbers and 17 length | 111 | // Check if id is all numbers and 17 length |
| @@ -178,6 +197,15 @@ func FetchUser(c *gin.Context) { | |||
| 178 | return | 197 | return |
| 179 | } | 198 | } |
| 180 | 199 | ||
| 200 | // PUT Profile | ||
| 201 | // | ||
| 202 | // @Summary Update profile page of session user. | ||
| 203 | // @Accept json | ||
| 204 | // @Produce json | ||
| 205 | // @Success 200 {object} models.Response{data=models.ProfileResponse} | ||
| 206 | // @Failure 400 {object} models.Response | ||
| 207 | // @Failure 401 {object} models.Response | ||
| 208 | // @Router /profile [post] | ||
| 181 | func UpdateUser(c *gin.Context) { | 209 | func UpdateUser(c *gin.Context) { |
| 182 | // Check if user exists | 210 | // Check if user exists |
| 183 | user, exists := c.Get("user") | 211 | user, exists := c.Get("user") |
| @@ -208,9 +236,18 @@ func UpdateUser(c *gin.Context) { | |||
| 208 | CountryCode: profile.LocCountryCode, | 236 | CountryCode: profile.LocCountryCode, |
| 209 | }, | 237 | }, |
| 210 | }) | 238 | }) |
| 211 | return | ||
| 212 | } | 239 | } |
| 213 | 240 | ||
| 241 | // PUT Profile/CountryCode | ||
| 242 | // | ||
| 243 | // @Summary Update country code of session user. | ||
| 244 | // @Accept json | ||
| 245 | // @Produce json | ||
| 246 | // @Param country_code query string true "Country Code [XX]" | ||
| 247 | // @Success 200 {object} models.Response{data=models.ProfileResponse} | ||
| 248 | // @Failure 400 {object} models.Response | ||
| 249 | // @Failure 401 {object} models.Response | ||
| 250 | // @Router /profile [put] | ||
| 214 | func UpdateCountryCode(c *gin.Context) { | 251 | func UpdateCountryCode(c *gin.Context) { |
| 215 | // Check if user exists | 252 | // Check if user exists |
| 216 | user, exists := c.Get("user") | 253 | user, exists := c.Get("user") |