leaf-library-3/internal/api/http/v1/test.go
2024-12-06 01:44:29 +08:00

44 lines
1.1 KiB
Go

package v1
import (
"net/http"
"github.com/gofiber/fiber/v2"
"leafdev.top/Leaf/leaf-library-3/internal/api/http/response"
"leafdev.top/Leaf/leaf-library-3/internal/schema"
"leafdev.top/Leaf/leaf-library-3/internal/service/auth"
)
type UserController struct {
authService *auth.Service
}
func NewUserController(authService *auth.Service) *UserController {
return &UserController{authService}
}
// Test godoc
// @Summary Greet
// @Description 测试接口,将会返回当前用户的信息
// @Tags ping
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @deprecated true
// @Success 200 {object} response.Body{data=schema.CurrentUserResponse}
// @Failure 400 {object} response.Body
// @Router /api/v1/ping [get]
func (u *UserController) Test(c *fiber.Ctx) error {
user := u.authService.GetUser(c)
var currentUserResponse = &schema.CurrentUserResponse{
IP: c.IP(),
Valid: user.Valid,
UserEmail: user.Token.Email,
UserId: user.Token.Sub,
UserName: user.Token.Name,
}
return response.Ctx(c).Status(http.StatusOK).Data(currentUserResponse).Send()
}