diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/controllers/loginController.go | 18 | ||||
| -rw-r--r-- | backend/controllers/userController.go | 39 |
2 files changed, 52 insertions, 5 deletions
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index 50189e8..6feda8a 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go | |||
| @@ -15,6 +15,14 @@ import ( | |||
| 15 | "github.com/solovev/steam_go" | 15 | "github.com/solovev/steam_go" |
| 16 | ) | 16 | ) |
| 17 | 17 | ||
| 18 | // Login | ||
| 19 | // | ||
| 20 | // @Summary Get (redirect) login page for Steam auth. | ||
| 21 | // @Accept json | ||
| 22 | // @Produce json | ||
| 23 | // @Success 200 {object} models.Response{data=models.LoginResponse} | ||
| 24 | // @Failure 400 {object} models.Response | ||
| 25 | // @Router /login [get] | ||
| 18 | func Login(c *gin.Context) { | 26 | func Login(c *gin.Context) { |
| 19 | openID := steam_go.NewOpenId(c.Request) | 27 | openID := steam_go.NewOpenId(c.Request) |
| 20 | switch openID.Mode() { | 28 | switch openID.Mode() { |
| @@ -31,14 +39,16 @@ func Login(c *gin.Context) { | |||
| 31 | // Create user if new | 39 | // Create user if new |
| 32 | var checkSteamID int64 | 40 | var checkSteamID int64 |
| 33 | err = database.DB.QueryRow("SELECT steam_id FROM users WHERE steam_id = $1", steamID).Scan(&checkSteamID) | 41 | err = database.DB.QueryRow("SELECT steam_id FROM users WHERE steam_id = $1", steamID).Scan(&checkSteamID) |
| 34 | if err != nil { | 42 | // if err != nil { |
| 35 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 43 | // fmt.Println("y1") |
| 36 | return | 44 | // c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 37 | } | 45 | // return |
| 46 | // } | ||
| 38 | // User does not exist | 47 | // User does not exist |
| 39 | if checkSteamID == 0 { | 48 | if checkSteamID == 0 { |
| 40 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) | 49 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) |
| 41 | if err != nil { | 50 | if err != nil { |
| 51 | fmt.Println("y2") | ||
| 42 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 52 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 43 | return | 53 | return |
| 44 | } | 54 | } |
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") |