mirror of https://github.com/halo-dev/halo
Create update api for attachment.
parent
9a8ade7b17
commit
ff4f9c4bd6
|
@ -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;
|
||||
}
|
|
@ -9,9 +9,11 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
import run.halo.app.model.dto.AttachmentOutputDTO;
|
||||
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.service.AttachmentService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -58,6 +60,15 @@ public class AttachmentController {
|
|||
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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue