mirror of https://github.com/halo-dev/halo
feat: support remove in batch api for comment.
parent
2a077fe04c
commit
f36f8aed8a
|
@ -98,11 +98,17 @@ public class PostCommentController {
|
|||
|
||||
@DeleteMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Deletes comment permanently and recursively")
|
||||
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
||||
public BaseCommentDTO deletePermanently(@PathVariable("commentId") Long commentId) {
|
||||
PostComment deletedPostComment = postCommentService.removeById(commentId);
|
||||
return postCommentService.convertTo(deletedPostComment);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@ApiOperation("Delete post comments permanently in batch by id array")
|
||||
public List<PostComment> deletePermanentlyInBatch(@RequestBody List<Long> ids) {
|
||||
return postCommentService.removeByIds(ids);
|
||||
}
|
||||
|
||||
@GetMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Gets a post comment by comment id")
|
||||
public PostCommentWithPostVO getBy(@PathVariable("commentId") Long commentId) {
|
||||
|
|
|
@ -93,11 +93,17 @@ public class SheetCommentController {
|
|||
|
||||
@DeleteMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Deletes comment permanently and recursively")
|
||||
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
||||
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")
|
||||
public List<SheetComment> deletePermanentlyInBatch(@RequestBody List<Long> ids) {
|
||||
return sheetCommentService.removeByIds(ids);
|
||||
}
|
||||
|
||||
@GetMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Gets a post comment by comment id")
|
||||
public SheetCommentWithSheetVO getBy(@PathVariable("commentId") Long commentId) {
|
||||
|
|
|
@ -23,7 +23,8 @@ import java.util.Map;
|
|||
* Base comment service interface.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
* @author ryanwang
|
||||
* @date 2019-04-24
|
||||
*/
|
||||
public interface BaseCommentService<COMMENT extends BaseComment> extends CrudService<COMMENT, Long> {
|
||||
|
||||
|
@ -149,6 +150,15 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
|
|||
@NonNull
|
||||
COMMENT updateStatus(@NonNull Long commentId, @NonNull CommentStatus status);
|
||||
|
||||
/**
|
||||
* Removes comments in batch.
|
||||
*
|
||||
* @param ids ids must not be null.
|
||||
* @return a list of deleted comment.
|
||||
*/
|
||||
@NonNull
|
||||
List<COMMENT> removeByIds(@NonNull Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Converts to base comment dto.
|
||||
*
|
||||
|
|
|
@ -51,6 +51,7 @@ import java.util.stream.Collectors;
|
|||
* Base comment service implementation.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 2019-04-24
|
||||
*/
|
||||
@Slf4j
|
||||
|
@ -328,6 +329,14 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
|||
return updatedComment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<COMMENT> removeByIds(Collection<Long> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return ids.stream().map(this::removeById).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseCommentDTO> convertTo(List<COMMENT> comments) {
|
||||
if (CollectionUtils.isEmpty(comments)) {
|
||||
|
|
Loading…
Reference in New Issue