Skip to content

Commit

Permalink
#29 [Update] 업장 상세 조회에 review 이미지 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna-Jin committed Jul 27, 2022
1 parent 113fc5c commit 5d9a211
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mpnp.baechelin.login.jwt.AuthToken;
import com.mpnp.baechelin.login.jwt.AuthTokenProvider;
import com.mpnp.baechelin.store.dto.StoreCardResponseDto;
import com.mpnp.baechelin.store.dto.StoreDetailResponseDto;
import com.mpnp.baechelin.store.dto.StorePagedResponseDto;
import com.mpnp.baechelin.store.service.StoreService;
import io.swagger.annotations.Api;
Expand Down Expand Up @@ -72,7 +73,7 @@ public StorePagedResponseDto getStoreInRangeHighBookmark(@RequestParam(required

@ApiOperation(value = "업장 상세정보를 조회하는 메소드")
@GetMapping("/detail/{storeId}")
public StoreCardResponseDto getStore(
public StoreDetailResponseDto getStore(
@PathVariable(required = false) int storeId,
HttpServletRequest request,
@AuthenticationPrincipal User user) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.mpnp.baechelin.store.dto;

import com.mpnp.baechelin.review.domain.Review;
import com.mpnp.baechelin.store.domain.Store;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class StoreDetailResponseDto {
private long storeId;
private String category;
private String name;
private BigDecimal latitude;
private BigDecimal longitude;
private String address;
private String elevator;
private String toilet;
private String parking;
private String phoneNumber;
private String heightDifferent;
private String approach;
private List<String> storeImgList;
private int bookmarkCount;
private String bookmark;
@Builder.Default
private double pointAvg = 0.0;

public StoreDetailResponseDto(Store store, String isBookMark, List<String> imageList) {
this.storeId = store.getId();
this.category = store.getCategory();
this.name = store.getName();
this.latitude = store.getLatitude();
this.longitude = store.getLongitude();
this.address = store.getAddress();
this.elevator = store.getElevator();
this.toilet = store.getToilet();
this.parking = store.getParking();
this.phoneNumber = store.getPhoneNumber();
this.heightDifferent = store.getHeightDifferent();
this.approach = store.getApproach();
this.bookmarkCount = store.getBookMarkCount();
this.storeImgList = imageList;
this.pointAvg = Double.parseDouble(String.format(store.getReviewList().stream()
.collect(Collectors.averagingDouble(Review::getPoint)).toString(), 0.1f));
this.bookmark = isBookMark;
}
}
31 changes: 28 additions & 3 deletions src/main/java/com/mpnp/baechelin/store/service/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import com.mpnp.baechelin.bookmark.domain.Bookmark;
import com.mpnp.baechelin.bookmark.repository.BookmarkRepository;
import com.mpnp.baechelin.common.QuerydslLocation;
import com.mpnp.baechelin.review.domain.Review;
import com.mpnp.baechelin.review.domain.ReviewImage;
import com.mpnp.baechelin.store.domain.Store;
import com.mpnp.baechelin.store.domain.StoreImage;
import com.mpnp.baechelin.store.dto.StoreCardResponseDto;
import com.mpnp.baechelin.store.dto.StoreDetailResponseDto;
import com.mpnp.baechelin.store.dto.StorePagedResponseDto;
import com.mpnp.baechelin.store.repository.StoreQueryRepository;
import com.mpnp.baechelin.store.repository.StoreRepository;
Expand Down Expand Up @@ -160,11 +164,23 @@ private List<StoreCardResponseDto> getStoreCardResponseDtos(User targetUser, Lis
* @param socialId 유저 social 아이디
* @return 업장 상세 정보
*/
public StoreCardResponseDto getStore(long storeId, String socialId) {
public StoreDetailResponseDto getStore(long storeId, String socialId) {
Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다."));

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

for (StoreImage storeImage : store.getStoreImageList()) {
storeImageList.add(storeImage.getStoreImageUrl());
}

for (Review review : store.getReviewList()) {
for (ReviewImage reviewImage : review.getReviewImageList()) {
storeImageList.add(reviewImage.getReviewImageUrl());
}
}

if (socialId == null) {
return new StoreCardResponseDto(store, "N");
return new StoreDetailResponseDto(store, "N", storeImageList);
} else {
String isBookmark = "N";
for (Bookmark bookmark : store.getBookmarkList()) {
Expand All @@ -174,7 +190,7 @@ public StoreCardResponseDto getStore(long storeId, String socialId) {
break;
}
}
return new StoreCardResponseDto(store, isBookmark);
return new StoreDetailResponseDto(store, isBookmark, storeImageList);
}
}

Expand Down Expand Up @@ -203,6 +219,15 @@ public Map<String, List<String>> getSigungu(String sido) {
return result;
}

/**
* 업장 검색
* @param sido 시/도명
* @param sigungu 시/군/구명
* @param keyword 검색어
* @param socialId 업장 pk
* @param pageable page, size
* @return
*/
public List<StoreCardResponseDto> searchStores(String sido, String sigungu, String keyword, String socialId, Pageable pageable) {
List<Store> storeList = storeQueryRepository.searchStores(sido, sigungu, keyword, pageable);

Expand Down

0 comments on commit 5d9a211

Please sign in to comment.