Skip to content

Commit

Permalink
[Merge] 'feature/jin' -> 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/com/mpnp/baechelin/store/service/StoreService.java
  • Loading branch information
Anna-Jin committed Jul 30, 2022
2 parents a3c64a8 + ab8854d commit a280912
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 55 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/mpnp/baechelin/common/QueryDslSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ public static BooleanExpression matchAddressWithSido(String sido) {
"function('match', {0}, {1}, {2})", store.address, store.address, sido).gt(0);
}
public static BooleanExpression matchAddressWithSidoAndSigungu(String sido, String sigungu) {
String[] diviedSigungu = sigungu.split(" ");

// sido가 null이면 sigungu는 무조건 null
// sido가 null이 아니면 sigungu는 null 또는 not null
if (StringUtils.isEmpty(sido)) {
return null;
} else if (StringUtils.isEmpty(sigungu)) {
// sido가 null이 아니고 sigungu가 null이면 sido 검색 결과 리턴
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido).gt(0);
} else if (sigungu.split(" ").length > 1) {
} else if (diviedSigungu.length > 1) {
// sigungu가 도/시/구 로 나눠져있을 때 (ex. 경기도 성남시 분당구)
// 정확한 검색을 위해 + 연산자 추가
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + diviedSigungu[0] + " +" + diviedSigungu[1]).gt(0);
} else {
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu).gt(0);
}
return Expressions.numberTemplate(
Integer.class,
"function('match', {0}, {1}, {2})", store.address, store.address, sido + " +" + sigungu).gt(0);
}

public static BooleanExpression matchKeyword(String keyword) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Map<String, List<String>> getSigungu(@RequestParam String sido) {

@ApiOperation(value = "시/도, 시/군/구, 검색어를 이용해 업장 리스트를 조회하는 메소드")
@GetMapping("/search")
public List<StoreCardResponseDto> searchStoresByKeyword(
public StorePagedResponseDto searchStoresByKeyword(
@RequestParam(required = false) String sido,
@RequestParam(required = false) String sigungu,
@RequestParam(required = false) String keyword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public Page<Store> findStoreOrderByBookmarkNullCase(BooleanBuilder builder,
return new PageImpl<>(storeList, pageable, fetchCount);
}

// 시/도 정보로 시/군/구 정보를 조회
public List<Store> getSigungu(String sido) {
BooleanExpression matchAddress = QueryDslSearch.matchAddressWithSido(sido);

Expand All @@ -155,17 +156,20 @@ public List<Store> getSigungu(String sido) {


// 주소로 검색, 검색어로 검색
public List<Store> searchStores(String sido, String sigungu, String keyword, Pageable pageable) {
public Page<Store> searchStores(String sido, String sigungu, String keyword, Pageable pageable) {
BooleanExpression matchAddress = QueryDslSearch.matchAddressWithSidoAndSigungu(sido, sigungu);
BooleanExpression matchKeyword = QueryDslSearch.matchKeyword(keyword);

return queryFactory
List<Store> storeList = queryFactory
.selectFrom(store)
.where(matchAddress,
matchKeyword)
.where(matchAddress, matchKeyword)
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.fetch();
int fetchSize = queryFactory.selectFrom(store)
.where(matchAddress, matchKeyword)
.fetch().size();
return new PageImpl<>(storeList, pageable, fetchSize);
}

}
63 changes: 18 additions & 45 deletions src/main/java/com/mpnp/baechelin/store/service/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,15 @@ public StoreDetailResponseDto getStore(long storeId, String socialId) {

List<String> storeImageList = new ArrayList<>();

store.getStoreImageList()
.forEach(storeImage -> storeImageList.add(storeImage.getStoreImageUrl()));

store.getReviewList()
.forEach(review -> review.getReviewImageList()
store.getStoreImageList().forEach(storeImage -> storeImageList.add(storeImage.getStoreImageUrl()));
store.getReviewList().forEach(review -> review.getReviewImageList()
.forEach(reviewImage -> storeImageList.add(reviewImage.getReviewImageUrl())));

if (socialId == null) {
return new StoreDetailResponseDto(store, "N", storeImageList);
} else {
String isBookmark = "N";
for (Bookmark bookmark : store.getBookmarkList()) {
if (bookmark.getStoreId().getId() == store.getId()
&& bookmark.getUserId().getSocialId().equals(socialId)) {
isBookmark = "Y";
break;
}
}
return new StoreDetailResponseDto(store, isBookmark, storeImageList);
}
User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId);

boolean isBookmark = bookmarkRepository.existsByStoreIdAndUserId(store, targetUser);
return new StoreDetailResponseDto(store, isBookmark ? "Y" : "N", storeImageList);

}

/**
Expand Down Expand Up @@ -227,36 +216,20 @@ public Map<String, List<String>> getSigungu(String sido) {
}

/**
* 업장 검색
*
* @param sido 시/도명
* @param sigungu 시/군/구명
* @param keyword 검색어
* @param socialId 업장 pk
* @param pageable page, size
* @return 검색된 업장 리스트
* 엄장 검색
* @param sido 시/도명
* @param sigungu 시/군/구명
* @param keyword 검색어
* @param socialId 사용자 소셜 아이디
* @param pageable 페이징
* @return 페이징이 적용된 검색 결과 리턴
*/
public List<StoreCardResponseDto> searchStores(String sido, String sigungu, String keyword, String socialId, Pageable pageable) {
List<Store> storeList = storeQueryRepository.searchStores(sido, sigungu, keyword, pageable);
public StorePagedResponseDto searchStores(String sido, String sigungu, String keyword, String socialId, Pageable pageable) {
Page<Store> searchStores = storeQueryRepository.searchStores(sido, sigungu, keyword, pageable);

List<StoreCardResponseDto> result = new ArrayList<>();
User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId);

for (Store store : storeList) {
if (socialId == null) {
result.add(new StoreCardResponseDto(store, "N"));
} else {
String isBookmark = "N";
for (Bookmark bookmark : store.getBookmarkList()) {
if (bookmark.getStoreId().getId() == store.getId()
&& bookmark.getUserId().getSocialId().equals(socialId)) {
isBookmark = "Y";
break;
}
}
result.add(new StoreCardResponseDto(store, isBookmark));
}
}
return result;
return getStoreCardPagedResponseDto(targetUser, searchStores);
}

@Scheduled(cron = "0 0 0-23 * * *")
Expand Down

0 comments on commit a280912

Please sign in to comment.