generated from WildEgor/e-shop-fiber-microservice-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
49 lines (41 loc) · 1.06 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package handlers
import (
dtos "github.com/WildEgor/e-shop-auth/internal/dtos/user"
auth_middleware "github.com/WildEgor/e-shop-auth/internal/middlewares/auth"
"github.com/WildEgor/e-shop-auth/internal/repositories"
core_dtos "github.com/WildEgor/e-shop-gopack/pkg/core/dtos"
"github.com/gofiber/fiber/v3"
)
type MeHandler struct {
userRepository *repositories.UserRepository
}
func NewMeHandler(
userRepository *repositories.UserRepository,
) *MeHandler {
return &MeHandler{
userRepository,
}
}
// TODO: add swagger response
// Get profile godoc
//
// @Param Authorization header string true "123"
// @Tags User Controller
// @Accept json
// @Produce json
//
// @Success 200 {object} dtos.MeResponseDto
// @Router /api/v1/user/me [get]
func (hch *MeHandler) Handle(ctx fiber.Ctx) error {
resp := core_dtos.NewResponse(ctx)
authUser := auth_middleware.ExtractUser(ctx)
resp.SetStatus(fiber.StatusOK)
resp.SetData([]*dtos.MeResponseDto{
{
ID: authUser.Id.Hex(),
Mobile: authUser.Phone,
Email: authUser.Email,
},
})
return resp.JSON()
}