sys_api.go 3.7 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
package v1
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2 3 4

import (
	"fmt"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
5 6
	"gin-vue-admin/global/response"
	"gin-vue-admin/model"
7
	"gin-vue-admin/model/request"
8
	resp "gin-vue-admin/model/response"
9
	"gin-vue-admin/service"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
10 11 12
	"github.com/gin-gonic/gin"
)

13
// @Tags SysApi
Mr.奇淼('s avatar
Mr.奇淼( 已提交
14
// @Summary 创建基础api
Mr.奇淼('s avatar
Mr.奇淼( 已提交
15 16 17
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
18
// @Param data body model.SysApi true "创建api"
19
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
20 21
// @Router /api/createApi [post]
func CreateApi(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22
	var api model.SysApi
23
	_ = c.ShouldBindJSON(&api)
24
	err := service.CreateApi(api)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
25
	if err != nil {
26
		response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
27
	} else {
28
		response.OkWithMessage("创建成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
29 30 31
	}
}

32
// @Tags SysApi
Mr.奇淼('s avatar
Mr.奇淼( 已提交
33
// @Summary 删除指定api
Mr.奇淼('s avatar
Mr.奇淼( 已提交
34 35 36
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
37
// @Param data body model.SysApi true "删除api"
38
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
39 40
// @Router /api/deleteApi [post]
func DeleteApi(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
41
	var a model.SysApi
42
	_ = c.ShouldBindJSON(&a)
43
	err := service.DeleteApi(a)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
44
	if err != nil {
45
		response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
46
	} else {
47
		response.OkWithMessage("删除成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
48 49
	}
}
50

51 52
//条件搜索后端看此api

53
// @Tags SysApi
Mr.奇淼('s avatar
Mr.奇淼( 已提交
54
// @Summary 分页获取API列表
55 56 57
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
Mr.奇淼('s avatar
Mr.奇淼( 已提交
58
// @Param data body request.SearchApiParams true "分页获取API列表"
59
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
60 61
// @Router /api/getApiList [post]
func GetApiList(c *gin.Context) {
62
	// 此结构体仅本方法使用
63
	var sp request.SearchApiParams
64
	_ = c.ShouldBindJSON(&sp)
65
	err, list, total := service.GetAPIInfoList(sp.SysApi, sp.PageInfo, sp.OrderKey, sp.Desc)
66
	if err != nil {
67
		response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
68
	} else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
69 70 71 72 73 74
		response.OkWithData(resp.PageResult{
			List:     list,
			Total:    total,
			Page:     sp.PageInfo.Page,
			PageSize: sp.PageInfo.PageSize,
		}, c)
75
	}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
76
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
77

78
// @Tags SysApi
Mr.奇淼('s avatar
Mr.奇淼( 已提交
79 80 81 82
// @Summary 根据id获取api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
Mr.奇淼('s avatar
Mr.奇淼( 已提交
83
// @Param data body request.GetById true "根据id获取api"
84
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
85 86
// @Router /api/getApiById [post]
func GetApiById(c *gin.Context) {
87
	var idInfo request.GetById
88
	_ = c.ShouldBindJSON(&idInfo)
89
	err, api := service.GetApiById(idInfo.Id)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
90
	if err != nil {
91
		response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
92
	} else {
93
		response.OkWithData(resp.SysAPIResponse{Api: api}, c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
94 95 96
	}
}

97
// @Tags SysApi
Mr.奇淼('s avatar
Mr.奇淼( 已提交
98 99 100 101
// @Summary 创建基础api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
102
// @Param data body model.SysApi true "创建api"
103
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
R
rainyan 已提交
104 105
// @Router /api/updateApi [post]
func UpdateApi(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
106
	var api model.SysApi
107
	_ = c.ShouldBindJSON(&api)
108
	err := service.UpdateApi(api)
109
	if err != nil {
110
		response.FailWithMessage(fmt.Sprintf("修改数据失败,%v", err), c)
111
	} else {
112
		response.OkWithMessage("修改数据成功", c)
113 114
	}
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
115

116
// @Tags SysApi
Mr.奇淼('s avatar
Mr.奇淼( 已提交
117 118 119 120
// @Summary 获取所有的Api 不分页
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
121
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
122
// @Router /api/getAllApis [post]
123
func GetAllApis(c *gin.Context) {
124
	err, apis := service.GetAllApis()
Mr.奇淼('s avatar
Mr.奇淼( 已提交
125
	if err != nil {
126
		response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
127
	} else {
128
		response.OkWithData(resp.SysAPIListResponse{Apis: apis}, c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
129
	}
130
}