feat: add /users/me route

This commit is contained in:
2025-12-04 00:49:59 +00:00
parent 539b15dcb7
commit 1bedafd3de
3 changed files with 34 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
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)
}
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)
}

View File

@@ -15,8 +15,8 @@ type User struct {
DisplayName string `bun:"display_name" json:"displayName"`
Email string `bun:"email,unique,notnull" json:"email"`
Password password.Hashed `bun:"password,notnull" json:"-"`
CreatedAt time.Time `bun:"created_at,notnull,nullzero" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,nullzero" json:"updatedAt"`
CreatedAt time.Time `bun:"created_at,notnull,nullzero" json:"-"`
UpdatedAt time.Time `bun:"updated_at,notnull,nullzero" json:"-"`
}
func newUserID() (uuid.UUID, error) {