Complete journal comment list api

pull/146/head
johnniang 2019-04-25 20:10:07 +08:00
parent ef2c2b2759
commit c9bfd11cd5
5 changed files with 33 additions and 23 deletions

View File

@ -2,7 +2,10 @@ package run.halo.app.controller.admin.api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;
import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.dto.JournalDTO;
@ -11,12 +14,17 @@ import run.halo.app.model.entity.Journal;
import run.halo.app.model.entity.JournalComment;
import run.halo.app.model.params.JournalCommentParam;
import run.halo.app.model.params.JournalParam;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.JournalService;
import run.halo.app.service.OptionService;
import javax.validation.Valid;
import java.util.List;
import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Journal controller.
*
@ -31,10 +39,14 @@ public class JournalController {
private final JournalCommentService journalCommentService;
private final OptionService optionService;
public JournalController(JournalService journalService,
JournalCommentService journalCommentService) {
JournalCommentService journalCommentService,
OptionService optionService) {
this.journalService = journalService;
this.journalCommentService = journalCommentService;
this.optionService = optionService;
}
@GetMapping
@ -64,4 +76,20 @@ public class JournalController {
JournalComment journalComment = journalCommentService.createBy(journalCommentParam);
return journalCommentService.convertTo(journalComment);
}
@GetMapping("{journalId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentTree(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageVosBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
@GetMapping("{journalId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageWithParentVoBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
}

View File

@ -1,4 +1,4 @@
package run.halo.app.controller.admin;
package run.halo.app.controller.admin.api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

View File

@ -1,18 +0,0 @@
package run.halo.app.model.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Comment output dto.
*
* @author johnniang
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Deprecated
public class CommentDTO extends BaseCommentDTO {
}

View File

@ -22,7 +22,7 @@ public interface InputConverter<DOMAIN> {
@SuppressWarnings("unchecked")
default DOMAIN convertTo() {
// Get parameterized type
ParameterizedType currentType = getParameterizedType();
ParameterizedType currentType = parameterizedType();
// Assert not equal
Objects.requireNonNull(currentType, "Cannot fetch actual type because parameterized type is null");
@ -47,7 +47,7 @@ public interface InputConverter<DOMAIN> {
* @return parameterized type or null
*/
@Nullable
default ParameterizedType getParameterizedType() {
default ParameterizedType parameterizedType() {
return ReflectionUtils.getParameterizedType(InputConverter.class, this.getClass());
}
}

View File

@ -42,7 +42,7 @@ public abstract class BaseCommentParam<COMMENT> implements InputConverter<COMMEN
private Long parentId = 0L;
@Override
public ParameterizedType getParameterizedType() {
public ParameterizedType parameterizedType() {
return ReflectionUtils.getParameterizedTypeBySuperClass(BaseCommentParam.class, this.getClass());
}
}