1. 添加部分swagger文档
This commit is contained in:
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/proobj")
|
||||
public class ProtectObjectController {
|
||||
public class ProtectObjectController implements ProtectObjectControllerApi {
|
||||
|
||||
private final ProtectObjectService protectObjectService;
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ProtectObjectController {
|
||||
this.protectObjectService = protectObjectService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/new")
|
||||
public ResponseResult newProtectObject(@RequestBody @Valid ProtectObject protectObject) {
|
||||
Integer protectObjectId = protectObjectService.newProtectObject(protectObject);
|
||||
@@ -42,15 +43,17 @@ public class ProtectObjectController {
|
||||
.setData("success", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/upload")
|
||||
public ResponseResult uploadFile(
|
||||
@NotNull(message = "uploadFile cannot be null") MultipartFile uploadFile
|
||||
@NotNull(message = "uploadFile cannot be null. ") MultipartFile uploadFile
|
||||
) throws IOException {
|
||||
EasyExcel.read(uploadFile.getInputStream(), ProtectObject.class,
|
||||
new ProjectObjectDataListener(protectObjectService)).sheet().doRead();
|
||||
return ResponseResult.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/download")
|
||||
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
@@ -64,6 +67,7 @@ public class ProtectObjectController {
|
||||
.doWrite(List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/query")
|
||||
public ResponseResult queryProtectObjects(@RequestParam(value = "proobj_name", required = false)
|
||||
String protectObjectName,
|
||||
@@ -77,6 +81,7 @@ public class ProtectObjectController {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/{protectObjectId}/query")
|
||||
public ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException {
|
||||
ProtectObject protectObject = protectObjectService.queryProtectObject(protectObjectId);
|
||||
@@ -84,6 +89,7 @@ public class ProtectObjectController {
|
||||
.setDataMap(EntityUtils.entityToMap(protectObject));
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/{protectObjectId}/update")
|
||||
public ResponseResult updateProtectObject(@PathVariable Integer protectObjectId,
|
||||
@RequestBody @Valid ProtectObject protectObject) {
|
||||
@@ -93,6 +99,7 @@ public class ProtectObjectController {
|
||||
.setData("success", protectObjectService.updateProtectObject(protectObject));
|
||||
}
|
||||
|
||||
@Override
|
||||
@DeleteMapping("/{protectObjectId}/delete")
|
||||
public ResponseResult deleteProtectObject(@PathVariable Integer protectObjectId) {
|
||||
return ResponseResult.ok()
|
||||
@@ -100,14 +107,16 @@ public class ProtectObjectController {
|
||||
.setData("success", protectObjectService.deleteProtectObject(protectObjectId));
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseResult deleteProtectObject(@RequestBody List<Integer> protectObjectIds) {
|
||||
@Override
|
||||
@DeleteMapping("/delete/{protectObjectIds}")
|
||||
public ResponseResult deleteProtectObject(@PathVariable List<Integer> protectObjectIds) {
|
||||
return ResponseResult.ok()
|
||||
.setData("proobj_ids", protectObjectIds)
|
||||
.setData("success", protectObjectService.deleteProtectObjects(protectObjectIds));
|
||||
}
|
||||
|
||||
@PostMapping("/{protectObjectId}/audit/{auditStatus}")
|
||||
@Override
|
||||
@GetMapping("/{protectObjectId}/audit/{auditStatus}")
|
||||
public ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId,
|
||||
@PathVariable Integer auditStatus) {
|
||||
return ResponseResult.ok()
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.realtime.protection.server.defense.object;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.apache.coyote.Response;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "防护对象API", description = "防护对象模块所有接口")
|
||||
public interface ProtectObjectControllerApi {
|
||||
@PostMapping("/new")
|
||||
@Operation(
|
||||
summary = "新建防护对象",
|
||||
description = "新建一个防护对象",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回新建对象结果",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "防护对象信息")
|
||||
)
|
||||
ResponseResult newProtectObject(@RequestBody @Valid ProtectObject protectObject);
|
||||
|
||||
@PostMapping("/upload")
|
||||
@Operation(
|
||||
summary = "批量上传防护对象",
|
||||
description = "使用模板文件上传并新建多个防护对象",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回批量上传新建对象结果",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "上传文件")
|
||||
)
|
||||
ResponseResult uploadFile(
|
||||
@NotNull(message = "uploadFile cannot be null. ") MultipartFile uploadFile
|
||||
) throws IOException;
|
||||
|
||||
@GetMapping("/download")
|
||||
@Operation(
|
||||
summary = "下载模板文件",
|
||||
description = "下载防护对象上传模板文件",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回防护对象模板文件",
|
||||
content = @Content(
|
||||
mediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
void downloadTemplate(HttpServletResponse response) throws IOException;
|
||||
|
||||
@GetMapping("/query")
|
||||
@Operation(
|
||||
summary = "根据条件查询多个防护对象",
|
||||
description = "根据查询条件和页码等,查询多个对象并以列表返回",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回多个防护对象",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
parameters = {
|
||||
@Parameter()
|
||||
}
|
||||
)
|
||||
ResponseResult queryProtectObjects(@RequestParam(value = "proobj_name", required = false)
|
||||
String protectObjectName,
|
||||
@RequestParam(value = "proobj_id", required = false) @Min(1)
|
||||
Integer protectObjectId,
|
||||
@RequestParam("page") @Min(1) Integer page,
|
||||
@RequestParam("page_size") @Min(1) Integer pageSize);
|
||||
|
||||
@GetMapping("/{protectObjectId}/query")
|
||||
ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException;
|
||||
|
||||
@PostMapping("/{protectObjectId}/update")
|
||||
ResponseResult updateProtectObject(@PathVariable Integer protectObjectId,
|
||||
@RequestBody @Valid ProtectObject protectObject);
|
||||
|
||||
@DeleteMapping("/{protectObjectId}/delete")
|
||||
ResponseResult deleteProtectObject(@PathVariable Integer protectObjectId);
|
||||
|
||||
@DeleteMapping("/delete/{protectObjectIds}")
|
||||
ResponseResult deleteProtectObject(@PathVariable List<Integer> protectObjectIds);
|
||||
|
||||
@GetMapping("/{protectObjectId}/audit/{auditStatus}")
|
||||
ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId,
|
||||
@PathVariable Integer auditStatus);
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/deftac")
|
||||
@RequestMapping("/template")
|
||||
public class TemplateController {
|
||||
|
||||
private final TemplateService templateService;
|
||||
@@ -21,15 +21,8 @@ public class TemplateController {
|
||||
|
||||
@PostMapping("/new")
|
||||
public ResponseResult newTemplate(@RequestBody @Valid Template template) {
|
||||
Integer templateId;
|
||||
try {
|
||||
templateId = templateService.newTemplate(template);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return new ResponseResult(400, "Illegal Argument in template_elements or default_op")
|
||||
.setData("template_id", null)
|
||||
.setData("success", false);
|
||||
}
|
||||
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
|
||||
if (templateId > 0) {
|
||||
return ResponseResult.ok()
|
||||
|
||||
Reference in New Issue
Block a user