feat✨ 添加api管理
This commit is contained in:
1 parent
70998c424d
commit
d0b2e8d03f
6 files changed
+395
-53
No files matched your search
@@ -0,0 +1,259 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/actions"
|
||||
"go-admin/common/apis"
|
||||
)
|
||||
|
||||
type SysApi struct {
|
||||
apis.Api
|
||||
}
|
||||
|
||||
// GetSysApiList 获取接口管理列表
|
||||
// @Summary 获取接口管理列表
|
||||
// @Description 获取接口管理列表
|
||||
// @Tags 接口管理
|
||||
// @Param name query string false "名称"
|
||||
// @Param title query string false "标题"
|
||||
// @Param path query string false "地址"
|
||||
// @Param action query string false "类型"
|
||||
// @Param parentId query string false "按钮id"
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageIndex query int false "页码"
|
||||
// @Success 200 {object} response.Response{data=response.Page{list=[]models.SysApi}} "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/sys_api [get]
|
||||
// @Security Bearer
|
||||
func (e SysApi) GetSysApiList(c *gin.Context) {
|
||||
e.MakeContext(c)
|
||||
log := e.GetLogger()
|
||||
db, err := e.GetOrm()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
d := new(dto.SysApiSearch)
|
||||
//查询列表
|
||||
err = d.Bind(c)
|
||||
if err != nil {
|
||||
log.Warnf("request body bind error, %s", err.Error())
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
|
||||
//数据权限检查
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
list := make([]models.SysApi, 0)
|
||||
var count int64
|
||||
serviceSysApi := service.SysApi{}
|
||||
serviceSysApi.Log = log
|
||||
serviceSysApi.Orm = db
|
||||
err = serviceSysApi.GetSysApiPage(d, p, &list, &count)
|
||||
if err != nil {
|
||||
log.Errorf("Get SysApi Page error, %s", err.Error())
|
||||
e.Error(http.StatusInternalServerError, err, "查询失败")
|
||||
return
|
||||
}
|
||||
|
||||
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
|
||||
}
|
||||
|
||||
// GetSysApi 获取接口管理
|
||||
// @Summary 获取接口管理
|
||||
// @Description 获取接口管理
|
||||
// @Tags 接口管理
|
||||
// @Param id path string false "id"
|
||||
// @Success 200 {object} response.Response{data=models.SysApi} "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/sys_api/{id} [get]
|
||||
// @Security Bearer
|
||||
func (e SysApi) GetSysApi(c *gin.Context) {
|
||||
e.MakeContext(c)
|
||||
log := e.GetLogger()
|
||||
db, err := e.GetOrm()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
control := new(dto.SysApiById)
|
||||
|
||||
//查看详情
|
||||
err = control.Bind(c)
|
||||
if err != nil {
|
||||
log.Warnf("request body bind error, %s", err.Error())
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
var object models.SysApi
|
||||
|
||||
//数据权限检查
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
serviceSysApi := service.SysApi{}
|
||||
serviceSysApi.Log = log
|
||||
serviceSysApi.Orm = db
|
||||
err = serviceSysApi.GetSysApi(control, p, &object)
|
||||
if err != nil {
|
||||
log.Errorf("Get SysApi error, %s", err.Error())
|
||||
e.Error(http.StatusInternalServerError, err, "查询失败")
|
||||
return
|
||||
}
|
||||
|
||||
e.OK(object, "查看成功")
|
||||
}
|
||||
|
||||
// InsertSysApi 创建接口管理
|
||||
// @Summary 创建接口管理
|
||||
// @Description 创建接口管理
|
||||
// @Tags 接口管理
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body dto.SysApiControl true "data"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
|
||||
// @Router /api/v1/sys_api [post]
|
||||
// @Security Bearer
|
||||
//func (e SysApi) InsertSysApi(c *gin.Context) {
|
||||
// e.MakeContext(c)
|
||||
// log := e.GetLogger()
|
||||
// db, err := e.GetOrm()
|
||||
// if err != nil {
|
||||
// log.Error(err)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// control := new(dto.SysApiControl)
|
||||
//
|
||||
// //新增操作
|
||||
// err = control.Bind(c)
|
||||
// if err != nil {
|
||||
// log.Warnf("request body bind error, %s", err.Error())
|
||||
// e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
// return
|
||||
// }
|
||||
// object, err := control.GenerateM()
|
||||
// if err != nil {
|
||||
// log.Errorf("generate SysApi model error, %s", err.Error())
|
||||
// e.Error(http.StatusInternalServerError, err, "模型生成失败")
|
||||
// return
|
||||
// }
|
||||
// // 设置创建人
|
||||
// object.SetCreateBy(user.GetUserId(c))
|
||||
//
|
||||
// serviceSysApi := service.SysApi{}
|
||||
// serviceSysApi.Orm = db
|
||||
// serviceSysApi.Log = log
|
||||
// err = serviceSysApi.InsertSysApi(object.(*models.SysApi))
|
||||
// if err != nil {
|
||||
// log.Errorf("Insert SysApi error, %s", err.Error())
|
||||
// e.Error(http.StatusInternalServerError, err, "创建失败")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// e.OK(object.GetId(), "创建成功")
|
||||
//}
|
||||
|
||||
// UpdateSysApi 修改接口管理
|
||||
// @Summary 修改接口管理
|
||||
// @Description 修改接口管理
|
||||
// @Tags 接口管理
|
||||
// @Accept application/json
|
||||
// @Product application/json
|
||||
// @Param data body dto.SysApiControl true "body"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
|
||||
// @Router /api/v1/sys_api/{id} [put]
|
||||
// @Security Bearer
|
||||
func (e SysApi) UpdateSysApi(c *gin.Context) {
|
||||
e.MakeContext(c)
|
||||
log := e.GetLogger()
|
||||
db, err := e.GetOrm()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
control := new(dto.SysApiControl)
|
||||
|
||||
//更新操作
|
||||
err = control.Bind(c)
|
||||
if err != nil {
|
||||
log.Warnf("request body bind error, %s", err.Error())
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
object, err := control.GenerateM()
|
||||
if err != nil {
|
||||
log.Errorf("generate SysApi model error, %s", err.Error())
|
||||
e.Error(http.StatusInternalServerError, err, "模型生成失败")
|
||||
return
|
||||
}
|
||||
object.SetUpdateBy(user.GetUserId(c))
|
||||
|
||||
//数据权限检查
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
serviceSysApi := service.SysApi{}
|
||||
serviceSysApi.Orm = db
|
||||
serviceSysApi.Log = log
|
||||
err = serviceSysApi.UpdateSysApi(object.(*models.SysApi), p)
|
||||
if err != nil {
|
||||
log.Errorf("Update SysApi error, %s", err.Error())
|
||||
e.Error(http.StatusInternalServerError, err, "更新失败")
|
||||
return
|
||||
}
|
||||
e.OK(object.GetId(), "更新成功")
|
||||
}
|
||||
|
||||
// DeleteSysApi 删除接口管理
|
||||
// @Summary 删除接口管理
|
||||
// @Description 删除接口管理
|
||||
// @Tags 接口管理
|
||||
// @Param ids body []int false "ids"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
|
||||
// @Router /api/v1/sys_api [delete]
|
||||
// @Security Bearer
|
||||
func (e SysApi) DeleteSysApi(c *gin.Context) {
|
||||
e.MakeContext(c)
|
||||
log := e.GetLogger()
|
||||
db, err := e.GetOrm()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
control := new(dto.SysApiById)
|
||||
|
||||
//删除操作
|
||||
err = control.Bind(c)
|
||||
if err != nil {
|
||||
log.Warnf("request body bind error, %s", err.Error())
|
||||
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||
return
|
||||
}
|
||||
|
||||
// 设置编辑人
|
||||
control.SetUpdateBy(user.GetUserId(c))
|
||||
|
||||
// 数据权限检查
|
||||
p := actions.GetPermissionFromContext(c)
|
||||
|
||||
serviceSysApi := service.SysApi{}
|
||||
serviceSysApi.Orm = db
|
||||
serviceSysApi.Log = log
|
||||
err = serviceSysApi.RemoveSysApi(control, p)
|
||||
if err != nil {
|
||||
log.Errorf("Remove SysApi error, %s", err.Error())
|
||||
e.Error(http.StatusInternalServerError, err, "删除失败")
|
||||
return
|
||||
}
|
||||
e.OK(control.GetId(), "删除成功")
|
||||
}
|
||||
Reference in new issue
Block a user