Create update api for attachment.

pull/146/head
ruibaby 2019-04-20 12:26:52 +08:00
parent 9a8ade7b17
commit ff4f9c4bd6
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package run.halo.app.model.params;
import lombok.Data;
import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Attachment;
import javax.validation.constraints.NotBlank;
/**
* Attachment params.
*
* @author : RYAN0UP
* @date : 2019/04/20
*/
@Data
public class AttachmentParam implements InputConverter<Attachment> {
@NotBlank(message = "Attachment name must not be blank")
private String name;
}

View File

@ -9,9 +9,11 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import run.halo.app.model.dto.AttachmentOutputDTO; import run.halo.app.model.dto.AttachmentOutputDTO;
import run.halo.app.model.entity.Attachment; import run.halo.app.model.entity.Attachment;
import run.halo.app.model.params.AttachmentParam;
import run.halo.app.model.params.AttachmentQuery; import run.halo.app.model.params.AttachmentQuery;
import run.halo.app.service.AttachmentService; import run.halo.app.service.AttachmentService;
import javax.validation.Valid;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -58,6 +60,15 @@ public class AttachmentController {
return attachmentService.convertToDto(attachment); return attachmentService.convertToDto(attachment);
} }
@PutMapping("{attachmentId:\\d+}")
@ApiOperation("Updates a attachment")
public AttachmentOutputDTO updateBy(@PathVariable("attachmentId") Integer attachmentId,
@RequestBody @Valid AttachmentParam attachmentParam) {
Attachment attachment = attachmentService.getById(attachmentId);
attachmentParam.update(attachment);
return new AttachmentOutputDTO().convertFrom(attachmentService.update(attachment));
}
/** /**
* Delete attachment by id * Delete attachment by id
* *