pref: remove useless code.

pull/461/head^2
ruibaby 2020-01-01 22:42:50 +08:00
parent e13c014a6b
commit d3ef9c4a7a
9 changed files with 37 additions and 27 deletions

View File

@ -21,7 +21,6 @@ import run.halo.app.model.entity.PostMeta;
import run.halo.app.model.entity.Tag; import run.halo.app.model.entity.Tag;
import run.halo.app.model.enums.PostStatus; import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.support.HaloConst; import run.halo.app.model.support.HaloConst;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.PostListVO; import run.halo.app.model.vo.PostListVO;
import run.halo.app.service.*; import run.halo.app.service.*;
import run.halo.app.utils.MarkdownUtils; import run.halo.app.utils.MarkdownUtils;
@ -114,17 +113,14 @@ public class ContentArchiveController {
/** /**
* Render post page. * Render post page.
* *
* @param url post slug url. * @param url post slug url.
* @param preview preview * @param token view token.
* @param token preview token * @param model model
* @param model model
* @return template path: themes/{theme}/post.ftl * @return template path: themes/{theme}/post.ftl
*/ */
@GetMapping("{url}") @GetMapping("{url}")
public String post(@PathVariable("url") String url, public String post(@PathVariable("url") String url,
@RequestParam(value = "token", required = false) String token, @RequestParam(value = "token", required = false) String token,
@RequestParam(value = "cp", defaultValue = "1") Integer cp,
@SortDefault(sort = "createTime", direction = DESC) Sort sort,
Model model) { Model model) {
Post post = postService.getByUrl(url); Post post = postService.getByUrl(url);
@ -151,14 +147,12 @@ public class ContentArchiveController {
List<Tag> tags = postTagService.listTagsBy(post.getId()); List<Tag> tags = postTagService.listTagsBy(post.getId());
List<PostMeta> metas = postMetaService.listBy(post.getId()); List<PostMeta> metas = postMetaService.listBy(post.getId());
Page<BaseCommentVO> comments = postCommentService.pageVosBy(post.getId(), PageRequest.of(cp, optionService.getCommentPageSize(), sort));
model.addAttribute("is_post", true); model.addAttribute("is_post", true);
model.addAttribute("post", postService.convertToDetailVo(post)); model.addAttribute("post", postService.convertToDetailVo(post));
model.addAttribute("categories", categories); model.addAttribute("categories", categories);
model.addAttribute("tags", tags); model.addAttribute("tags", tags);
model.addAttribute("metas", postMetaService.convertToMap(metas)); model.addAttribute("metas", postMetaService.convertToMap(metas));
model.addAttribute("comments", comments); model.addAttribute("comments", Page.empty());
if (themeService.templateExists(ThemeService.CUSTOM_POST_PREFIX + post.getTemplate() + HaloConst.SUFFIX_FTL)) { if (themeService.templateExists(ThemeService.CUSTOM_POST_PREFIX + post.getTemplate() + HaloConst.SUFFIX_FTL)) {
return themeService.render(ThemeService.CUSTOM_POST_PREFIX + post.getTemplate()); return themeService.render(ThemeService.CUSTOM_POST_PREFIX + post.getTemplate());

View File

@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import run.halo.app.model.entity.Journal; import run.halo.app.model.entity.Journal;
import run.halo.app.model.enums.JournalType; import run.halo.app.model.enums.JournalType;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.JournalService; import run.halo.app.service.JournalService;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import run.halo.app.service.ThemeService; import run.halo.app.service.ThemeService;
@ -34,18 +33,14 @@ public class ContentJournalController {
private final JournalService journalService; private final JournalService journalService;
private final JournalCommentService journalCommentService;
private final OptionService optionService; private final OptionService optionService;
private final ThemeService themeService; private final ThemeService themeService;
public ContentJournalController(JournalService journalService, public ContentJournalController(JournalService journalService,
JournalCommentService journalCommentService,
OptionService optionService, OptionService optionService,
ThemeService themeService) { ThemeService themeService) {
this.journalService = journalService; this.journalService = journalService;
this.journalCommentService = journalCommentService;
this.optionService = optionService; this.optionService = optionService;
this.themeService = themeService; this.themeService = themeService;
} }
@ -84,7 +79,7 @@ public class ContentJournalController {
int[] rainbow = PageUtil.rainbow(page, journals.getTotalPages(), 3); int[] rainbow = PageUtil.rainbow(page, journals.getTotalPages(), 3);
model.addAttribute("is_journal", true); model.addAttribute("is_journal", true);
model.addAttribute("journals", journals); model.addAttribute("journals", journalService.convertToCmtCountDto(journals));
model.addAttribute("rainbow", rainbow); model.addAttribute("rainbow", rainbow);
return themeService.render("journals"); return themeService.render("journals");
} }

View File

@ -5,7 +5,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -17,7 +16,6 @@ import run.halo.app.model.dto.PhotoDTO;
import run.halo.app.model.entity.Sheet; import run.halo.app.model.entity.Sheet;
import run.halo.app.model.enums.PostStatus; import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.support.HaloConst; import run.halo.app.model.support.HaloConst;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.SheetDetailVO; import run.halo.app.model.vo.SheetDetailVO;
import run.halo.app.service.*; import run.halo.app.service.*;
import run.halo.app.utils.MarkdownUtils; import run.halo.app.utils.MarkdownUtils;
@ -102,17 +100,14 @@ public class ContentSheetController {
/** /**
* Render custom sheet * Render custom sheet
* *
* @param url sheet url * @param url sheet url
* @param preview preview * @param token view token
* @param token token * @param model model
* @param model model
* @return template path: themes/{theme}/sheet.ftl * @return template path: themes/{theme}/sheet.ftl
*/ */
@GetMapping(value = "/s/{url}") @GetMapping(value = "/s/{url}")
public String sheet(@PathVariable(value = "url") String url, public String sheet(@PathVariable(value = "url") String url,
@RequestParam(value = "token", required = false) String token, @RequestParam(value = "token", required = false) String token,
@RequestParam(value = "cp", defaultValue = "1") Integer cp,
@SortDefault(sort = "createTime", direction = DESC) Sort sort,
Model model) { Model model) {
Sheet sheet = sheetService.getByUrl(url); Sheet sheet = sheetService.getByUrl(url);
@ -131,15 +126,13 @@ public class ContentSheetController {
} }
} }
Page<BaseCommentVO> comments = sheetCommentService.pageVosBy(sheet.getId(), PageRequest.of(cp, optionService.getCommentPageSize(), sort));
SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheet); SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheet);
// sheet and post all can use // sheet and post all can use
model.addAttribute("sheet", sheetDetailVO); model.addAttribute("sheet", sheetDetailVO);
model.addAttribute("post", sheetDetailVO); model.addAttribute("post", sheetDetailVO);
model.addAttribute("is_sheet", true); model.addAttribute("is_sheet", true);
model.addAttribute("comments", comments); model.addAttribute("comments", Page.empty());
if (themeService.templateExists(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate() + HaloConst.SUFFIX_FTL)) { if (themeService.templateExists(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate() + HaloConst.SUFFIX_FTL)) {
return themeService.render(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate()); return themeService.render(ThemeService.CUSTOM_SHEET_PREFIX + sheet.getTemplate());

View File

@ -17,4 +17,6 @@ public class BasePostDetailDTO extends BasePostSimpleDTO {
private String originalContent; private String originalContent;
private String formatContent; private String formatContent;
private Long commentCount;
} }

View File

@ -67,6 +67,14 @@ public interface BaseCommentRepository<COMMENT extends BaseComment> extends Base
@NonNull @NonNull
List<CommentCountProjection> countByPostIds(@NonNull Collection<Integer> postIds); List<CommentCountProjection> countByPostIds(@NonNull Collection<Integer> postIds);
/**
* Count comments by post id.
*
* @param postId post id must not be null.
* @return comments count
*/
long countByPostId(@NonNull Integer postId);
/** /**
* Counts by comment status. * Counts by comment status.
* *

View File

@ -134,6 +134,14 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
@NonNull @NonNull
Map<Integer, Long> countByPostIds(@Nullable Collection<Integer> postIds); Map<Integer, Long> countByPostIds(@Nullable Collection<Integer> postIds);
/**
* Count comments by post id.
*
* @param postId post id must not be null.
* @return comments count
*/
long countByPostId(@NonNull Integer postId);
/** /**
* Counts by comment status. * Counts by comment status.
* *

View File

@ -233,6 +233,12 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
return ServiceUtils.convertToMap(commentCountProjections, CommentCountProjection::getPostId, CommentCountProjection::getCount); return ServiceUtils.convertToMap(commentCountProjections, CommentCountProjection::getPostId, CommentCountProjection::getCount);
} }
@Override
public long countByPostId(Integer postId) {
Assert.notNull(postId, "Post id must not be null");
return baseCommentRepository.countByPostId(postId);
}
@Override @Override
public long countByStatus(CommentStatus status) { public long countByStatus(CommentStatus status) {
return baseCommentRepository.countByStatus(status); return baseCommentRepository.countByStatus(status);

View File

@ -549,6 +549,8 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
postDetailVO.setPostMetaIds(postMetaIds); postDetailVO.setPostMetaIds(postMetaIds);
postDetailVO.setPostMetas(postMetaService.convertTo(postMetaList)); postDetailVO.setPostMetas(postMetaService.convertTo(postMetaList));
postDetailVO.setCommentCount(postCommentService.countByPostId(post.getId()));
return postDetailVO; return postDetailVO;
} }

View File

@ -289,6 +289,8 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
if (StringUtils.isBlank(sheetDetailVO.getSummary())) { if (StringUtils.isBlank(sheetDetailVO.getSummary())) {
sheetDetailVO.setSummary(generateSummary(sheet.getFormatContent())); sheetDetailVO.setSummary(generateSummary(sheet.getFormatContent()));
} }
sheetDetailVO.setCommentCount(sheetCommentService.countByPostId(sheet.getId()));
return sheetDetailVO; return sheetDetailVO;
} }