/
share-var.go
98 lines (87 loc) · 3.05 KB
/
share-var.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package handler
import (
"github.com/aaronchen2k/deeptest/internal/pkg/domain"
"github.com/aaronchen2k/deeptest/internal/server/modules/service"
"github.com/aaronchen2k/deeptest/pkg/domain"
"github.com/kataras/iris/v12"
)
type ShareVarCtrl struct {
ShareVarService *service.ShareVarService `inject:""`
BaseCtrl
}
// List
// @Tags 共享变量
// @summary 列出变量列表
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param DebugInfo body domain.DebugInfo true "列出变量列表的请求参数"
// @success 200 {object} _domain.Response{data=[]domain.GlobalVar}
// @Router /api/v1/shareVars/list [post]
func (c *ShareVarCtrl) List(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
req := domain.DebugInfo{}
err := ctx.ReadJSON(&req)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
data := c.ShareVarService.List(tenantId, req.DebugInterfaceId,
req.EndpointInterfaceId, req.DiagnoseInterfaceId, req.CaseInterfaceId, req.ScenarioProcessorId,
req.UsedBy)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: data})
}
// Delete 删除
// @Tags 共享变量
// @summary 删除共享变量
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param id path int true "变量ID"
// @success 200 {object} _domain.Response
// @Router /api/v1/shareVars/{id} [delete]
func (c *ShareVarCtrl) Delete(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
id, err := ctx.Params().GetInt("id")
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
err = c.ShareVarService.Delete(tenantId, id)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Msg: _domain.NoErr.Msg})
}
// Clear 清除
// @Tags 共享变量
// @summary 清空共享变量
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param DebugInfo body domain.DebugInfo true "清空共享变量的请求参数"
// @success 200 {object} _domain.Response
// @Router /api/v1/shareVars/clear [post]
func (c *ShareVarCtrl) Clear(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
req := domain.DebugInfo{}
err := ctx.ReadJSON(&req)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
err = c.ShareVarService.Clear(tenantId, req)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Msg: _domain.NoErr.Msg})
}