/
import.go
87 lines (74 loc) · 2.64 KB
/
import.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
package handler
import (
"fmt"
domain "github.com/aaronchen2k/deeptest/cmd/server/v1/domain"
commService "github.com/aaronchen2k/deeptest/internal/pkg/service"
service "github.com/aaronchen2k/deeptest/internal/server/modules/service"
"github.com/aaronchen2k/deeptest/pkg/domain"
logUtils "github.com/aaronchen2k/deeptest/pkg/lib/log"
"github.com/getkin/kin-openapi/openapi3"
"github.com/kataras/iris/v12"
)
type ImportCtrl struct {
ImportService *service.ImportService `inject:""`
YapiService *service.YapiService `inject:""`
FileService *commService.FileService `inject:""`
BaseCtrl
}
// ImportSpec
// @Tags 导入模块
// @summary 导入OpenApi文件
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param targetId query int true "targetId"
// @success 200 {object} _domain.Response
// @Router /api/v1/import/importSpec [post]
func (c *ImportCtrl) ImportSpec(ctx iris.Context) {
targetId, err := ctx.URLParamInt("targetId")
if targetId == 0 {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
var req openapi3.T
err = ctx.ReadJSON(&req)
if err != nil {
logUtils.Errorf("参数验证失败", err.Error())
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
c.ImportService.Import(req, targetId)
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Msg: _domain.NoErr.Msg})
return
}
// ImportYapi
// @Tags 导入模块
// @summary 导入yapi项目接口
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param InterfaceYapiReq body serverDomain.InterfaceYapiReq true "导入yapi项目接口的请求参数"
// @success 200 {object} _domain.Response
// @Router /api/v1/import/importYapi [post]
func (c *ImportCtrl) ImportYapi(ctx iris.Context) {
projectId, err := ctx.URLParamInt("currProjectId")
fmt.Println("projectId", projectId)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
req := domain.InterfaceYapiReq{}
err = ctx.ReadJSON(&req)
if err != nil {
logUtils.Errorf("参数验证失败", err.Error())
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
fmt.Println("InterfaceYapiReq", req)
req.ProjectId = projectId
c.YapiService.ImportYapiProject(req)
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Msg: _domain.NoErr.Msg})
return
}