/
endpoint-mock-script.go
82 lines (72 loc) · 2.59 KB
/
endpoint-mock-script.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
package handler
import (
"github.com/aaronchen2k/deeptest/internal/server/modules/model"
"github.com/aaronchen2k/deeptest/internal/server/modules/service"
"github.com/aaronchen2k/deeptest/pkg/domain"
"github.com/kataras/iris/v12"
)
type EndpointMockScriptCtrl struct {
EndpointMockScriptService *service.EndpointMockScriptService `inject:""`
BaseCtrl
}
// Get
// @Tags Mock脚本管理
// @summary 脚本详情
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param endpointId path int true "Endpoint ID"
// @success 200 {object} _domain.Response{data=model.EndpointMockScript}
// @Router /api/v1/mockScripts/{id} [get]
func (c *EndpointMockScriptCtrl) Get(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
endpointId, err := ctx.Params().GetInt("endpointId")
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
ret, err := c.EndpointMockScriptService.Get(tenantId, uint(endpointId))
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: ret, Msg: _domain.NoErr.Msg})
}
// Update
// @Tags Mock脚本管理
// @summary 更新脚本
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param EndpointMockScript body model.EndpointMockScript true "update Mock Script Object"
// @success 200 {object} _domain.Response
// @Router /api/v1/mockScripts [put]
func (c *EndpointMockScriptCtrl) Update(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
var req model.EndpointMockScript
err := ctx.ReadJSON(&req)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
}
err = c.EndpointMockScriptService.Update(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})
}
func (c *EndpointMockScriptCtrl) Disable(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
endpointId, err := ctx.Params().GetInt("endpointId")
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
err = c.EndpointMockScriptService.Disable(tenantId, uint(endpointId))
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: _domain.SystemErr.Msg})
return
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Msg: _domain.NoErr.Msg})
}