Skip to content

Commit

Permalink
creat new controller
Browse files Browse the repository at this point in the history
  • Loading branch information
XuCpeng committed Apr 16, 2021
1 parent 7be086b commit 269505a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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<AttachmentDTO> pageBy(
@PageableDefault(sort = "createTime", direction = DESC) Pageable pageable,
AttachmentQuery attachmentQuery) {
@PageableDefault(sort = "createTime", direction = DESC) Pageable pageable,
AttachmentQuery attachmentQuery) {
return attachmentService.pageDtosBy(pageable, attachmentQuery);
}

Expand All @@ -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));
Expand Down Expand Up @@ -110,18 +110,4 @@ public List<String> listMediaTypes() {
public List<AttachmentType> listTypes() {
return attachmentService.listAllType();
}

@PutMapping("covert_attachment_handler")
@ApiOperation("Covert all attachments to current Handler.")
public Future<String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}

0 comments on commit 269505a

Please sign in to comment.