Files
nixcn-cms/service/user/info.go
2026-01-02 12:36:07 +08:00

45 lines
839 B
Go

package user
import (
"nixcn-cms/data"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
func Info(c *gin.Context) {
userData := new(data.User)
userIdOrig, ok := c.Get("user_id")
if !ok {
c.JSON(404, gin.H{
"status": "user not found",
})
return
}
userId, err := uuid.Parse(userIdOrig.(string))
if err != nil {
c.JSON(500, gin.H{
"status": "failed to parse uuid",
})
}
// Get user from database
user, err := userData.GetByUserId(userId)
if err != nil {
c.JSON(404, gin.H{
"status": "user not found",
})
return
}
c.JSON(200, gin.H{
"user_id": user.UserId,
"email": user.Email,
"nickname": user.Nickname,
"subtitle": user.Subtitle,
"avatar": user.Avatar,
"bio": user.Bio,
"permission_level": user.PermissionLevel,
})
}