mirror of https://github.com/halo-dev/halo
feat: add update status in batch api for comment.
parent
68512988d0
commit
30eacdb342
|
@ -8,6 +8,7 @@ import org.springframework.data.domain.Sort;
|
|||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import run.halo.app.model.BaseCommentUpdateStatusParam;
|
||||
import run.halo.app.model.dto.BaseCommentDTO;
|
||||
import run.halo.app.model.entity.PostComment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
|
@ -54,7 +55,7 @@ public class PostCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("latest")
|
||||
@ApiOperation("Pages latest comments")
|
||||
@ApiOperation("Pages post latest comments")
|
||||
public List<PostCommentWithPostVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
// Get latest comment
|
||||
|
@ -65,7 +66,7 @@ public class PostCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("{postId:\\d+}/tree_view")
|
||||
@ApiOperation("Lists comments with tree view")
|
||||
@ApiOperation("Lists post comments with tree view")
|
||||
public Page<BaseCommentVO> listCommentTree(@PathVariable("postId") Integer postId,
|
||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||
|
@ -73,7 +74,7 @@ public class PostCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("{postId:\\d+}/list_view")
|
||||
@ApiOperation("Lists comment with list view")
|
||||
@ApiOperation("Lists post comment with list view")
|
||||
public Page<BaseCommentWithParentVO> listComments(@PathVariable("postId") Integer postId,
|
||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||
|
@ -81,14 +82,14 @@ public class PostCommentController {
|
|||
}
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("Creates a comment (new or reply)")
|
||||
@ApiOperation("Creates a post comment (new or reply)")
|
||||
public BaseCommentDTO createBy(@RequestBody PostCommentParam postCommentParam) {
|
||||
PostComment createdPostComment = postCommentService.createBy(postCommentParam);
|
||||
return postCommentService.convertTo(createdPostComment);
|
||||
}
|
||||
|
||||
@PutMapping("{commentId:\\d+}/status/{status}")
|
||||
@ApiOperation("Updates comment status")
|
||||
@ApiOperation("Updates post comment status")
|
||||
public BaseCommentDTO updateStatusBy(@PathVariable("commentId") Long commentId,
|
||||
@PathVariable("status") CommentStatus status) {
|
||||
// Update comment status
|
||||
|
@ -96,8 +97,15 @@ public class PostCommentController {
|
|||
return postCommentService.convertTo(updatedPostComment);
|
||||
}
|
||||
|
||||
@PutMapping("status")
|
||||
@ApiOperation("Updates post comment status in batch")
|
||||
public List<BaseCommentDTO> updateStatusInBatch(@RequestBody BaseCommentUpdateStatusParam param) {
|
||||
List<PostComment> comments = postCommentService.updateStatusByIds(param.getIds(), param.getStatus());
|
||||
return postCommentService.convertTo(comments);
|
||||
}
|
||||
|
||||
@DeleteMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Deletes comment permanently and recursively")
|
||||
@ApiOperation("Deletes post comment permanently and recursively")
|
||||
public BaseCommentDTO deletePermanently(@PathVariable("commentId") Long commentId) {
|
||||
PostComment deletedPostComment = postCommentService.removeById(commentId);
|
||||
return postCommentService.convertTo(deletedPostComment);
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.data.domain.Sort;
|
|||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import run.halo.app.model.BaseCommentUpdateStatusParam;
|
||||
import run.halo.app.model.dto.BaseCommentDTO;
|
||||
import run.halo.app.model.entity.SheetComment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
|
@ -60,7 +61,7 @@ public class SheetCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("{sheetId:\\d+}/tree_view")
|
||||
@ApiOperation("Lists comments with tree view")
|
||||
@ApiOperation("Lists sheet comments with tree view")
|
||||
public Page<BaseCommentVO> listCommentTree(@PathVariable("sheetId") Integer sheetId,
|
||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||
|
@ -68,7 +69,7 @@ public class SheetCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("{sheetId:\\d+}/list_view")
|
||||
@ApiOperation("Lists comment with list view")
|
||||
@ApiOperation("Lists sheet comment with list view")
|
||||
public Page<BaseCommentWithParentVO> listComments(@PathVariable("sheetId") Integer sheetId,
|
||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||
|
@ -76,14 +77,14 @@ public class SheetCommentController {
|
|||
}
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("Creates a comment (new or reply)")
|
||||
@ApiOperation("Creates a sheet comment (new or reply)")
|
||||
public BaseCommentDTO createBy(@RequestBody SheetCommentParam commentParam) {
|
||||
SheetComment createdComment = sheetCommentService.createBy(commentParam);
|
||||
return sheetCommentService.convertTo(createdComment);
|
||||
}
|
||||
|
||||
@PutMapping("{commentId:\\d+}/status/{status}")
|
||||
@ApiOperation("Updates comment status")
|
||||
@ApiOperation("Updates sheet comment status")
|
||||
public BaseCommentDTO updateStatusBy(@PathVariable("commentId") Long commentId,
|
||||
@PathVariable("status") CommentStatus status) {
|
||||
// Update comment status
|
||||
|
@ -91,21 +92,29 @@ public class SheetCommentController {
|
|||
return sheetCommentService.convertTo(updatedSheetComment);
|
||||
}
|
||||
|
||||
@PutMapping("status")
|
||||
@ApiOperation("Updates sheet comment status in batch")
|
||||
public List<BaseCommentDTO> updateStatusInBatch(@RequestBody BaseCommentUpdateStatusParam param) {
|
||||
List<SheetComment> comments = sheetCommentService.updateStatusByIds(param.getIds(), param.getStatus());
|
||||
return sheetCommentService.convertTo(comments);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Deletes comment permanently and recursively")
|
||||
@ApiOperation("Deletes sheet comment permanently and recursively")
|
||||
public BaseCommentDTO deletePermanently(@PathVariable("commentId") Long commentId) {
|
||||
SheetComment deletedSheetComment = sheetCommentService.removeById(commentId);
|
||||
return sheetCommentService.convertTo(deletedSheetComment);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@ApiOperation("Delete post comments permanently in batch by id array")
|
||||
@ApiOperation("Delete sheet comments permanently in batch by id array")
|
||||
public List<SheetComment> deletePermanentlyInBatch(@RequestBody List<Long> ids) {
|
||||
return sheetCommentService.removeByIds(ids);
|
||||
}
|
||||
|
||||
@GetMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Gets a post comment by comment id")
|
||||
@ApiOperation("Gets a sheet comment by comment id")
|
||||
public SheetCommentWithSheetVO getBy(@PathVariable("commentId") Long commentId) {
|
||||
SheetComment comment = sheetCommentService.getById(commentId);
|
||||
return sheetCommentService.convertToWithSheetVo(comment);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package run.halo.app.model;
|
||||
|
||||
import lombok.Data;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Base comment update status param.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @date 2019-12-12
|
||||
*/
|
||||
@Data
|
||||
public class BaseCommentUpdateStatusParam {
|
||||
|
||||
private List<Long> ids;
|
||||
|
||||
private CommentStatus status;
|
||||
}
|
|
@ -150,6 +150,16 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
|
|||
@NonNull
|
||||
COMMENT updateStatus(@NonNull Long commentId, @NonNull CommentStatus status);
|
||||
|
||||
/**
|
||||
* Updates comment status by ids.
|
||||
*
|
||||
* @param ids comment ids must not be null
|
||||
* @param status comment status must not be null
|
||||
* @return updated comments
|
||||
*/
|
||||
@NonNull
|
||||
List<COMMENT> updateStatusByIds(@NonNull List<Long> ids, @NonNull CommentStatus status);
|
||||
|
||||
/**
|
||||
* Removes comments in batch.
|
||||
*
|
||||
|
|
|
@ -329,6 +329,16 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
|||
return updatedComment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<COMMENT> updateStatusByIds(List<Long> ids, CommentStatus status) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return ids.stream().map(id -> {
|
||||
return updateStatus(id, status);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<COMMENT> removeByIds(Collection<Long> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
|
|
Loading…
Reference in New Issue