/
debug-invoke.go
210 lines (186 loc) · 6.98 KB
/
debug-invoke.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package handler
import (
"github.com/aaronchen2k/deeptest/internal/pkg/domain"
"github.com/aaronchen2k/deeptest/internal/server/modules/model"
service "github.com/aaronchen2k/deeptest/internal/server/modules/service"
"github.com/aaronchen2k/deeptest/pkg/domain"
"github.com/kataras/iris/v12"
)
type DebugInvokeCtrl struct {
DebugInvokeService *service.DebugInvokeService `inject:""`
ExtractorService *service.ExtractorService `inject:""`
CheckpointService *service.CheckpointService `inject:""`
BaseCtrl
}
// SubmitResult
// @Tags 接口调试
// @summary Agent提交接口执行结果
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param SubmitDebugResultRequest body domain.SubmitDebugResultRequest true "Agent提交接口执行结果的请求体"
// @success 200 {object} _domain.Response
// @Router /api/v1/debugs/invoke/submitResult [post]
func (c *DebugInvokeCtrl) SubmitResult(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
req := domain.SubmitDebugResultRequest{}
err := ctx.ReadJSON(&req)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
var invoke model.DebugInvoke
invoke, err = c.DebugInvokeService.SubmitResult(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, Data: invoke.ID})
}
// List
// @Tags 接口调试
// @summary 调试记录列表
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param debugInterfaceId query int true "debugInterfaceId"
// @Param endpointInterfaceId query int true "endpointInterfaceId"
// @success 200 {object} _domain.Response{data=[]model.DebugInvoke}
// @Router /api/v1/debugs/invoke [get]
func (c *DebugInvokeCtrl) List(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
debugInterfaceId, err := ctx.URLParamInt("debugInterfaceId")
endpointInterfaceId, err := ctx.URLParamInt("endpointInterfaceId")
if debugInterfaceId <= 0 && endpointInterfaceId <= 0 {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
if debugInterfaceId < 0 {
debugInterfaceId = 0
}
if endpointInterfaceId < 0 {
endpointInterfaceId = 0
}
data, err := c.DebugInvokeService.ListByInterface(tenantId, uint(debugInterfaceId), uint(endpointInterfaceId))
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})
}
// GetLastResp
// @Tags 接口调试
// @summary 获取最后调试记录响应
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param debugInterfaceId query int true "debugInterfaceId"
// @Param endpointInterfaceId query int true "endpointInterfaceId"
// @success 200 {object} _domain.Response{data=domain.DebugResponse}
// @Router /api/v1/debugs/invoke/getLastResp [get]
func (c *DebugInvokeCtrl) GetLastResp(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
debugInterfaceId, err := ctx.URLParamInt("debugInterfaceId")
endpointInterfaceId, err := ctx.URLParamInt("endpointInterfaceId")
if debugInterfaceId <= 0 && endpointInterfaceId <= 0 {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
if debugInterfaceId < 0 {
debugInterfaceId = 0
}
if endpointInterfaceId < 0 {
endpointInterfaceId = 0
}
reqAndResp, err := c.DebugInvokeService.GetLastResp(tenantId, uint(debugInterfaceId), uint(endpointInterfaceId))
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: _domain.SystemErr.Msg})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: reqAndResp})
}
// GetResult 获取调用结果细节
func (c *DebugInvokeCtrl) GetResult(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
invokeId, err := ctx.URLParamInt("invokeId")
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
result, err := c.DebugInvokeService.GetResult(tenantId, invokeId)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: _domain.SystemErr.Msg})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: result})
}
// GetLog 获取调用日志
func (c *DebugInvokeCtrl) GetLog(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
invokeId, err := ctx.URLParamInt("invokeId")
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
result, err := c.DebugInvokeService.GetLog(tenantId, invokeId)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: _domain.SystemErr.Msg})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: result})
}
// GetAsInterface 详情
// @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{data=object{debugData=domain.DebugData,resp=domain.DebugResponse}}
// @Router /api/v1/debugs/invoke/{id} [get]
func (c *DebugInvokeCtrl) GetAsInterface(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
}
debugData, resultReq, resultResp, err := c.DebugInvokeService.GetAsInterface(tenantId, id)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: _domain.SystemErr.Msg})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: iris.Map{
"debugData": debugData,
"req": resultReq,
"resp": resultResp,
}})
}
// 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/debugs/invoke/{id} [delete]
func (c *DebugInvokeCtrl) 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: err.Error()})
return
}
err = c.DebugInvokeService.Delete(tenantId, uint(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})
}