From 31d40267f4963e6d129ab9faea23be355ba65140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B6=98=EC=8B=9D?= <142300831+Choon0414@users.noreply.github.com> Date: Sun, 15 Dec 2024 20:21:27 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/bus/controller/BusController.java | 1 - .../article/repository/ArticleRepository.java | 2 +- .../article/service/ArticleService.java | 30 ++++++++----------- 3 files changed, 13 insertions(+), 20 deletions(-) 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(); }