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 40a6dc04f..5f924668c 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 @@ -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 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 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 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 updateStatusInBatch(@RequestBody BaseCommentUpdateStatusParam param) { + List 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); 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 ea3310dfe..a5305d521 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 @@ -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 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 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 updateStatusInBatch(@RequestBody BaseCommentUpdateStatusParam param) { + List 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 deletePermanentlyInBatch(@RequestBody List 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); diff --git a/src/main/java/run/halo/app/model/BaseCommentUpdateStatusParam.java b/src/main/java/run/halo/app/model/BaseCommentUpdateStatusParam.java new file mode 100644 index 000000000..b0c6ebca0 --- /dev/null +++ b/src/main/java/run/halo/app/model/BaseCommentUpdateStatusParam.java @@ -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 ids; + + private CommentStatus status; +} 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 ca3416dbe..0820c6200 100644 --- a/src/main/java/run/halo/app/service/base/BaseCommentService.java +++ b/src/main/java/run/halo/app/service/base/BaseCommentService.java @@ -150,6 +150,16 @@ public interface BaseCommentService 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 updateStatusByIds(@NonNull List ids, @NonNull CommentStatus status); + /** * Removes comments in batch. * 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 f97fdbfa7..a9038e693 100644 --- a/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java @@ -329,6 +329,16 @@ public abstract class BaseCommentServiceImpl extend return updatedComment; } + @Override + public List updateStatusByIds(List 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 removeByIds(Collection ids) { if (CollectionUtils.isEmpty(ids)) {