Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add comment assembler for theme render #1729

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.JournalService;
import run.halo.app.service.OptionService;
import run.halo.app.service.assembler.comment.JournalCommentAssembler;
import run.halo.app.service.assembler.comment.JournalCommentRenderAssembler;

/**
* Content journal controller.
Expand All @@ -49,18 +49,18 @@ public class JournalController {

private final JournalService journalService;

private final JournalCommentAssembler journalCommentAssembler;
private final JournalCommentRenderAssembler journalCommentRenderAssembler;

private final JournalCommentService journalCommentService;

private final OptionService optionService;

public JournalController(JournalService journalService,
JournalCommentAssembler journalCommentAssembler,
JournalCommentRenderAssembler journalCommentRenderAssembler,
JournalCommentService journalCommentService,
OptionService optionService) {
this.journalService = journalService;
this.journalCommentAssembler = journalCommentAssembler;
this.journalCommentRenderAssembler = journalCommentRenderAssembler;
this.journalCommentService = journalCommentService;
this.optionService = optionService;
}
Expand All @@ -85,8 +85,11 @@ public Page<CommentWithHasChildrenVO> listTopComments(
@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageTopCommentsBy(journalId, CommentStatus.PUBLISHED,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<CommentWithHasChildrenVO> comments =
journalCommentService.pageTopCommentsBy(journalId, CommentStatus.PUBLISHED,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.forEach(journalCommentRenderAssembler::clearSensitiveField);
return comments;
}

@GetMapping("{journalId:\\d+}/comments/{commentParentId:\\d+}/children")
Expand All @@ -97,25 +100,30 @@ public List<BaseCommentDTO> listChildrenBy(@PathVariable("journalId") Integer jo
List<JournalComment> postComments = journalCommentService
.listChildrenBy(journalId, commentParentId, CommentStatus.PUBLISHED, sort);
// Convert to base comment dto
return journalCommentAssembler.convertTo(postComments);
return journalCommentRenderAssembler.convertTo(postComments);
}

@GetMapping("{journalId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService
Page<BaseCommentVO> comments = journalCommentService
.pageVosBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.getContent().forEach(journalCommentRenderAssembler::clearSensitiveField);
return comments;
}

@GetMapping("{journalId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageWithParentVoBy(journalId,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentWithParentVO> comments =
journalCommentService.pageWithParentVoBy(journalId,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.getContent().forEach(journalCommentRenderAssembler::clearSensitiveField);
return comments;
}

@PostMapping("comments")
Expand All @@ -126,7 +134,7 @@ public BaseCommentDTO comment(@RequestBody JournalCommentParam journalCommentPar
// Escape content
journalCommentParam.setContent(HtmlUtils
.htmlEscape(journalCommentParam.getContent(), StandardCharsets.UTF_8.displayName()));
return journalCommentAssembler.convertTo(
return journalCommentRenderAssembler.convertTo(
journalCommentService.createBy(journalCommentParam));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import run.halo.app.service.PostCommentService;
import run.halo.app.service.PostService;
import run.halo.app.service.assembler.PostRenderAssembler;
import run.halo.app.service.assembler.comment.PostCommentAssembler;
import run.halo.app.service.assembler.comment.PostCommentRenderAssembler;

/**
* Content post controller.
Expand All @@ -58,7 +58,7 @@ public class PostController {

private final PostService postService;

private final PostCommentAssembler postCommentAssembler;
private final PostCommentRenderAssembler postCommentRenderAssembler;

private final PostCommentService postCommentService;

Expand All @@ -69,12 +69,12 @@ public class PostController {
private final PostAuthentication postAuthentication;

public PostController(PostService postService,
PostCommentAssembler postCommentAssembler,
PostCommentRenderAssembler postCommentRenderAssembler,
PostCommentService postCommentService,
OptionService optionService, PostRenderAssembler postRenderAssembler,
PostAuthentication postAuthentication) {
this.postService = postService;
this.postCommentAssembler = postCommentAssembler;
this.postCommentRenderAssembler = postCommentRenderAssembler;
this.postCommentService = postCommentService;
this.optionService = optionService;
this.postRenderAssembler = postRenderAssembler;
Expand Down Expand Up @@ -194,8 +194,11 @@ public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("postId") In
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
checkAuthenticate(postId);
return postCommentService.pageTopCommentsBy(postId, CommentStatus.PUBLISHED,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<CommentWithHasChildrenVO> comments =
postCommentService.pageTopCommentsBy(postId, CommentStatus.PUBLISHED,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.getContent().forEach(postCommentRenderAssembler::clearSensitiveField);
return comments;
}

@GetMapping("{postId:\\d+}/comments/{commentParentId:\\d+}/children")
Expand All @@ -208,7 +211,7 @@ public List<BaseCommentDTO> listChildrenBy(@PathVariable("postId") Integer postI
.listChildrenBy(postId, commentParentId, CommentStatus.PUBLISHED, sort);
// Convert to base comment dto

return postCommentAssembler.convertTo(postComments);
return postCommentRenderAssembler.convertTo(postComments);
}

@GetMapping("{postId:\\d+}/comments/tree_view")
Expand All @@ -217,8 +220,10 @@ public Page<BaseCommentVO> listCommentsTree(@PathVariable("postId") Integer post
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
checkAuthenticate(postId);
return postCommentService
Page<BaseCommentVO> comments = postCommentService
.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.getContent().forEach(postCommentRenderAssembler::clearSensitiveField);
return comments;
}

@GetMapping("{postId:\\d+}/comments/list_view")
Expand All @@ -227,8 +232,11 @@ public Page<BaseCommentWithParentVO> listComments(@PathVariable("postId") Intege
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
checkAuthenticate(postId);
return postCommentService.pageWithParentVoBy(postId,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentWithParentVO> comments =
postCommentService.pageWithParentVoBy(postId,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.getContent().forEach(postCommentRenderAssembler::clearSensitiveField);
return comments;
}

@PostMapping("comments")
Expand All @@ -241,7 +249,7 @@ public BaseCommentDTO comment(@RequestBody PostCommentParam postCommentParam) {
// Escape content
postCommentParam.setContent(HtmlUtils
.htmlEscape(postCommentParam.getContent(), StandardCharsets.UTF_8.displayName()));
return postCommentAssembler.convertTo(postCommentService.createBy(postCommentParam));
return postCommentRenderAssembler.convertTo(postCommentService.createBy(postCommentParam));
}

@PostMapping("{postId:\\d+}/likes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import run.halo.app.service.SheetCommentService;
import run.halo.app.service.SheetService;
import run.halo.app.service.assembler.SheetRenderAssembler;
import run.halo.app.service.assembler.comment.SheetCommentAssembler;
import run.halo.app.service.assembler.comment.SheetCommentRenderAssembler;

/**
* Content sheet controller.
Expand All @@ -48,7 +48,7 @@
@RequestMapping("/api/content/sheets")
public class SheetController {

private final SheetCommentAssembler sheetCommentAssembler;
private final SheetCommentRenderAssembler sheetCommentRenderAssembler;

private final SheetService sheetService;

Expand All @@ -59,12 +59,12 @@ public class SheetController {
private final OptionService optionService;

public SheetController(
SheetCommentAssembler sheetCommentAssembler,
SheetCommentRenderAssembler sheetCommentRenderAssembler,
SheetService sheetService,
SheetRenderAssembler sheetRenderAssembler,
SheetCommentService sheetCommentService,
OptionService optionService) {
this.sheetCommentAssembler = sheetCommentAssembler;
this.sheetCommentRenderAssembler = sheetCommentRenderAssembler;
this.sheetService = sheetService;
this.sheetRenderAssembler = sheetRenderAssembler;
this.sheetCommentService = sheetCommentService;
Expand Down Expand Up @@ -134,8 +134,11 @@ public SheetDetailVO getBy(@RequestParam("slug") String slug,
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return sheetCommentService.pageTopCommentsBy(sheetId, CommentStatus.PUBLISHED,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<CommentWithHasChildrenVO> comments =
sheetCommentService.pageTopCommentsBy(sheetId, CommentStatus.PUBLISHED,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.forEach(sheetCommentRenderAssembler::clearSensitiveField);
return comments;
}

@GetMapping("{sheetId:\\d+}/comments/{commentParentId:\\d+}/children")
Expand All @@ -146,7 +149,7 @@ public List<BaseCommentDTO> listChildrenBy(@PathVariable("sheetId") Integer shee
List<SheetComment> sheetComments = sheetCommentService
.listChildrenBy(sheetId, commentParentId, CommentStatus.PUBLISHED, sort);
// Convert to base comment dto
return sheetCommentAssembler.convertTo(sheetComments);
return sheetCommentRenderAssembler.convertTo(sheetComments);
}


Expand All @@ -155,17 +158,22 @@ public List<BaseCommentDTO> listChildrenBy(@PathVariable("sheetId") Integer shee
public Page<BaseCommentVO> listCommentsTree(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return sheetCommentService
Page<BaseCommentVO> comments = sheetCommentService
.pageVosBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.getContent().forEach(sheetCommentRenderAssembler::clearSensitiveField);
return comments;
}

@GetMapping("{sheetId:\\d+}/comments/list_view")
@ApiOperation("Lists 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) {
return sheetCommentService.pageWithParentVoBy(sheetId,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentWithParentVO> comments =
sheetCommentService.pageWithParentVoBy(sheetId,
PageRequest.of(page, optionService.getCommentPageSize(), sort));
comments.getContent().forEach(sheetCommentRenderAssembler::clearSensitiveField);
return comments;
}

@PostMapping("comments")
Expand All @@ -176,6 +184,7 @@ public BaseCommentDTO comment(@RequestBody SheetCommentParam sheetCommentParam)
// Escape content
sheetCommentParam.setContent(HtmlUtils
.htmlEscape(sheetCommentParam.getContent(), StandardCharsets.UTF_8.displayName()));
return sheetCommentAssembler.convertTo(sheetCommentService.createBy(sheetCommentParam));
return sheetCommentRenderAssembler.convertTo(
sheetCommentService.createBy(sheetCommentParam));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.support.HaloConst;
import run.halo.app.service.PostCommentService;
import run.halo.app.service.assembler.comment.PostCommentAssembler;
import run.halo.app.service.assembler.comment.PostCommentRenderAssembler;

/**
* Freemarker custom tag of comment.
*
* @author ryanwang
* @author guqing
* @date 2019-03-22
*/
@Component
public class CommentTagDirective implements TemplateDirectiveModel {

private final PostCommentService postCommentService;

private final PostCommentAssembler postCommentAssembler;
private final PostCommentRenderAssembler postCommentRenderAssembler;

public CommentTagDirective(Configuration configuration, PostCommentService postCommentService,
PostCommentAssembler postCommentAssembler) {
PostCommentRenderAssembler postCommentRenderAssembler) {
this.postCommentService = postCommentService;
this.postCommentAssembler = postCommentAssembler;
this.postCommentRenderAssembler = postCommentRenderAssembler;
configuration.setSharedVariable("commentTag", this);
}

Expand All @@ -52,7 +53,7 @@ public void execute(Environment env, Map params, TemplateModel[] loopVars,
postCommentService.pageLatest(top, CommentStatus.PUBLISHED);
env.setVariable("comments",
builder.build()
.wrap(postCommentAssembler.convertToWithPostVo(postComments)));
.wrap(postCommentRenderAssembler.convertToWithPostVo(postComments)));
break;
case "count":
env.setVariable("count", builder.build().wrap(postCommentService.count()));
Expand Down
Loading