mirror of https://github.com/halo-dev/halo
Complete page attachments api
parent
24a1888247
commit
082aee6715
|
@ -0,0 +1,60 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import cc.ryanc.halo.model.entity.Attachment;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Attachment output dto.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/21/19
|
||||
*/
|
||||
@Data
|
||||
public class AttachmentOutputDTO implements OutputConverter<AttachmentOutputDTO, Attachment> {
|
||||
|
||||
/**
|
||||
* Attachment id.
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 附件名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 附件路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 缩略图路径
|
||||
*/
|
||||
private String thumbPath;
|
||||
|
||||
/**
|
||||
* 附件类型
|
||||
*/
|
||||
private String mediaType;
|
||||
|
||||
/**
|
||||
* 附件后缀
|
||||
*/
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 附件尺寸
|
||||
*/
|
||||
private String dimension;
|
||||
|
||||
/**
|
||||
* 附件大小
|
||||
*/
|
||||
private String size;
|
||||
|
||||
/**
|
||||
* 附件上传类型
|
||||
*/
|
||||
private Integer type;
|
||||
}
|
|
@ -13,6 +13,8 @@ import lombok.Data;
|
|||
@Data
|
||||
public class TagOutputDTO implements OutputConverter<TagOutputDTO, Tag> {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String slugName;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.dto.AttachmentOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Attachment;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -11,4 +14,11 @@ import cc.ryanc.halo.service.base.CrudService;
|
|||
*/
|
||||
public interface AttachmentService extends CrudService<Attachment, Integer> {
|
||||
|
||||
/**
|
||||
* Pages attachment output dtos.
|
||||
*
|
||||
* @param pageable page info must not be null
|
||||
* @return a page of attachment output dto
|
||||
*/
|
||||
Page<AttachmentOutputDTO> pageDtosBy(Pageable pageable);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.dto.AttachmentOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Attachment;
|
||||
import cc.ryanc.halo.repository.AttachmentRepository;
|
||||
import cc.ryanc.halo.service.AttachmentService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* AttachmentService implementation class
|
||||
|
@ -21,4 +25,15 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
|
|||
super(attachmentRepository);
|
||||
this.attachmentRepository = attachmentRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<AttachmentOutputDTO> pageDtosBy(Pageable pageable) {
|
||||
Assert.notNull(pageable, "Page info must not be null");
|
||||
|
||||
// List all
|
||||
Page<Attachment> attachmentPage = listAll(pageable);
|
||||
|
||||
// Convert and return
|
||||
return attachmentPage.map(attachment -> new AttachmentOutputDTO().convertFrom(attachment));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package cc.ryanc.halo.web.controller.admin.api;
|
||||
|
||||
import cc.ryanc.halo.model.dto.AttachmentOutputDTO;
|
||||
import cc.ryanc.halo.service.AttachmentService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* Attachment controller.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/21/19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/api/attachments")
|
||||
public class AttachmentController {
|
||||
|
||||
private final AttachmentService attachmentService;
|
||||
|
||||
public AttachmentController(AttachmentService attachmentService) {
|
||||
this.attachmentService = attachmentService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Page<AttachmentOutputDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||
return attachmentService.pageDtosBy(pageable);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue