Skip to content

Commit

Permalink
#18 [Refactor] 스트림 및 범위 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 15, 2022
1 parent 69b0787 commit 56de131
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ public StorePagedResponseDto getStoreInRange(@RequestParam(required = false) Big
@RequestParam(required = false) BigDecimal latEnd,
@RequestParam(required = false) BigDecimal lngStart,
@RequestParam(required = false) BigDecimal lngEnd,
@RequestParam(required = false) BigDecimal lat,
@RequestParam(required = false) BigDecimal lng,
@RequestParam(required = false) String category,
@RequestParam(required = false) List<String> facility,
@PageableDefault Pageable pageable,
@AuthenticationPrincipal User user) {
return storeService.getStoreInRange(latStart, latEnd, lngStart, lngEnd, category, facility, pageable, user == null ? null : user.getUsername());
if (lat != null && lng != null)
return storeService.getStoreInRangeMain(lat, lng, category, facility, pageable, user == null ? null : user.getUsername());
else
return storeService.getStoreInRange(latStart, latEnd, lngStart, lngEnd, category, facility, pageable, user == null ? null : user.getUsername());
}

@GetMapping("/point")
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/mpnp/baechelin/store/service/StoreService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mpnp.baechelin.store.service;

import com.mpnp.baechelin.bookmark.repository.BookmarkRepository;
import com.mpnp.baechelin.config.QuerydslLocation;
import com.mpnp.baechelin.review.domain.Review;
import com.mpnp.baechelin.review.repository.ReviewRepository;
import com.mpnp.baechelin.store.domain.Store;
Expand Down Expand Up @@ -87,7 +88,19 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat
return getStoreCardPagedResponseDto(targetUser, betweenLngLat);
}

// public List<StoreCardResponseDto> getStoreInRangeHighPoint(BigDecimal lat, BigDecimal lng, String
public StorePagedResponseDto getStoreInRangeMain(BigDecimal lat, BigDecimal lng, String category, List<String> facility, Pageable pageable, String socialId) {
BigDecimal[] range = QuerydslLocation.getRange(lat, lng, 10);
return getStoreInRange(range[0], range[1], range[2], range[3], category, facility, pageable, socialId);
}

public StorePagedResponseDto getStoreInRangeMap(BigDecimal lat, BigDecimal lng, String category, List<String> facility, Pageable pageable, String socialId) {
User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId);
Page<Store> betweenLngLat = storeQueryRepository.findStoreOrderByPoint(lat, lng, category, facility, pageable);
// store 가져와서 dto 매핑
return getStoreCardPagedResponseDto(targetUser, betweenLngLat);
}

// public List<StoreCardResponseDto> getStoreInRangeHighPoint(BigDecimal lat, BigDecimal lng, String
public StorePagedResponseDto getStoreInRangeHighPoint(BigDecimal lat, BigDecimal lng, String
category, List<String> facility, Pageable pageable, String socialId) {
User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId);
Expand Down Expand Up @@ -120,14 +133,14 @@ private StorePagedResponseDto getStoreCardPagedResponseDto(User targetUser, Page

private List<StoreCardResponseDto> getStoreCardResponseDtos(User targetUser, List<Store> resultStoreList) {
if (targetUser == null) {
return resultStoreList.parallelStream().map(store -> new StoreCardResponseDto(store, false))
return resultStoreList.stream().map(store -> new StoreCardResponseDto(store, false))
.collect(Collectors.toList());
} else {
return resultStoreList.parallelStream().map(store -> {
return resultStoreList.stream().map(store -> {
long count = targetUser.getBookmarkList().stream()
.filter(b -> b.getUserId() == targetUser && b.getStoreId() == store).count();
return new StoreCardResponseDto(store, count > 0);
}).collect(Collectors.toList());// 순서보장}
}).collect(Collectors.toList());
}
}
}

0 comments on commit 56de131

Please sign in to comment.