mirror of https://github.com/halo-dev/halo
Complete comment status update api
parent
2e94ff0524
commit
6b0dc1ce5e
|
@ -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<String, String> OWO_MAP = Collections.emptyMap();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Json格式
|
||||
* </pre>
|
||||
*
|
||||
* @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;
|
||||
// }
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
package cc.ryanc.halo.model.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* List分页
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/8/27
|
||||
*/
|
||||
public class ListPage<T> {
|
||||
|
||||
/**
|
||||
* 原集合
|
||||
*/
|
||||
private List<T> 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<T> 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<T> 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<T> 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;
|
||||
}
|
||||
}
|
|
@ -85,4 +85,14 @@ public interface CommentService extends CrudService<Comment, Long> {
|
|||
*/
|
||||
@NonNull
|
||||
Page<CommentVO> 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);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> imple
|
|||
|
||||
List<CommentVO> topComments = topVirtualComment.getChildren();
|
||||
|
||||
List<CommentVO> pageContent = null;
|
||||
List<CommentVO> pageContent;
|
||||
|
||||
// Calc the shear index
|
||||
int startIndex = pageable.getPageNumber() * pageable.getPageSize();
|
||||
|
@ -176,6 +176,21 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> 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<Comment, Long> imple
|
|||
};
|
||||
}
|
||||
|
||||
private void concreteTree(CommentVO parentComment, List<Comment> comments, Comparator<CommentVO> 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<Comment> comments, @NonNull Comparator<CommentVO> commentComparator) {
|
||||
Assert.notNull(parentComment, "Parent comment must not be null");
|
||||
Assert.notNull(commentComparator, "Comment comparator must not be null");
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue