diff --git a/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java b/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java index 3a151fceb..40a6dc04f 100644 --- a/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java +++ b/src/main/java/run/halo/app/controller/admin/api/PostCommentController.java @@ -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 deletePermanentlyInBatch(@RequestBody List ids) { + return postCommentService.removeByIds(ids); + } + @GetMapping("{commentId:\\d+}") @ApiOperation("Gets a post comment by comment id") public PostCommentWithPostVO getBy(@PathVariable("commentId") Long commentId) { diff --git a/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java b/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java index 1e1896dc8..ea3310dfe 100644 --- a/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java +++ b/src/main/java/run/halo/app/controller/admin/api/SheetCommentController.java @@ -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 deletePermanentlyInBatch(@RequestBody List ids) { + return sheetCommentService.removeByIds(ids); + } + @GetMapping("{commentId:\\d+}") @ApiOperation("Gets a post comment by comment id") public SheetCommentWithSheetVO getBy(@PathVariable("commentId") Long commentId) { diff --git a/src/main/java/run/halo/app/service/base/BaseCommentService.java b/src/main/java/run/halo/app/service/base/BaseCommentService.java index 37172c378..ca3416dbe 100644 --- a/src/main/java/run/halo/app/service/base/BaseCommentService.java +++ b/src/main/java/run/halo/app/service/base/BaseCommentService.java @@ -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 extends CrudService { @@ -149,6 +150,15 @@ public interface BaseCommentService 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 removeByIds(@NonNull Collection ids); + /** * Converts to base comment dto. * diff --git a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java index 5852b7ee5..f97fdbfa7 100644 --- a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java @@ -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 extend return updatedComment; } + @Override + public List removeByIds(Collection ids) { + if (CollectionUtils.isEmpty(ids)) { + return Collections.emptyList(); + } + return ids.stream().map(this::removeById).collect(Collectors.toList()); + } + @Override public List convertTo(List comments) { if (CollectionUtils.isEmpty(comments)) {