diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 75573fd..ae4eb69 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -37,6 +37,22 @@ func userAuth(c *gin.Context) { c.JSON(http.StatusOK, user) } +func userGet(c *gin.Context) { + session := sessions.Default(c) + user_id, ok := session.Get("user_id").(string) + if !ok { + c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"}) + return + } + user, err := db.UserGet(context.Background(), user_id) + if err != nil { + status, message := HandleDBError(err) + c.JSON(status, gin.H{"error": message}) + return + } + c.JSON(http.StatusOK, user) +} + func userUpdate(c *gin.Context) { session := sessions.Default(c) user_id, ok := session.Get("user_id").(string) diff --git a/backend/api/routes.go b/backend/api/routes.go index 62b9935..b81417b 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -21,6 +21,7 @@ func RegisterRoutes(r *gin.Engine) { api := r.Group("/api") { api.POST("/auth", userAuth) + api.GET("/auth", userGet) api.PATCH("/auth", userUpdate) api.GET("/quotes", quotesGet)