Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package controllers |
||
2 | |||
3 | import ( |
||
4 | "log/slog" |
||
5 | |||
6 | "github.com/gofiber/fiber/v2" |
||
7 | "github.com/gofiber/fiber/v2/log" |
||
8 | "github.com/memnix/memnix-rest/app/v1/views" |
||
9 | "github.com/memnix/memnix-rest/services/user" |
||
10 | ) |
||
11 | |||
12 | // UserController is the controller for the user routes. |
||
13 | type UserController struct { |
||
14 | user.IUseCase |
||
15 | } |
||
16 | |||
17 | // NewUserController creates a new user controller. |
||
18 | func NewUserController(useCase user.IUseCase) UserController { |
||
19 | return UserController{IUseCase: useCase} |
||
20 | } |
||
21 | |||
22 | // GetName returns the name of the user. |
||
23 | func (u *UserController) GetName(c *fiber.Ctx) error { |
||
24 | uuid := c.Params("uuid") |
||
25 | |||
26 | return c.SendString(u.IUseCase.GetName(c.UserContext(), uuid)) |
||
27 | } |
||
28 | |||
29 | // GetMe returns the user from the context. |
||
30 | func (*UserController) GetMe(c *fiber.Ctx) error { |
||
31 | userCtx, err := GetUserFromContext(c) |
||
32 | if err != nil { |
||
33 | return c.Status(fiber.StatusUnauthorized).JSON(views.NewHTTPResponseVM("User not found", nil)) |
||
34 | } |
||
35 | |||
36 | log.Info("user found", slog.String("user", userCtx.Username)) |
||
37 | return c.Status(fiber.StatusOK).JSON(views.NewHTTPResponseVM("User found", userCtx)) |
||
38 | } |
||
39 |