Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Academ Back-end repository입니다.
---

### 프로젝트 구조
( 최신화 : v1.2.0-alpha )
( 최신화 : v1.2.1-alpha )
```
├── .github
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,61 +22,41 @@ public class TrafficFilter extends OncePerRequestFilter {

@Override
@Transactional
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {

// 비동기 가능 여부 확인
if(request.isAsyncSupported())
{
// 비동기 작업 수행
AsyncContext asyncContext = request.startAsync();

asyncContext.start(() -> {

Traffic traffic = trafficRepository.searchTraffic(request.getRequestURI(), String.valueOf(LocalDate.now().getYear()), (byte) LocalDate.now().getMonthValue());

// 기존 트래픽 정보가 존재한다면, count 값을 1 증가
// 기존 트래픽 정보가 존재하지 않는다면, 새롭게 만든 후 count 값을 1로 초기화
if(traffic != null)
{
traffic.setCount(traffic.getCount() + 1);

trafficRepository.save(traffic);
}
else
{
Traffic newTraffic = Traffic.builder()
.api_path(request.getRequestURI())
.year(String.valueOf(LocalDate.now().getYear()))
.month((byte) LocalDate.now().getMonthValue())
.count(1)
.build();

trafficRepository.save(newTraffic);
}

// 비동기 작업 완료
asyncContext.complete();
});
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
{
try {
Traffic traffic = trafficRepository.searchTraffic(request.getRequestURI(), String.valueOf(LocalDate.now().getYear()), (byte) LocalDate.now().getMonthValue());

// 기존 트래픽 정보가 존재한다면, count 값을 1 증가
// 기존 트래픽 정보가 존재하지 않는다면, 새롭게 만든 후 count 값을 1로 초기화
if (traffic != null) {
traffic.setCount(traffic.getCount() + 1);

trafficRepository.save(traffic);
} else {
Traffic newTraffic = Traffic.builder()
.api_path(request.getRequestURI())
.year(String.valueOf(LocalDate.now().getYear()))
.month((byte) LocalDate.now().getMonthValue())
.count(1)
.build();

trafficRepository.save(newTraffic);
}
} catch (Exception error) {
throw new RuntimeException(error);
}

filterChain.doFilter(request, response);

}

// 필터를 적용하지 않을 경로 설정
@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {

String[] excludePath = {
"/api/admin",
"/api/is-secure",
"/swagger-ui",
"/v3/api-docs"
};
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException
{
String path = request.getRequestURI();

return Arrays.stream(excludePath).anyMatch(path::startsWith);

return !path.startsWith("/api");
}

}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
academ:
version: "v1.2.0-alpha"
version: "v1.2.1-alpha"

spring:

Expand Down
Loading