mirror of
https://gitee.com/shikong-sk/gofiber-study
synced 2025-02-24 15:52:15 +08:00
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package user
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"gofiber.study.skcks.cn/common/errorx"
|
|
"gofiber.study.skcks.cn/common/response"
|
|
"gofiber.study.skcks.cn/controller/types"
|
|
"gofiber.study.skcks.cn/middleware"
|
|
"gofiber.study.skcks.cn/services/user"
|
|
)
|
|
|
|
type Controller struct {
|
|
*types.Controller
|
|
}
|
|
|
|
func (c *Controller) GetRouter() fiber.Router {
|
|
return c.Router
|
|
}
|
|
|
|
func NewController(app *fiber.App) *Controller {
|
|
return &Controller{
|
|
Controller: types.NewController(app, "/user", middleware.CasbinMiddleWare),
|
|
}
|
|
}
|
|
|
|
// GetByAccount 根据 账号 获取用户信息
|
|
//
|
|
// @Summary 根据 账号 获取用户信息
|
|
// @Description 根据 账号 获取用户信息
|
|
// @Tags User
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param account query string true "账号名称"
|
|
// @Success 200 {object} response.Response{data=models.User}
|
|
// @Failure default {object} errorx.CodeErrorResponse
|
|
// @Router /user/account [get]
|
|
// @Security Token
|
|
func (c *Controller) GetByAccount() {
|
|
c.Router.Get("/account", func(ctx *fiber.Ctx) error {
|
|
account := ctx.Query("account")
|
|
|
|
u, err := user.Services.GetUserByAccount(account)
|
|
if err != nil {
|
|
return ctx.JSON(errorx.NewDefaultError(err.Error()))
|
|
}
|
|
|
|
return ctx.JSON(response.NewResponse(u))
|
|
})
|
|
}
|