Skip to content

Commit

Permalink
refactor : 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
Choon0414 committed Dec 15, 2024
1 parent a7fdd57 commit 31d4026
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class BusController implements BusApi {

private final BusService busService;
private final ShuttleBusService shuttleBusService;
private final ArticleService articleService;

@GetMapping
public ResponseEntity<BusRemainTimeResponse> getBusRemainTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ default Article getNextArticle(Board board, Article article) {
@Query(value = "SELECT * FROM koreatech_articles a "
+ "WHERE a.title REGEXP '통학버스|등교버스|셔틀버스|하교버스' "
+ "ORDER BY a.created_at DESC LIMIT 5", nativeQuery = true)
List<Article> findTop5OrderByCreatedAtDesc();
List<Article> findBusArticlesTop5OrderByCreatedAtDesc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void updateHotArticles() {

@Transactional
public void updateBusNoticeArticle() {
List<Article> articles = articleRepository.findTop5OrderByCreatedAtDesc();
List<Article> articles = articleRepository.findBusArticlesTop5OrderByCreatedAtDesc();
LocalDate latestDate = articles.get(0).getCreatedAt().toLocalDate();
List<Article> latestArticles = articles.stream()
.filter(article -> article.getCreatedAt().toLocalDate().isEqual(latestDate))
Expand All @@ -269,23 +269,17 @@ public void updateBusNoticeArticle() {
if (latestArticles.size() >= 2) {
latestArticles = latestArticles.stream()
.sorted((first, second) -> {
// title에 '사과'가 포함되면 후순위
if (first.getTitle().contains("사과") && !second.getTitle().contains("사과")) {
return 1;
}
if (!first.getTitle().contains("사과") && second.getTitle().contains("사과")) {
return -1;
}

// title에 '긴급'이 포함되면 우선순위
if (first.getTitle().contains("긴급") && !second.getTitle().contains("긴급")) {
return -1;
}
if (!first.getTitle().contains("긴급") && second.getTitle().contains("긴급")) {
return 1;
}

return 0;
int firstWeight = 0;
int secondWeight = 0;

// 제목(title)에 "사과"가 들어가면 후순위, "긴급"이 포함되면 우선순위
if (first.getTitle().contains("사과")) firstWeight++;
if (first.getTitle().contains("긴급")) firstWeight--;

if (second.getTitle().contains("사과")) secondWeight++;
if (second.getTitle().contains("긴급")) secondWeight--;

return Integer.compare(firstWeight, secondWeight);
})
.toList();
}
Expand Down

0 comments on commit 31d4026

Please sign in to comment.