/
plan-exec.go
126 lines (109 loc) · 4.37 KB
/
plan-exec.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
package handler
import (
"github.com/aaronchen2k/deeptest/internal/agent/exec/domain"
"github.com/aaronchen2k/deeptest/internal/server/modules/service"
"github.com/aaronchen2k/deeptest/pkg/domain"
"github.com/kataras/iris/v12"
"github.com/snowlyg/multi"
)
type PlanExecCtrl struct {
PlanExecService *service.PlanExecService `inject:""`
BaseCtrl
}
// LoadExecData
// @Tags 测试计划/执行计划
// @summary 加载执行计划
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param id query int true "计划ID"
// @Param environmentId query int true "环境ID"
// @success 200 {object} _domain.Response{data=agentExec.PlanExecObj}
// @Router /api/v1/plans/exec/loadExecPlan [get]
func (c *PlanExecCtrl) LoadExecData(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
id, err := ctx.URLParamInt("id")
environmentId, err := ctx.URLParamInt("environmentId")
data, err := c.PlanExecService.LoadExecData(tenantId, id, environmentId)
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, Msg: _domain.NoErr.Msg})
}
// LoadExecResult
// @Tags 测试计划/执行计划
// @summary 加载执行结果
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param planId query int true "计划ID"
// @success 200 {object} _domain.Response{data=domain.Report}
// @Router /api/v1/plans/exec/loadExecResult [get]
func (c *PlanExecCtrl) LoadExecResult(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
scenarioId, err := ctx.URLParamInt("planId")
data, err := c.PlanExecService.LoadExecResult(tenantId, scenarioId)
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, Msg: _domain.NoErr.Msg})
}
// SubmitResult
// @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"
// @Param PlanExecResult body agentDomain.PlanExecResult true "提交计划测试结果的请求参数"
// @success 200 {object} _domain.Response{data=model.PlanReport}
// @Router /api/v1/plans/exec/submitResult/{id} [post]
func (c *PlanExecCtrl) SubmitResult(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
planId, err := ctx.Params().GetInt("id")
result := agentDomain.PlanExecResult{}
err = ctx.ReadJSON(&result)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
userId := multi.GetUserId(ctx)
report, err := c.PlanExecService.SaveReport(tenantId, planId, userId, result)
// report.Logs = nil // otherwise will cause a json parse err on agent size
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: report})
}
// GetPlanReportNormalData
// @Tags 测试计划/执行计划
// @summary 获取计划执行中的静态内容
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param id query int true "计划ID"
// @Param environmentId query int true "环境ID"
// @success 200 {object} _domain.Response{data=agentDomain.Report}
// @Router /api/v1/plans/exec/getPlanReportNormalData [get]
func (c *PlanExecCtrl) GetPlanReportNormalData(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
planId, err := ctx.URLParamInt("id")
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
environmentId, err := ctx.URLParamInt("environmentId")
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
data, err := c.PlanExecService.GetPlanReportNormalData(tenantId, uint(planId), uint(environmentId))
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: _domain.ParamErr.Msg})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: data})
}