Bulk commit: November work
This commit is contained in:
32
routers/user.go
Normal file
32
routers/user.go
Normal file
@ -0,0 +1,32 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"git.kocoder.xyz/kocoded/vt/query"
|
||||
"git.kocoder.xyz/kocoded/vt/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type userRouter struct {
|
||||
utils.Application
|
||||
}
|
||||
|
||||
func RegisterUserRouter(group fiber.Router, appCtx utils.Application) {
|
||||
router := &userRouter{Application: appCtx}
|
||||
|
||||
r := group.Use(utils.IsAuthenticated(appCtx))
|
||||
r.Get("/current", router.getCurrentUserInfo)
|
||||
}
|
||||
|
||||
func (r *userRouter) getCurrentUserInfo(c *fiber.Ctx) error {
|
||||
u := query.User
|
||||
|
||||
session := c.Locals("USER_KEY").(*utils.Session)
|
||||
|
||||
currentUser, err := u.Where(u.ID.Eq(session.UserID)).First()
|
||||
if err != nil {
|
||||
r.Logger.Warn("Current mandant not found.", "error", err)
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return c.JSON(currentUser)
|
||||
}
|
||||
Reference in New Issue
Block a user