66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
jwt "github.com/appleboy/gin-jwt/v2"
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
"joylink.club/bj-rtsts-server/dto"
|
|
"joylink.club/bj-rtsts-server/middleware"
|
|
"joylink.club/bj-rtsts-server/service"
|
|
)
|
|
|
|
func InitUserRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
|
unauthed := api.Group("/v1/user")
|
|
unauthed.POST("/login", login(authMiddleware))
|
|
|
|
authed := api.Group("/v1/user").Use(authMiddleware.MiddlewareFunc())
|
|
authed.GET("/paging", pageQueryUser)
|
|
}
|
|
|
|
// 用户登录
|
|
//
|
|
// @Summary 用户登录
|
|
// @Description 用户登录
|
|
// @Tags 用户Api
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param loginInfo body dto.LoginDto true "登录信息"
|
|
// @Success 200 {object} dto.TokenRespDto
|
|
// @Failure 500 {object} dto.ErrorDto
|
|
// @Router /api/v1/user/login [post]
|
|
func login(authMiddleware *jwt.GinJWTMiddleware) func(*gin.Context) {
|
|
return authMiddleware.LoginHandler
|
|
}
|
|
|
|
// 分页查询用户
|
|
//
|
|
// @Summary 分页查询用户
|
|
//
|
|
// @Security JwtAuth
|
|
//
|
|
// @Description 可以通过用户名称过滤,分页查询用户
|
|
// @Tags 用户Api
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id query dto.PageUserReqDto true "用户查询条件"
|
|
// @Success 200 {object} dto.PageDto
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
// @Failure 500 {object} dto.ErrorDto
|
|
// @Router /api/v1/user/paging [get]
|
|
func pageQueryUser(c *gin.Context) {
|
|
user, _ := c.Get(middleware.IdentityKey)
|
|
zap.S().Debug("分页查询用户", user)
|
|
req := dto.PageUserReqDto{}
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
zap.S().Warn("分页查询参数绑定错误,使用默认参数", err)
|
|
req.Default()
|
|
}
|
|
zap.S().Debug("分页查用户参数", req)
|
|
page, _ := service.PagingQueryUser(&req)
|
|
|
|
c.JSON(http.StatusOK, page)
|
|
}
|