mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 08:51:16 +00:00
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package user
|
|
|
|
import (
|
|
"github.com/get-drexa/drexa/internal/reqctx"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type HTTPHandler struct {
|
|
service *Service
|
|
db *bun.DB
|
|
authMiddleware fiber.Handler
|
|
}
|
|
|
|
func NewHTTPHandler(service *Service, db *bun.DB, authMiddleware fiber.Handler) *HTTPHandler {
|
|
return &HTTPHandler{service: service, db: db, authMiddleware: authMiddleware}
|
|
}
|
|
|
|
func (h *HTTPHandler) RegisterRoutes(api fiber.Router) fiber.Router {
|
|
users := api.Group("/users")
|
|
users.Use(h.authMiddleware)
|
|
users.Get("/me", h.getAuthenticatedUser)
|
|
return users
|
|
}
|
|
|
|
// getAuthenticatedUser returns the currently authenticated user
|
|
// @Summary Get current user
|
|
// @Description Retrieve the authenticated user's profile information
|
|
// @Tags users
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Success 200 {object} User "User profile"
|
|
// @Failure 401 {string} string "Not authenticated"
|
|
// @Router /users/me [get]
|
|
func (h *HTTPHandler) getAuthenticatedUser(c *fiber.Ctx) error {
|
|
u := reqctx.AuthenticatedUser(c).(*User)
|
|
if u == nil {
|
|
return c.SendStatus(fiber.StatusUnauthorized)
|
|
}
|
|
return c.JSON(u)
|
|
}
|