Files
drive/apps/backend/internal/user/http.go
Kenneth 7b13326e22 docs: add OpenAPI documentation with Scalar UI
- Add swaggo annotations to all HTTP handlers
- Add Swagger/OpenAPI spec generation with swag
- Create separate docs server binary (drexa-docs)
- Add Makefile with build, run, and docs targets
- Configure Scalar as the API documentation UI

Run 'make docs' to regenerate, 'make run-docs' to serve.
2025-12-13 22:44:37 +00:00

41 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) {
user := api.Group("/users")
user.Use(h.authMiddleware)
user.Get("/me", h.getAuthenticatedUser)
}
// 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)
}