Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
holmes
Commits
f342d9f1
Commit
f342d9f1
authored
Apr 09, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增接口相关接口
parent
67a055e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
3 deletions
+99
-3
InterfaceController.java
...ava/cn/qg/holmes/controller/auto/InterfaceController.java
+98
-0
Interface.java
src/main/java/cn/qg/holmes/entity/auto/Interface.java
+1
-3
No files found.
src/main/java/cn/qg/holmes/controller/auto/InterfaceController.java
View file @
f342d9f1
package
cn
.
qg
.
holmes
.
controller
.
auto
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.entity.auto.Interface
;
import
cn.qg.holmes.service.auto.AutoModuleService
;
import
cn.qg.holmes.service.auto.InterfaceService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 接口相关controller
* @author libo
*/
@CrossOrigin
@RestController
@RequestMapping
(
"/auto/interface"
)
public
class
InterfaceController
{
@Autowired
InterfaceService
interfaceService
;
@Autowired
AutoModuleService
autoModuleService
;
/**
* 获取接口列表
* @param moduleId 非必传
* @param pageNum 第几页
* @param pageSize 每页数量
* @return
*/
@GetMapping
(
"/list"
)
public
JsonResult
getInterfaceList
(
Integer
moduleId
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNum
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
pageSize
)
{
IPage
<
Interface
>
interfaceIPage
=
new
Page
<>(
pageNum
,
pageSize
);
IPage
<
Interface
>
interfaceIPageEntity
;
if
(
moduleId
!=
null
)
{
QueryWrapper
<
Interface
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"module_id"
,
moduleId
);
interfaceIPageEntity
=
interfaceService
.
page
(
interfaceIPage
,
queryWrapper
);
}
else
{
interfaceIPageEntity
=
interfaceService
.
page
(
interfaceIPage
);
}
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"total"
,
interfaceIPageEntity
.
getTotal
());
map
.
put
(
"list"
,
interfaceIPageEntity
.
getRecords
());
return
JsonResult
.
buildSuccessResult
(
map
);
}
/**
* 新增接口
* @param interfaceEntity 接口类实体
* @return
*/
@PostMapping
(
"/add"
)
public
JsonResult
addInterface
(
@RequestBody
Interface
interfaceEntity
)
{
QueryWrapper
<
Interface
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"module_id"
,
interfaceEntity
.
getModuleId
());
queryWrapper
.
eq
(
"url"
,
interfaceEntity
.
getUrl
());
if
(
autoModuleService
.
getById
(
interfaceEntity
.
getModuleId
())
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"模块不存在!"
,
false
);
}
if
(
interfaceService
.
getOne
(
queryWrapper
)
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"接口已存在!"
,
false
);
}
else
{
return
JsonResult
.
buildSuccessResult
(
interfaceService
.
save
(
interfaceEntity
));
}
}
/**
* 编辑接口
* @param interfaceEntity 接口实体类
* @return
*/
@PostMapping
(
"/modify"
)
public
JsonResult
modifyInterface
(
@RequestBody
Interface
interfaceEntity
)
{
if
(
interfaceService
.
getById
(
interfaceEntity
.
getId
())
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"接口不存在!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
interfaceService
.
updateById
(
interfaceEntity
));
}
/**
* 删除接口
* @param interfaceId 接口id
* @return
*/
@GetMapping
(
"/delete"
)
public
JsonResult
deleteInterface
(
@RequestParam
Integer
interfaceId
)
{
if
(
interfaceService
.
getById
(
interfaceId
)
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"接口不存在!"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
interfaceService
.
removeById
(
interfaceId
));
}
}
src/main/java/cn/qg/holmes/entity/auto/Interface.java
View file @
f342d9f1
...
...
@@ -20,9 +20,7 @@ public class Interface {
private
String
method
;
private
String
headers
;
private
String
paramType
;
private
String
requestTemplate
;
private
String
responseTemplate
;
private
String
author
;
private
String
paramTemplate
;
private
Integer
moduleId
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
createTime
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment