init(api): add user get handler

This commit is contained in:
Masahiko AMANO 2025-01-06 17:37:40 +03:00
parent d2a6522157
commit 3327dc6f18
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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)