feat: 添加修改角色状态接口

This commit is contained in:
zhangwenjian
2021-06-09 21:31:31 +08:00
parent 91d902389a
commit 1b579fb814
5 changed files with 103 additions and 19 deletions
+52 -14
View File
@@ -1,6 +1,7 @@
package apis
import (
"fmt"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk"
"go-admin/app/admin/models"
@@ -63,8 +64,7 @@ func (e SysRole) GetPage(c *gin.Context) {
// @Description 获取JSON
// @Tags 角色/Role
// @Param roleId path string false "roleId"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role/{id} [get]
// @Security Bearer
func (e SysRole) Get(c *gin.Context) {
@@ -77,7 +77,7 @@ func (e SysRole) Get(c *gin.Context) {
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
e.Error(500, err, fmt.Sprintf(" %s ", err.Error()))
return
}
@@ -99,8 +99,7 @@ func (e SysRole) Get(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param data body dto.SysRoleControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role [post]
// @Security Bearer
func (e SysRole) Insert(c *gin.Context) {
@@ -144,8 +143,7 @@ func (e SysRole) Insert(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param data body dto.SysRoleControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role/{id} [put]
// @Security Bearer
func (e SysRole) Update(c *gin.Context) {
@@ -183,8 +181,7 @@ func (e SysRole) Update(c *gin.Context) {
// @Description 删除数据
// @Tags 角色/Role
// @Param data body dto.SysRoleById true "body"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role [delete]
// @Security Bearer
func (e SysRole) Delete(c *gin.Context) {
@@ -197,25 +194,66 @@ func (e SysRole) Delete(c *gin.Context) {
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
e.Error(500, err, fmt.Sprintf("删除角色 %v 失败,\r\n失败信息 %s", req.Ids, err.Error()))
return
}
err = s.Remove(&req)
if err != nil {
e.Logger.Error(err)
e.Error(http.StatusInternalServerError, err, "")
e.Error(500, err, "")
return
}
_, err = global.LoadPolicy(c)
if err != nil {
e.Error(http.StatusInternalServerError, err, "")
e.Error(500, err, fmt.Sprintf("删除角色 %v 失败,失败信息 %s", req.Id, err.Error()))
return
}
e.OK(req.GetId(), "删除成功")
e.OK(req.GetId(), fmt.Sprintf("删除角色角色 %v 状态成功", req.GetId()))
}
// Update2Status 修改用户角色状态
// @Summary 修改用户角色
// @Description 获取JSON
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body dto.UpdateStatusReq true "body"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role-status/{id} [put]
// @Security Bearer
func (e SysRole) Update2Status(c *gin.Context) {
s := service.SysRole{}
req := dto.UpdateStatusReq{}
err := e.MakeContext(c).
MakeOrm().
Bind(&req, nil, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, fmt.Sprintf("更新角色状态失败,失败原因:%s ", err.Error()))
return
}
req.SetUpdateBy(user.GetUserId(c))
err = s.UpdateStatus(&req)
if err != nil {
e.Error(500, err, fmt.Sprintf("更新角色状态失败,失败原因:%s ", err.Error()))
return
}
e.OK(req.GetId(), fmt.Sprintf("更新角色 %v 状态成功!", req.GetId()))
}
// Update2DataScope 更新角色数据权限
// @Summary 更新角色数据权限
// @Description 获取JSON
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body dto.RoleDataScopeReq true "body"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role-status/{id} [put]
// @Security Bearer
func (e SysRole) Update2DataScope(c *gin.Context) {
s := &service.SysRole{}
req := dto.RoleDataScopeReq{}
@@ -241,4 +279,4 @@ func (e SysRole) Update2DataScope(c *gin.Context) {
return
}
e.OK(nil, "操作成功")
}
}