Complete comment status update api

pull/137/head
johnniang 2019-03-25 19:26:03 +08:00
parent 2e94ff0524
commit 6b0dc1ce5e
6 changed files with 46 additions and 307 deletions

View File

@ -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();

View File

@ -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;
// }
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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");

View File

@ -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);
}
}