diff --git a/src/main/java/cc/ryanc/halo/model/support/HaloConst.java b/src/main/java/cc/ryanc/halo/model/support/HaloConst.java index c57c21f91..d4b17b319 100644 --- a/src/main/java/cc/ryanc/halo/model/support/HaloConst.java +++ b/src/main/java/cc/ryanc/halo/model/support/HaloConst.java @@ -1,7 +1,5 @@ package cc.ryanc.halo.model.support; -import cn.hutool.json.JSONObject; - import java.util.Collections; import java.util.List; import java.util.Map; @@ -33,13 +31,7 @@ public class HaloConst { public static final String TOKEN_HEADER = "token"; /** - * All of the Owo - */ - @Deprecated - public static JSONObject OWO; - - /** - * Owo map. (Unmodified) + * Owo map. (Unmodified map) */ public static Map OWO_MAP = Collections.emptyMap(); diff --git a/src/main/java/cc/ryanc/halo/model/support/JsonResult.java b/src/main/java/cc/ryanc/halo/model/support/JsonResult.java deleted file mode 100644 index d6d52e940..000000000 --- a/src/main/java/cc/ryanc/halo/model/support/JsonResult.java +++ /dev/null @@ -1,168 +0,0 @@ -package cc.ryanc.halo.model.support; - -import lombok.Data; -import org.springframework.http.HttpStatus; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; - -/** - *
- *     Json格式
- * 
- * - * @author : RYAN0UP - * @date : 2018/5/24 - */ -@Data -@Deprecated -public class JsonResult { - - /** - * 返回的状态码 (Same as HttpStatus.value()). - */ - private Integer code; - - /** - * 返回信息 - */ - private String msg; - - /** - * Development message.(Development environment only) - */ - private String devMsg; - - /** - * 返回的数据 - */ - private Object result; - - public JsonResult() { - } - - /** - * 只返回状态码 - * - * @param code 状态码 - */ - public JsonResult(Integer code) { - this.code = code; - } - - /** - * 不返回数据的构造方法 - * - * @param code 状态码 - * @param msg 信息 - */ - public JsonResult(Integer code, String msg) { - this.code = code; - this.msg = msg; - } - - /** - * 返回数据的构造方法 - * - * @param code 状态码 - * @param msg 信息 - * @param result 数据 - */ - public JsonResult(Integer code, String msg, Object result) { - this.code = code; - this.msg = msg; - this.result = result; - } - - /** - * 返回状态码和数据 - * - * @param code 状态码 - * @param result 数据 - */ - public JsonResult(Integer code, Object result) { - this.code = code; - this.result = result; - } - - public JsonResult(Integer code, String msg, String devMsg, Object result) { - this.code = code; - this.msg = msg; - this.devMsg = devMsg; - this.result = result; - } - - /** - * Create an ok result with message and data. - * - * @param data result data - * @param message result message - * @return ok result with message and data - */ - @NonNull - public static JsonResult ok(@Nullable String message, @Nullable Object data) { - return new JsonResult(HttpStatus.OK.value(), message, data); - } - - /** - * Creates an ok result with message only. - * - * @param message result message - * @return ok result with message only - */ - @NonNull - public static JsonResult ok(@Nullable String message) { - return ok(message, null); - } - -// /** -// * Creates an fail result with message only. -// * -// * @param message message of result must not be blank -// * @return fail result with message only -// */ -// public static JsonResult fail(@NonNull String message) { -// Assert.hasText(message, "Message of result must not be blank"); -// -// return new JsonResult(ResultCodeEnum.FAIL.getCode(), message); -// } - -// /** -// * Creates an fail result. -// * -// * @param message message of result must not be blank -// * @return fail result -// */ -// public static JsonResult fail(@NonNull String message, @NonNull Object data) { -// Assert.notNull(data, "Data of result must not be null"); -// -// JsonResult failResult = fail(message); -// failResult.setResult(data); -// return failResult; -// } - -// /** -// * Creates an success result with message only. -// * -// * @param message message of result must not be blank -// * @return success result with message only -// */ -// public static JsonResult success(@NonNull String message) { -// Assert.hasText(message, "Message of result must not be blank"); -// -// return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), message); -// } - -// /** -// * Creates an success result. -// * -// * @param message message of result must not be blank -// * @return success result -// */ -// public static JsonResult success(@NonNull String message, @NonNull Object data) { -// Assert.notNull(data, "Data of result must not be null"); -// -// JsonResult successResult = success(message); -// successResult.setResult(data); -// return successResult; -// } -} diff --git a/src/main/java/cc/ryanc/halo/model/support/ListPage.java b/src/main/java/cc/ryanc/halo/model/support/ListPage.java deleted file mode 100644 index 82f115118..000000000 --- a/src/main/java/cc/ryanc/halo/model/support/ListPage.java +++ /dev/null @@ -1,128 +0,0 @@ -package cc.ryanc.halo.model.support; - -import java.util.Collections; -import java.util.List; - -/** - *
- *     List分页
- * 
- * - * @author : RYAN0UP - * @date : 2018/8/27 - */ -public class ListPage { - - /** - * 原集合 - */ - private List data; - - /** - * 上一页页码 - */ - private int prePage; - - /** - * 是否有上一页 - */ - private boolean hasPrevious; - - /** - * 当前页 - */ - private int nowPage; - - /** - * 下一页页码 - */ - private int nextPage; - - /** - * 是否有下一页 - */ - private boolean hasNext; - - /** - * 每页条数 - */ - private int pageSize; - - /** - * 总页数 - */ - private int totalPage; - - /** - * 总数据条数 - */ - private int totalCount; - - public ListPage(List data, int nowPage, int pageSize) { - this.data = data; - this.pageSize = pageSize; - this.nowPage = nowPage; - this.totalCount = data.size(); - this.totalPage = (totalCount + pageSize - 1) / pageSize; - this.prePage = nowPage - 1 > 1 ? nowPage - 1 : 1; - this.nextPage = nowPage >= totalPage ? totalPage : nowPage + 1; - this.hasPrevious = nowPage != prePage; - this.hasNext = nowPage != nextPage; - } - - /** - * 当前页数据 - * - * @return List - */ - public List getPageList() { - int fromIndex = (nowPage - 1) * pageSize; - if (fromIndex >= data.size()) { - return Collections.emptyList(); - } - if (fromIndex < 0) { - return Collections.emptyList(); - } - int toIndex = nowPage * pageSize; - if (toIndex >= data.size()) { - toIndex = data.size(); - } - return data.subList(fromIndex, toIndex); - } - - public List getData() { - return data; - } - - public int getPrePage() { - return prePage; - } - - public boolean isHasPrevious() { - return hasPrevious; - } - - public int getNowPage() { - return nowPage; - } - - public int getNextPage() { - return nextPage; - } - - public boolean isHasNext() { - return hasNext; - } - - public int getPageSize() { - return pageSize; - } - - public int getTotalPage() { - return totalPage; - } - - public int getTotalCount() { - return totalCount; - } -} diff --git a/src/main/java/cc/ryanc/halo/service/CommentService.java b/src/main/java/cc/ryanc/halo/service/CommentService.java index 6122da0cc..e7f92f2f3 100644 --- a/src/main/java/cc/ryanc/halo/service/CommentService.java +++ b/src/main/java/cc/ryanc/halo/service/CommentService.java @@ -85,4 +85,14 @@ public interface CommentService extends CrudService { */ @NonNull Page pageVosBy(@NonNull Integer postId, @NonNull Pageable pageable); + + /** + * Updates comment status. + * + * @param commentId comment id must not be null + * @param status comment status must not be null + * @return updated comment + */ + @NonNull + Comment updateStatus(Long commentId, CommentStatus status); } diff --git a/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java index cd78cfea4..887c3cc29 100644 --- a/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/CommentServiceImpl.java @@ -154,7 +154,7 @@ public class CommentServiceImpl extends AbstractCrudService imple List topComments = topVirtualComment.getChildren(); - List pageContent = null; + List pageContent; // Calc the shear index int startIndex = pageable.getPageNumber() * pageable.getPageSize(); @@ -176,6 +176,21 @@ public class CommentServiceImpl extends AbstractCrudService imple return new CommentPage<>(pageContent, pageable, topComments.size(), comments.size()); } + @Override + public Comment updateStatus(Long commentId, CommentStatus status) { + Assert.notNull(commentId, "Comment id must not be null"); + Assert.notNull(status, "Comment status must not be null"); + + // Get comment by id + Comment comment = getById(commentId); + + // Set comment status + comment.setStatus(status); + + // Update comment + return update(comment); + } + /** * Builds a comment comparator. * @@ -201,7 +216,14 @@ public class CommentServiceImpl extends AbstractCrudService imple }; } - private void concreteTree(CommentVO parentComment, List comments, Comparator commentComparator) { + /** + * Concretes comment tree. + * + * @param parentComment parent comment vo must not be null + * @param comments comment list must not null + * @param commentComparator comment vo comparator + */ + private void concreteTree(@NonNull CommentVO parentComment, Collection comments, @NonNull Comparator commentComparator) { Assert.notNull(parentComment, "Parent comment must not be null"); Assert.notNull(commentComparator, "Comment comparator must not be null"); diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/api/CommentController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/api/CommentController.java index 19885a51b..e066621b6 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/api/CommentController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/api/CommentController.java @@ -1,6 +1,7 @@ package cc.ryanc.halo.web.controller.admin.api; import cc.ryanc.halo.model.dto.CommentOutputDTO; +import cc.ryanc.halo.model.entity.Comment; import cc.ryanc.halo.model.enums.CommentStatus; import cc.ryanc.halo.model.params.CommentParam; import cc.ryanc.halo.model.vo.CommentListVO; @@ -68,4 +69,14 @@ public class CommentController { return new CommentOutputDTO().convertFrom(commentService.createBy(commentParam.convertTo(), request)); } + @PutMapping("{commentId:\\d+}/status/{status}") + @ApiOperation("Update comment status") + public CommentOutputDTO deleteBy(@PathVariable("commentId") Long commentId, + @PathVariable("status") CommentStatus status) { + // Update comment status + Comment updatedComment = commentService.updateStatus(commentId, status); + + return new CommentOutputDTO().convertFrom(updatedComment); + } + }