Fix comment sort bug

pull/146/head
johnniang 2019-04-28 00:00:28 +08:00
parent 4c2f329a39
commit 72b396e57e
2 changed files with 8 additions and 14 deletions

View File

@ -80,15 +80,11 @@ public class JournalController {
return new JournalDTO().convertFrom(journalService.update(journal)); return new JournalDTO().convertFrom(journalService.update(journal));
} }
/**
* Delete journal by id.
*
* @param journalId journalId
*/
@DeleteMapping("{journalId:\\d+}") @DeleteMapping("{journalId:\\d+}")
@ApiOperation("Delete link by id") @ApiOperation("Delete journal")
public void deletePermanently(@PathVariable("journalId") Integer journalId) { public JournalDTO deleteBy(@PathVariable("journalId") Integer journalId) {
journalService.removeById(journalId); Journal deletedJournal = journalService.removeById(journalId);
return journalService.convertTo(deletedJournal);
} }
@GetMapping("{journalId:\\d+}/comments/tree_view") @GetMapping("{journalId:\\d+}/comments/tree_view")

View File

@ -16,7 +16,6 @@ import org.springframework.util.CollectionUtils;
import run.halo.app.event.comment.CommentNewEvent; import run.halo.app.event.comment.CommentNewEvent;
import run.halo.app.event.comment.CommentPassEvent; import run.halo.app.event.comment.CommentPassEvent;
import run.halo.app.event.comment.CommentReplyEvent; import run.halo.app.event.comment.CommentReplyEvent;
import run.halo.app.exception.NotFoundException;
import run.halo.app.model.dto.BaseCommentDTO; import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.entity.BaseComment; import run.halo.app.model.entity.BaseComment;
import run.halo.app.model.entity.User; import run.halo.app.model.entity.User;
@ -29,7 +28,6 @@ import run.halo.app.model.properties.CommentProperties;
import run.halo.app.model.support.CommentPage; import run.halo.app.model.support.CommentPage;
import run.halo.app.model.vo.BaseCommentVO; import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO; import run.halo.app.model.vo.BaseCommentWithParentVO;
import run.halo.app.repository.PostRepository;
import run.halo.app.repository.base.BaseCommentRepository; import run.halo.app.repository.base.BaseCommentRepository;
import run.halo.app.security.authentication.Authentication; import run.halo.app.security.authentication.Authentication;
import run.halo.app.security.context.SecurityContextHolder; import run.halo.app.security.context.SecurityContextHolder;
@ -359,16 +357,16 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
Assert.notNull(toCompareComment, "Comment to compare must not be null"); Assert.notNull(toCompareComment, "Comment to compare must not be null");
// Get sort order // Get sort order
Sort.Order order = sort.filter(anOrder -> anOrder.getProperty().equals("createTime")) Sort.Order order = sort.filter(anOrder -> anOrder.getProperty().equals("id"))
.get() .get()
.findFirst() .findFirst()
.orElseGet(() -> Sort.Order.desc("createTime")); .orElseGet(() -> Sort.Order.desc("id"));
// Init sign // Init sign
int sign = order.getDirection().isAscending() ? 1 : -1; int sign = order.getDirection().isAscending() ? 1 : -1;
// Compare createTime property // Compare id property
return sign * currentComment.getCreateTime().compareTo(toCompareComment.getCreateTime()); return sign * currentComment.getId().compareTo(toCompareComment.getId());
}; };
} }