Refactor employee management
This commit is contained in:
@@ -58,12 +58,15 @@ func (c *AuthController) Login(ctx *gin.Context) {
|
||||
"message": "登录成功",
|
||||
"accessToken": token,
|
||||
"user": models.UserDTO{
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Role: user.Role,
|
||||
CreatedAt: user.CreatedAt,
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Phone: user.Phone,
|
||||
EmployeeNo: user.EmployeeNo,
|
||||
Position: user.Position,
|
||||
Role: user.Role,
|
||||
CreatedAt: user.CreatedAt,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"git.beifan.cn/trace-system/backend-go/services"
|
||||
)
|
||||
|
||||
// UsersController 用户管理控制器
|
||||
// UsersController 员工管理控制器
|
||||
type UsersController struct {
|
||||
usersService services.UsersService
|
||||
}
|
||||
@@ -22,17 +22,17 @@ func NewUsersController() *UsersController {
|
||||
}
|
||||
}
|
||||
|
||||
// Create 创建用户(管理员)
|
||||
// @Summary 创建用户
|
||||
// @Tags 用户管理
|
||||
// Create 创建员工(管理员)
|
||||
// @Summary 创建员工
|
||||
// @Tags 员工管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param data body models.CreateUserDTO true "用户数据"
|
||||
// @Param data body models.CreateUserDTO true "员工数据"
|
||||
// @Success 200 {object} models.DataResponse
|
||||
// @Failure 400 {object} models.ErrorResponse
|
||||
// @Failure 401 {object} models.ErrorResponse
|
||||
// @Router /users [post]
|
||||
// @Router /employees [post]
|
||||
func (c *UsersController) Create(ctx *gin.Context) {
|
||||
var dto models.CreateUserDTO
|
||||
if !BindJSON(ctx, &dto) {
|
||||
@@ -45,14 +45,14 @@ func (c *UsersController) Create(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
SuccessResponse(ctx, "用户创建成功", gin.H{
|
||||
"user": user,
|
||||
SuccessResponse(ctx, "员工创建成功", gin.H{
|
||||
"employee": user,
|
||||
})
|
||||
}
|
||||
|
||||
// FindAll 用户列表
|
||||
// @Summary 用户列表
|
||||
// @Tags 用户管理
|
||||
// FindAll 员工列表
|
||||
// @Summary 员工列表
|
||||
// @Tags 员工管理
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param page query int false "页码"
|
||||
@@ -61,7 +61,7 @@ func (c *UsersController) Create(ctx *gin.Context) {
|
||||
// @Param search query string false "搜索"
|
||||
// @Success 200 {object} models.PaginationResponse
|
||||
// @Failure 401 {object} models.ErrorResponse
|
||||
// @Router /users [get]
|
||||
// @Router /employees [get]
|
||||
func (c *UsersController) FindAll(ctx *gin.Context) {
|
||||
page, _ := strconv.Atoi(ctx.DefaultQuery("page", "1"))
|
||||
limit, _ := strconv.Atoi(ctx.DefaultQuery("limit", "20"))
|
||||
@@ -74,7 +74,7 @@ func (c *UsersController) FindAll(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
SuccessResponse(ctx, "获取用户列表成功", gin.H{
|
||||
SuccessResponse(ctx, "获取员工列表成功", gin.H{
|
||||
"data": users,
|
||||
"pagination": gin.H{
|
||||
"page": page,
|
||||
@@ -106,9 +106,9 @@ func (c *UsersController) FindAssignable(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// Update 更新用户信息
|
||||
// @Summary 更新用户
|
||||
// @Tags 用户管理
|
||||
// Update 更新员工信息
|
||||
// @Summary 更新员工
|
||||
// @Tags 员工管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
@@ -117,7 +117,7 @@ func (c *UsersController) FindAssignable(ctx *gin.Context) {
|
||||
// @Success 200 {object} models.DataResponse
|
||||
// @Failure 400 {object} models.ErrorResponse
|
||||
// @Failure 401 {object} models.ErrorResponse
|
||||
// @Router /users/{id} [patch]
|
||||
// @Router /employees/{id} [patch]
|
||||
func (c *UsersController) Update(ctx *gin.Context) {
|
||||
userModel, ok := GetCurrentUser(ctx)
|
||||
if !ok {
|
||||
@@ -141,14 +141,14 @@ func (c *UsersController) Update(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
SuccessResponse(ctx, "用户更新成功", gin.H{
|
||||
"user": user,
|
||||
SuccessResponse(ctx, "员工更新成功", gin.H{
|
||||
"employee": user,
|
||||
})
|
||||
}
|
||||
|
||||
// ResetPassword 重置用户密码
|
||||
// @Summary 重置密码
|
||||
// @Tags 用户管理
|
||||
// @Tags 员工管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
@@ -157,7 +157,7 @@ func (c *UsersController) Update(ctx *gin.Context) {
|
||||
// @Success 200 {object} models.BaseResponse
|
||||
// @Failure 400 {object} models.ErrorResponse
|
||||
// @Failure 401 {object} models.ErrorResponse
|
||||
// @Router /users/{id}/reset-password [post]
|
||||
// @Router /employees/{id}/reset-password [post]
|
||||
func (c *UsersController) ResetPassword(ctx *gin.Context) {
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 32)
|
||||
if err != nil {
|
||||
@@ -178,16 +178,16 @@ func (c *UsersController) ResetPassword(ctx *gin.Context) {
|
||||
SuccessResponse(ctx, "密码重置成功")
|
||||
}
|
||||
|
||||
// Delete 删除用户
|
||||
// @Summary 删除用户
|
||||
// @Tags 用户管理
|
||||
// Delete 删除员工
|
||||
// @Summary 删除员工
|
||||
// @Tags 员工管理
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path int true "用户 ID"
|
||||
// @Success 200 {object} models.BaseResponse
|
||||
// @Failure 400 {object} models.ErrorResponse
|
||||
// @Failure 401 {object} models.ErrorResponse
|
||||
// @Router /users/{id} [delete]
|
||||
// @Router /employees/{id} [delete]
|
||||
func (c *UsersController) Delete(ctx *gin.Context) {
|
||||
userModel, ok := GetCurrentUser(ctx)
|
||||
if !ok {
|
||||
@@ -205,5 +205,5 @@ func (c *UsersController) Delete(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
SuccessResponse(ctx, "用户删除成功")
|
||||
SuccessResponse(ctx, "员工删除成功")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user