Passed
Push — main ( f6597a...58b626 )
by Yume
01:31 queued 12s
created

controllers.*UserController.GetName   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
package controllers
2
3
import (
4
	"github.com/gofiber/fiber/v2"
5
	"github.com/memnix/memnix-rest/internal/user"
6
	"github.com/memnix/memnix-rest/pkg/utils"
7
	"github.com/memnix/memnix-rest/views"
8
)
9
10
type UserController struct {
11
	user.IUseCase
12
}
13
14
func NewUserController(useCase user.IUseCase) UserController {
15
	return UserController{IUseCase: useCase}
16
}
17
18
func (u *UserController) GetName(c *fiber.Ctx) error {
19
	uuid := c.Params("uuid")
20
21
	return c.SendString(u.IUseCase.GetName(uuid))
22
}
23
24
func (u *UserController) GetMe(c *fiber.Ctx) error {
25
	userCtx := utils.GetUserFromContext(c)
26
	if userCtx == nil {
27
		return c.Status(fiber.StatusUnauthorized).JSON(views.NewHTTPResponseVM("User not found", nil))
28
	}
29
30
	return c.Status(fiber.StatusOK).JSON(views.NewHTTPResponseVM("User found", *userCtx))
31
}
32