Skip to content

Commit

Permalink
Merge pull request #52 from one-dream-us/dev
Browse files Browse the repository at this point in the history
fix: 최신 콘텐츠에 태그 누락 오류 수정
  • Loading branch information
JuJaeng2 authored Jan 16, 2025
2 parents 1faac6b + bcb117a commit cdc4c4a
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,28 @@ public CursorResult<NewsListResponse> getNewList(Integer cursor, Integer size) {
}

private NewsListResponse convertToResponse(News news) {
List<String> tags = getTags(news);

Integer viewCount = newsViewRepository.findTotalViewCountByNews(news)
.orElse(0);

String formattedViewCount = NumberFormatter.format(viewCount);

return NewsListResponse.from(news, formattedViewCount, tags);
}

private List<String> getTags(News news) {
List<String> tags = new ArrayList<>();

List<Sentence> sentences = sentenceRepository.findByNews(news);
List<Dictionary> dictionaries =
dictionarySentenceRepository.findDictionaryBySentenceIn(sentences);
dictionarySentenceRepository.findDictionaryBySentenceIn(sentences);
for (Dictionary dictionary : dictionaries) {
tags.add(dictionary.getTerm()
);
}

Integer viewCount = newsViewRepository.findTotalViewCountByNews(news)
.orElse(0);

String formattedViewCount = NumberFormatter.format(viewCount);

return NewsListResponse.from(news, formattedViewCount, tags);
return tags;
}

/**
Expand Down Expand Up @@ -99,14 +105,7 @@ public NewsDetailResponse getNewsDetail(int newsId) {
}

// 조회수 증가
LocalDateTime now = LocalDateTime.now();
LocalDateTime startOfDay = now.toLocalDate().atStartOfDay();
LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59, 999999999);
NewsView newsView =
newsViewRepository.findByNewsAndViewDateBetween(news, startOfDay, endOfDay)
.orElse(NewsView.from(news));
newsView.setViewCount(newsView.getViewCount() + 1);
newsViewRepository.save(newsView);
increaseView(news);

return NewsDetailResponse.from(news, fullSentenceBuilder.toString(), descriptionDtos);
}
Expand All @@ -123,10 +122,20 @@ public NewsListResponse getLatestNews() {

int totalViewCnt = newsViewRepository.findTotalViewCountByNews(latestNews)
.orElse(0);
List<String> tags = newsTagRepository.findByNews(latestNews).stream()
.map(tag -> tag.getTag().getValue())
.toList();

List<String> tags = getTags(latestNews);

return NewsListResponse.from(latestNews, NumberFormatter.format(totalViewCnt), tags);
}

private void increaseView(News news) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime startOfDay = now.toLocalDate().atStartOfDay();
LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59, 999999999);
NewsView newsView =
newsViewRepository.findByNewsAndViewDateBetween(news, startOfDay, endOfDay)
.orElse(NewsView.from(news));
newsView.setViewCount(newsView.getViewCount() + 1);
newsViewRepository.save(newsView);
}
}

0 comments on commit cdc4c4a

Please sign in to comment.