Skip to content

Commit

Permalink
chore : 머지 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Choon0414 committed Dec 14, 2024
1 parent cc6f9bb commit a7fdd57
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ ResponseEntity<BusScheduleResponse> getBusRouteSchedule(
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
}
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))),
}
)
@Operation(summary = "버스 긴급 공지 조회")
@GetMapping("/notice")
ResponseEntity<BusNoticeResponse> getNotice();
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
package in.koreatech.koin.domain.bus.controller;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import in.koreatech.koin.domain.bus.dto.BusCourseResponse;
import in.koreatech.koin.domain.bus.dto.BusRemainTimeResponse;
import in.koreatech.koin.domain.bus.dto.BusRouteCommand;
import in.koreatech.koin.domain.bus.dto.BusScheduleResponse;
import in.koreatech.koin.domain.bus.dto.BusTimetableResponse;
import in.koreatech.koin.domain.bus.dto.CityBusTimetableResponse;
import in.koreatech.koin.domain.bus.dto.ShuttleBusRoutesResponse;
import in.koreatech.koin.domain.bus.dto.ShuttleBusTimetableResponse;
import in.koreatech.koin.domain.bus.dto.SingleBusTimeResponse;
import in.koreatech.koin.domain.bus.dto.*;
import in.koreatech.koin.domain.bus.model.BusTimetable;
import in.koreatech.koin.domain.bus.model.enums.BusRouteType;
Expand All @@ -33,10 +12,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalTime;
Expand Down
36 changes: 9 additions & 27 deletions src/main/java/in/koreatech/koin/domain/bus/service/BusService.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
package in.koreatech.koin.domain.bus.service;

import static in.koreatech.koin.domain.bus.model.enums.BusStation.getDirection;

import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.format.TextStyle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.*;

import in.koreatech.koin.domain.bus.dto.*;
import in.koreatech.koin.domain.bus.repository.BusNoticeRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import in.koreatech.koin.domain.bus.dto.BusCourseResponse;
import in.koreatech.koin.domain.bus.dto.BusRemainTimeResponse;
import in.koreatech.koin.domain.bus.dto.BusRouteCommand;
import in.koreatech.koin.domain.bus.dto.BusScheduleResponse;
import in.koreatech.koin.domain.bus.dto.BusScheduleResponse.ScheduleInfo;
import in.koreatech.koin.domain.bus.dto.BusTimetableResponse;
import in.koreatech.koin.domain.bus.dto.CityBusTimetableResponse;
import in.koreatech.koin.domain.bus.dto.SingleBusTimeResponse;
import in.koreatech.koin.domain.bus.exception.BusIllegalStationException;
import in.koreatech.koin.domain.bus.exception.BusTypeNotFoundException;
import in.koreatech.koin.domain.bus.exception.BusTypeNotSupportException;
Expand All @@ -42,6 +15,7 @@
import in.koreatech.koin.domain.bus.model.mongo.BusCourse;
import in.koreatech.koin.domain.bus.model.mongo.CityBusTimetable;
import in.koreatech.koin.domain.bus.model.mongo.Route;
import in.koreatech.koin.domain.bus.repository.BusNoticeRepository;
import in.koreatech.koin.domain.bus.repository.BusRepository;
import in.koreatech.koin.domain.bus.repository.CityBusTimetableRepository;
import in.koreatech.koin.domain.bus.service.route.BusRouteStrategy;
Expand All @@ -52,6 +26,14 @@
import in.koreatech.koin.domain.version.service.VersionService;
import in.koreatech.koin.global.exception.KoinIllegalArgumentException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.*;
import java.time.format.TextStyle;
import java.util.*;

import static in.koreatech.koin.domain.bus.model.enums.BusStation.getDirection;

@Service
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ default Article getNextArticle(Board board, Article article) {
@Query("SELECT a.title FROM Article a WHERE a.id = :id")
String getTitleById(@Param("id") Integer id);


@Query(value = "SELECT * FROM koreatech_articles a "
+ "WHERE a.title REGEXP '통학버스|등교버스|셔틀버스|하교버스' "
+ "ORDER BY a.created_at DESC LIMIT 5", nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public class ArticleService {
private static final int HOT_ARTICLE_LIMIT = 10;
private static final int MAXIMUM_SEARCH_LENGTH = 100;
private static final Sort ARTICLES_SORT = Sort.by(
Sort.Order.desc("id")
Sort.Order.desc("id")
);
private static final Sort NATIVE_ARTICLES_SORT = Sort.by(
Sort.Order.desc("id")
Sort.Order.desc("id")
);

private final ArticleRepository articleRepository;
Expand Down Expand Up @@ -82,7 +82,7 @@ private Board getBoard(Integer boardId, Article article) {
boardId = article.getBoard().getId();
}
if (!Objects.equals(boardId, article.getBoard().getId())
&& (!article.getBoard().isNotice() || boardId != NOTICE_BOARD_ID)) {
&& (!article.getBoard().isNotice() || boardId != NOTICE_BOARD_ID)) {
throw ArticleBoardMisMatchException.withDetail("boardId: " + boardId + ", articleId: " + article.getId());
}
return boardRepository.getById(boardId);
Expand All @@ -103,22 +103,22 @@ public ArticlesResponse getArticles(Integer boardId, Integer page, Integer limit

public List<HotArticleItemResponse> getHotArticles() {
List<Article> cacheList = hotArticleRepository.getHotArticles(HOT_ARTICLE_LIMIT).stream()
.map(articleRepository::getById)
.collect(Collectors.toList());
.map(articleRepository::getById)
.collect(Collectors.toList());
if (cacheList.size() < HOT_ARTICLE_LIMIT) {
List<Article> highestHitArticles = articleRepository.findMostHitArticles(
LocalDate.now(clock).minusDays(HOT_ARTICLE_BEFORE_DAYS), HOT_ARTICLE_LIMIT);
LocalDate.now(clock).minusDays(HOT_ARTICLE_BEFORE_DAYS), HOT_ARTICLE_LIMIT);
cacheList.addAll(highestHitArticles);
return cacheList.stream().limit(HOT_ARTICLE_LIMIT)
.map(HotArticleItemResponse::from)
.toList();
.map(HotArticleItemResponse::from)
.toList();
}
return cacheList.stream().map(HotArticleItemResponse::from).toList();
}

@Transactional
public ArticlesResponse searchArticles(String query, Integer boardId, Integer page, Integer limit,
String ipAddress) {
String ipAddress) {
if (query.length() >= MAXIMUM_SEARCH_LENGTH) {
throw new KoinIllegalArgumentException("검색어의 최대 길이를 초과했습니다.");
}
Expand Down Expand Up @@ -162,28 +162,28 @@ private void saveOrUpdateSearchLog(String query, String ipAddress) {

for (String keywordStr : keywords) {
ArticleSearchKeyword keyword = articleSearchKeywordRepository.findByKeyword(keywordStr)
.orElseGet(() -> {
ArticleSearchKeyword newKeyword = ArticleSearchKeyword.builder()
.keyword(keywordStr)
.weight(1.0)
.lastSearchedAt(LocalDateTime.now())
.totalSearch(1)
.build();
articleSearchKeywordRepository.save(newKeyword);
return newKeyword;
});
.orElseGet(() -> {
ArticleSearchKeyword newKeyword = ArticleSearchKeyword.builder()
.keyword(keywordStr)
.weight(1.0)
.lastSearchedAt(LocalDateTime.now())
.totalSearch(1)
.build();
articleSearchKeywordRepository.save(newKeyword);
return newKeyword;
});

ArticleSearchKeywordIpMap map = articleSearchKeywordIpMapRepository.findByArticleSearchKeywordAndIpAddress(
keyword, ipAddress)
.orElseGet(() -> {
ArticleSearchKeywordIpMap newMap = ArticleSearchKeywordIpMap.builder()
.articleSearchKeyword(keyword)
.ipAddress(ipAddress)
.searchCount(1)
.build();
articleSearchKeywordIpMapRepository.save(newMap);
return newMap;
});
keyword, ipAddress)
.orElseGet(() -> {
ArticleSearchKeywordIpMap newMap = ArticleSearchKeywordIpMap.builder()
.articleSearchKeyword(keyword)
.ipAddress(ipAddress)
.searchCount(1)
.build();
articleSearchKeywordIpMapRepository.save(newMap);
return newMap;
});

updateKeywordWeightAndCount(keyword, map);
}
Expand Down Expand Up @@ -223,9 +223,9 @@ public void resetWeightsAndCounts() {
LocalDateTime before = now.minusHours(6).minusMinutes(30);

List<ArticleSearchKeyword> keywordsToUpdate = articleSearchKeywordRepository.findByUpdatedAtBetween(
before, now);
before, now);
List<ArticleSearchKeywordIpMap> ipMapsToUpdate = articleSearchKeywordIpMapRepository.findByUpdatedAtBetween(
before, now);
before, now);

for (ArticleSearchKeyword keyword : keywordsToUpdate) {
keyword.resetWeight();
Expand All @@ -241,14 +241,14 @@ public void updateHotArticles() {
List<ArticleHit> articleHits = articleHitRepository.findAll();
articleHitRepository.deleteAll();
List<Article> allArticles =
articleRepository.findAllByRegisteredAtIsAfter(LocalDate.now(clock).minusDays(HOT_ARTICLE_BEFORE_DAYS));
articleRepository.findAllByRegisteredAtIsAfter(LocalDate.now(clock).minusDays(HOT_ARTICLE_BEFORE_DAYS));
articleHitRepository.saveAll(allArticles.stream().map(ArticleHit::from).toList());

Map<Integer, Integer> articlesIdWithHit = new HashMap<>();
for (Article article : allArticles) {
Optional<ArticleHit> cache = articleHits.stream()
.filter(articleHit -> articleHit.getId().equals(article.getId()))
.findAny();
.filter(articleHit -> articleHit.getId().equals(article.getId()))
.findAny();
int beforeArticleHit = cache.isPresent() ? cache.get().getHit() : 0;
if (article.getTotalHit() - beforeArticleHit <= 0) {
continue;
Expand All @@ -263,8 +263,8 @@ public void updateBusNoticeArticle() {
List<Article> articles = articleRepository.findTop5OrderByCreatedAtDesc();
LocalDate latestDate = articles.get(0).getCreatedAt().toLocalDate();
List<Article> latestArticles = articles.stream()
.filter(article -> article.getCreatedAt().toLocalDate().isEqual(latestDate))
.toList();
.filter(article -> article.getCreatedAt().toLocalDate().isEqual(latestDate))
.toList();

if (latestArticles.size() >= 2) {
latestArticles = latestArticles.stream()
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<configuration>
<!-- <springProperty scope="context" name="SLACK_WEBHOOK_URI" source="slack.logging.error"/>-->
<springProperty scope="context" name="SLACK_WEBHOOK_URI" source="slack.logging.error"/>
<property name="defaultLogPattern"
value="[%d{yyyy-MM-dd'T'HH:mm:ss.SSS}] %-5level --- [%15.15thread] %-40.40logger{36} : %msg%n"/>
<property name="consoleLogPattern"
Expand Down Expand Up @@ -37,7 +37,7 @@
</appender>

<appender name="SLACK" class="com.github.maricn.logback.SlackAppender">
<!-- <webhookUri>${SLACK_WEBHOOK_URI}</webhookUri>-->
<webhookUri>${SLACK_WEBHOOK_URI}</webhookUri>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>${slackLogPattern}</pattern>
</layout>
Expand Down

0 comments on commit a7fdd57

Please sign in to comment.