diff --git a/src/main/java/in/koreatech/koin/domain/bus/controller/BusController.java b/src/main/java/in/koreatech/koin/domain/bus/controller/BusController.java index c331562dd..56399fa81 100644 --- a/src/main/java/in/koreatech/koin/domain/bus/controller/BusController.java +++ b/src/main/java/in/koreatech/koin/domain/bus/controller/BusController.java @@ -25,7 +25,6 @@ public class BusController implements BusApi { private final BusService busService; private final ShuttleBusService shuttleBusService; - private final ArticleService articleService; @GetMapping public ResponseEntity getBusRemainTime( diff --git a/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java b/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java index 69bcbb770..eb560a30b 100644 --- a/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java +++ b/src/main/java/in/koreatech/koin/domain/community/article/repository/ArticleRepository.java @@ -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
findTop5OrderByCreatedAtDesc(); + List
findBusArticlesTop5OrderByCreatedAtDesc(); } diff --git a/src/main/java/in/koreatech/koin/domain/community/article/service/ArticleService.java b/src/main/java/in/koreatech/koin/domain/community/article/service/ArticleService.java index c77014b4b..198769340 100644 --- a/src/main/java/in/koreatech/koin/domain/community/article/service/ArticleService.java +++ b/src/main/java/in/koreatech/koin/domain/community/article/service/ArticleService.java @@ -260,7 +260,7 @@ public void updateHotArticles() { @Transactional public void updateBusNoticeArticle() { - List
articles = articleRepository.findTop5OrderByCreatedAtDesc(); + List
articles = articleRepository.findBusArticlesTop5OrderByCreatedAtDesc(); LocalDate latestDate = articles.get(0).getCreatedAt().toLocalDate(); List
latestArticles = articles.stream() .filter(article -> article.getCreatedAt().toLocalDate().isEqual(latestDate)) @@ -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(); }