Skip to content

Commit

Permalink
[Merge] develop -> jsoi
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 27, 2022
2 parents b3a3817 + a9c2aef commit 5e156d3
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.and()
.authorizeRequests()
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll() // cors 요청 허용
.antMatchers("/review", "/api/bookmark", "/store/register", "/userinfo").hasAnyAuthority(RoleType.USER.getCode(), RoleType.ADMIN.getCode())
.antMatchers("/review", "/api/bookmark", "/store/register", "/user").hasAnyAuthority(RoleType.USER.getCode(), RoleType.ADMIN.getCode())
.antMatchers("/admin/**").hasAnyAuthority(RoleType.ADMIN.getCode())
.antMatchers("/**").permitAll() // 그 외 요청은 모두 허용
.anyRequest().authenticated() // 위의 요청 외의 요청은 무조건 권한검사
Expand Down
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
Expand Up @@ -16,7 +16,7 @@
@Getter @Setter
@Builder
@Slf4j
public class StoreCardResponseDto implements Comparable<StoreCardResponseDto> {
public class StoreCardResponseDto {
private long storeId;
private String category;
private String name;
Expand All @@ -29,7 +29,7 @@ public class StoreCardResponseDto implements Comparable<StoreCardResponseDto> {
private String phoneNumber;
private String heightDifferent;
private String approach;
private List<StoreImgResponseDto> storeImgList = new ArrayList<>();
private List<StoreImgResponseDto> storeImgList;
private int bookmarkCount;
private String bookmark;

Expand All @@ -52,17 +52,6 @@ public StoreCardResponseDto(Store store) {
this.bookmarkCount = store.getBookMarkCount();
}

@Override
public int compareTo(StoreCardResponseDto sad) {
if (this.pointAvg > sad.pointAvg) {
return -1;
} else if (this.pointAvg < sad.pointAvg) {
return 1;
}
return 0;
}


public StoreCardResponseDto(Store store, String isBookMark) {
this.storeId = store.getId();
this.category = store.getCategory();
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
Loading

0 comments on commit 5e156d3

Please sign in to comment.