123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- package system
- import (
- "github.com/flipped-aurora/gin-vue-admin/server/global"
- "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
- "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
- "github.com/flipped-aurora/gin-vue-admin/server/model/system"
- systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
- systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
- "github.com/flipped-aurora/gin-vue-admin/server/utils"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- )
- type SystemApiApi struct {
- }
- // @Tags SysApi
- // @Summary 创建基础api
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body system.SysApi true "api路径, api中文描述, api组, 方法"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
- // @Router /api/createApi [post]
- func (s *SystemApiApi) CreateApi(c *gin.Context) {
- var api system.SysApi
- _ = c.ShouldBindJSON(&api)
- if err := utils.Verify(api, utils.ApiVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := apiService.CreateApi(api); err != nil {
- global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
- response.FailWithMessage("创建失败", c)
- } else {
- response.OkWithMessage("创建成功", c)
- }
- }
- // @Tags SysApi
- // @Summary 删除api
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body system.SysApi true "ID"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
- // @Router /api/deleteApi [post]
- func (s *SystemApiApi) DeleteApi(c *gin.Context) {
- var api system.SysApi
- _ = c.ShouldBindJSON(&api)
- if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := apiService.DeleteApi(api); err != nil {
- global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
- response.FailWithMessage("删除失败", c)
- } else {
- response.OkWithMessage("删除成功", c)
- }
- }
- // @Tags SysApi
- // @Summary 分页获取API列表
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body systemReq.SearchApiParams true "分页获取API列表"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
- // @Router /api/getApiList [post]
- func (s *SystemApiApi) GetApiList(c *gin.Context) {
- var pageInfo systemReq.SearchApiParams
- _ = c.ShouldBindJSON(&pageInfo)
- if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err, list, total := apiService.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: pageInfo.Page,
- PageSize: pageInfo.PageSize,
- }, "获取成功", c)
- }
- }
- // @Tags SysApi
- // @Summary 根据id获取api
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.GetById true "根据id获取api"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
- // @Router /api/getApiById [post]
- func (s *SystemApiApi) GetApiById(c *gin.Context) {
- var idInfo request.GetById
- _ = c.ShouldBindJSON(&idInfo)
- if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err, api := apiService.GetApiById(idInfo.ID)
- if err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithData(systemRes.SysAPIResponse{Api: api}, c)
- }
- }
- // @Tags SysApi
- // @Summary 创建基础api
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body system.SysApi true "api路径, api中文描述, api组, 方法"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
- // @Router /api/updateApi [post]
- func (s *SystemApiApi) UpdateApi(c *gin.Context) {
- var api system.SysApi
- _ = c.ShouldBindJSON(&api)
- if err := utils.Verify(api, utils.ApiVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := apiService.UpdateApi(api); err != nil {
- global.GVA_LOG.Error("修改失败!", zap.Any("err", err))
- response.FailWithMessage("修改失败", c)
- } else {
- response.OkWithMessage("修改成功", c)
- }
- }
- // @Tags SysApi
- // @Summary 获取所有的Api 不分页
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
- // @Router /api/getAllApis [post]
- func (s *SystemApiApi) GetAllApis(c *gin.Context) {
- if err, apis := apiService.GetAllApis(); err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithDetailed(systemRes.SysAPIListResponse{Apis: apis}, "获取成功", c)
- }
- }
- // @Tags SysApi
- // @Summary 删除选中Api
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.IdsReq true "ID"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
- // @Router /api/deleteApisByIds [delete]
- func (s *SystemApiApi) DeleteApisByIds(c *gin.Context) {
- var ids request.IdsReq
- _ = c.ShouldBindJSON(&ids)
- if err := apiService.DeleteApisByIds(ids); err != nil {
- global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
- response.FailWithMessage("删除失败", c)
- } else {
- response.OkWithMessage("删除成功", c)
- }
- }
|