From 269505aeec92ad9e2151b84b6f46ff879135f130 Mon Sep 17 00:00:00 2001 From: Stardust Date: Fri, 16 Apr 2021 23:59:05 +0800 Subject: [PATCH] creat new controller --- .../admin/api/AttachmentController.java | 52 +++++++------------ .../AttachmentHandlerCovertController.java | 36 +++++++++++++ 2 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 src/main/java/run/halo/app/controller/admin/api/AttachmentHandlerCovertController.java diff --git a/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java b/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java index 64fa3dca81d..a32ef675092 100644 --- a/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java +++ b/src/main/java/run/halo/app/controller/admin/api/AttachmentController.java @@ -1,27 +1,32 @@ package run.halo.app.controller.admin.api; +import static org.springframework.data.domain.Sort.Direction.DESC; + import io.swagger.annotations.ApiOperation; +import java.util.LinkedList; +import java.util.List; +import javax.validation.Valid; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import run.halo.app.model.dto.AttachmentDTO; import run.halo.app.model.entity.Attachment; import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.params.AttachmentParam; import run.halo.app.model.params.AttachmentQuery; -import run.halo.app.service.AttachmentHandlerCovertService; import run.halo.app.service.AttachmentService; -import javax.validation.Valid; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.Future; - -import static org.springframework.data.domain.Sort.Direction.DESC; - /** * Attachment controller. * @@ -33,19 +38,15 @@ public class AttachmentController { private final AttachmentService attachmentService; - private final AttachmentHandlerCovertService attachmentHandlerCovertService; - public AttachmentController( - AttachmentService attachmentService, - AttachmentHandlerCovertService attachmentHandlerCovertService) { + public AttachmentController(AttachmentService attachmentService) { this.attachmentService = attachmentService; - this.attachmentHandlerCovertService = attachmentHandlerCovertService; } @GetMapping public Page pageBy( - @PageableDefault(sort = "createTime", direction = DESC) Pageable pageable, - AttachmentQuery attachmentQuery) { + @PageableDefault(sort = "createTime", direction = DESC) Pageable pageable, + AttachmentQuery attachmentQuery) { return attachmentService.pageDtosBy(pageable, attachmentQuery); } @@ -58,9 +59,8 @@ public AttachmentDTO getBy(@PathVariable("id") Integer id) { @PutMapping("{attachmentId:\\d+}") @ApiOperation("Updates a attachment") - public AttachmentDTO updateBy( - @PathVariable("attachmentId") Integer attachmentId, - @RequestBody @Valid AttachmentParam attachmentParam) { + public AttachmentDTO updateBy(@PathVariable("attachmentId") Integer attachmentId, + @RequestBody @Valid AttachmentParam attachmentParam) { Attachment attachment = attachmentService.getById(attachmentId); attachmentParam.update(attachment); return new AttachmentDTO().convertFrom(attachmentService.update(attachment)); @@ -110,18 +110,4 @@ public List listMediaTypes() { public List listTypes() { return attachmentService.listAllType(); } - - @PutMapping("covert_attachment_handler") - @ApiOperation("Covert all attachments to current Handler.") - public Future covertAttachmentHandler( - @RequestParam(name = "sourceAttachmentType", required = false, defaultValue = "LOCAL") AttachmentType sourceAttachmentType, - @RequestParam(name = "deleteOldAttachment", required = false, defaultValue = "false") Boolean deleteOldAttachment, - @RequestParam(name = "uploadAllInAttachment", required = false, defaultValue = "false") Boolean uploadAllInAttachment, - @RequestParam(name = "uploadAllInPost", required = false, defaultValue = "false") Boolean uploadAllInPost) { - return attachmentHandlerCovertService.covertHandlerByPosts( - sourceAttachmentType, - deleteOldAttachment, - uploadAllInAttachment, - uploadAllInPost); - } } diff --git a/src/main/java/run/halo/app/controller/admin/api/AttachmentHandlerCovertController.java b/src/main/java/run/halo/app/controller/admin/api/AttachmentHandlerCovertController.java new file mode 100644 index 00000000000..4564657d21b --- /dev/null +++ b/src/main/java/run/halo/app/controller/admin/api/AttachmentHandlerCovertController.java @@ -0,0 +1,36 @@ +package run.halo.app.controller.admin.api; + +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import run.halo.app.model.enums.AttachmentType; +import run.halo.app.service.AttachmentHandlerCovertService; + +import java.util.concurrent.Future; + +@RestController +@RequestMapping("/api/admin/attachments") +public class AttachmentHandlerCovertController { + private final AttachmentHandlerCovertService attachmentHandlerCovertService; + + public AttachmentHandlerCovertController(AttachmentHandlerCovertService attachmentHandlerCovertService) { + this.attachmentHandlerCovertService = attachmentHandlerCovertService; + } + + + @PutMapping("covert_attachment_handler") + @ApiOperation("Covert all attachments to current Handler.") + public Future covertAttachmentHandler( + @RequestParam(name = "sourceAttachmentType", required = false, defaultValue = "LOCAL") AttachmentType sourceAttachmentType, + @RequestParam(name = "deleteOldAttachment", required = false, defaultValue = "false") Boolean deleteOldAttachment, + @RequestParam(name = "uploadAllInAttachment", required = false, defaultValue = "false") Boolean uploadAllInAttachment, + @RequestParam(name = "uploadAllInPost", required = false, defaultValue = "false") Boolean uploadAllInPost) { + return attachmentHandlerCovertService.covertHandlerByPosts( + sourceAttachmentType, + deleteOldAttachment, + uploadAllInAttachment, + uploadAllInPost); + } +} \ No newline at end of file