Skip to content

Commit

Permalink
#39 [Add] DTO에 카운트 변수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 28, 2022
1 parent 98eb22c commit 199d39e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@

import java.util.List;

@Getter @Setter
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class StorePagedResponseDto {
private boolean hasNextPage;
private long totalCount;
private List<StoreCardResponseDto> cards;

public StorePagedResponseDto(boolean hasNextPage, List<StoreCardResponseDto> cards, long totalCount) {
this.hasNextPage = hasNextPage;
this.cards = cards;
this.totalCount = totalCount;
}
}
22 changes: 5 additions & 17 deletions src/main/java/com/mpnp/baechelin/store/service/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.mpnp.baechelin.user.domain.User;
import com.mpnp.baechelin.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -58,13 +59,6 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat
return getStoreCardPagedResponseDto(targetUser, betweenLngLat);
}

public StorePagedResponseDto getStoreInTwoPointsRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility, Pageable pageable, String socialId) {
// public List<StoreCardResponseDto> getStoreInRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List<String> facility, Pageable pageable, String socialId) {
User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId);
Page<Store> betweenSquare = storeQueryRepository.findBetweenTwoPoint(latStart, latEnd, lngStart, lngEnd, category, facility, pageable);
// store 가져와서 dto 매핑
return getStoreCardPagedResponseDto(targetUser, betweenSquare);
}

/**
* @param lat 위도
Expand Down Expand Up @@ -126,17 +120,11 @@ public StorePagedResponseDto getStoreInRangeHighBookmark(BigDecimal lat, BigDeci
*/
private StorePagedResponseDto getStoreCardPagedResponseDto(User targetUser, Page<Store> resultStoreList) {
List<StoreCardResponseDto> mappingResult = new ArrayList<>();
if (targetUser == null) {
for (Store store : resultStoreList) {
mappingResult.add(new StoreCardResponseDto(store, "N"));
}
} else {
for (Store store : resultStoreList) {
boolean isBookmark = bookmarkRepository.existsByStoreIdAndUserId(store, targetUser);
mappingResult.add(new StoreCardResponseDto(store, isBookmark ? "Y" : "N"));
}
for (Store store : resultStoreList) {
boolean isBookmark = bookmarkRepository.existsByStoreIdAndUserId(store, targetUser);
mappingResult.add(new StoreCardResponseDto(store, isBookmark ? "Y" : "N"));
}
return new StorePagedResponseDto(resultStoreList.hasNext(), mappingResult);
return new StorePagedResponseDto(resultStoreList.hasNext(), mappingResult, resultStoreList.getTotalElements());
}


Expand Down

0 comments on commit 199d39e

Please sign in to comment.