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
1 change: 0 additions & 1 deletion .github/workflows/dev-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ jobs:
echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml
echo "${{ secrets.APPLICATION_PROD_YML }}" > ./src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_OAUTH2_YML }}" > ./src/main/resources/application-oauth2.yml
echo "${{ secrets.LOGBACK_SPRING_XML }}" > ./src/main/resources/logback-spring.xml

mkdir -p src/test/resources
echo "${{ secrets.APPLICATION_TEST_YML }}" > ./src/test/resources/application-test.yml
Expand Down
2 changes: 0 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ services:
condition: service_healthy
kibana:
condition: service_healthy
logstash01:
condition: service_healthy
networks:
- monstache-network

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class GlobalExceptionHandler {
private ApiResponse<CustomException> handleCustomException(CustomException exception) {

/// 로그 발생
log.error("[ERROR 로깅] : {}", exception.getMessage());
log.error("[ERROR 로깅] : {}", exception.getErrorCode().getMessage());

return ApiResponse.fail(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public void logBeforeExecution(JoinPoint joinPoint) throws Throwable {
}

// 로그 출력
log.info("요청 정보 - 전체URL: {} | URI: {} | 메서드: {} | 유저: {} | Origin: {}",
request.getRequestURL(),
request.getRequestURI(),
log.info("[HTTP 로깅]: {}, [{}] ,{}, {}",
request.getHeader("Origin"),
request.getMethod(),
username,
request.getHeader("Origin"));

request.getRequestURL(),
username);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ public class SearchController implements SearchControllerSpec {
@GetMapping
public ApiResponse<SliceResponse<ProductListResponse>> searchProducts(
@RequestParam("keyword") String keyword,
PageRequest pageRequest,
@RequestParam int page,
@RequestParam int size,
@AuthenticationPrincipal PrincipalDetails principalDetails
) {

/// Pageable
Pageable pageable = org.springframework.data.domain.PageRequest.of(
pageRequest.getPage() - 1,
pageRequest.getSize(),
Sort.by(Sort.Direction.DESC, "id")
);

/// 유저가 없다면 null 저장
UUID userId = principalDetails != null ? principalDetails.getId() : null;

/// 서비스 호출
Slice<ProductListResponse> products = service.searchProducts(keyword, pageable, userId);
Slice<ProductListResponse> products = service.searchProducts(keyword, page, size, userId);

/// 서비스 호출(총 검색 결과 개수)
long countByKeyword = service.countByKeyword(keyword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public interface SearchControllerSpec {
ApiResponse<SliceResponse<ProductListResponse>> searchProducts(
@Parameter(example = "하우징")
@RequestParam("keyword") String keyword,
PageRequest pageRequest,

@Parameter(example = "1")
@RequestParam int page,

@Parameter(example = "20")
@RequestParam int size,
@AuthenticationPrincipal PrincipalDetails principalDetails
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public interface SearchUseCase {

/// 검색
Slice<ProductListResponse> searchProducts(String keyword, Pageable pageable, UUID userId);
Slice<ProductListResponse> searchProducts(String keyword, int page, int size, UUID userId);

/// 나의 검색에 목록 확인하기
List<Search> getMySearches(UUID userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package site.kikihi.custom.platform.application.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
Expand Down Expand Up @@ -30,6 +32,7 @@
import java.util.UUID;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
public class SearchService implements SearchUseCase {
Expand All @@ -47,9 +50,10 @@ public class SearchService implements SearchUseCase {

/// 키워드 검색 (name, description)
@Override
public Slice<ProductListResponse> searchProducts(String keyword, Pageable pageable, UUID userId) {
public Slice<ProductListResponse> searchProducts(String keyword, int page, int size, UUID userId) {

/// Pageable 구성
Pageable pageRequest = PageRequest.of(page - 1, size);

// match 쿼리 구성
Query nameMatch = MatchQuery.of(m -> m.field("name").query(keyword))._toQuery();
Expand All @@ -65,7 +69,7 @@ public Slice<ProductListResponse> searchProducts(String keyword, Pageable pageab
// NativeQuery
NativeQuery query = NativeQuery.builder()
.withQuery(boolQuery)
.withPageable(pageable)
.withPageable(pageRequest)
.withMinScore(minScore)
.build();

Expand All @@ -91,9 +95,9 @@ public Slice<ProductListResponse> searchProducts(String keyword, Pageable pageab

/// 페이징 처리
// 현재 페이지 결과 수
boolean hasNext = checkNext(pageable.getPageNumber(), pageable.getPageSize(), searchHits);
boolean hasNext = checkNext(page, size, searchHits);

Slice<Product> products = new SliceImpl<>(elasticProducts, pageable, hasNext);
Slice<Product> products = new SliceImpl<>(elasticProducts, pageRequest, hasNext);

return toProductListResponse(userId, products);
}
Expand Down
53 changes: 38 additions & 15 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>
<springProfile name ="dev">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>

<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>kkh-logstash:5044</destination>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%msg%n</pattern>
</encoder>
</appender>
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>127.0.0.1:5044</destination>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="LOGSTASH"/>
</root>
</springProfile>
<springProfile name ="prod">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>

<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>kkh-logstash:5044</destination>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="LOGSTASH"/>
</root>
</springProfile>

<root level="info">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="LOGSTASH"/>
</root>
</configuration>
Loading