mirror of
https://github.com/get-drexa/drive.git
synced 2025-12-04 23:31:40 +00:00
feat: add /users/me route
This commit is contained in:
31
apps/backend/internal/user/http.go
Normal file
31
apps/backend/internal/user/http.go
Normal 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)
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user