From e1bca38eeeeadb2d7041d4431e97b0dc12532148 Mon Sep 17 00:00:00 2001 From: Anna-Jin Date: Tue, 19 Jul 2022 01:46:08 +0900 Subject: [PATCH] =?UTF-8?q?#18=20[Update]=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/security/SecurityConfig.java | 2 +- .../controller/StoreDetailController.java | 28 ------ .../store/service/StoreDetailService.java | 92 ------------------- 3 files changed, 1 insertion(+), 121 deletions(-) delete mode 100644 src/main/java/com/mpnp/baechelin/store/controller/StoreDetailController.java delete mode 100644 src/main/java/com/mpnp/baechelin/store/service/StoreDetailService.java diff --git a/src/main/java/com/mpnp/baechelin/config/security/SecurityConfig.java b/src/main/java/com/mpnp/baechelin/config/security/SecurityConfig.java index 4081b84..9baf12f 100644 --- a/src/main/java/com/mpnp/baechelin/config/security/SecurityConfig.java +++ b/src/main/java/com/mpnp/baechelin/config/security/SecurityConfig.java @@ -60,7 +60,7 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .and() .authorizeRequests() .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() // cors 요청 허용 - .antMatchers("/review", "/api/bookmark", "/store/register", "/user").hasAnyAuthority(RoleType.USER.getCode(), RoleType.ADMIN.getCode()) + .antMatchers("/review", "/api/bookmark", "/store/register", "/userinfo").hasAnyAuthority(RoleType.USER.getCode(), RoleType.ADMIN.getCode()) .antMatchers("/admin/**").hasAnyAuthority(RoleType.ADMIN.getCode()) .antMatchers("/**").permitAll() // 그 외 요청은 모두 허용 .anyRequest().authenticated() // 위의 요청 외의 요청은 무조건 권한검사 diff --git a/src/main/java/com/mpnp/baechelin/store/controller/StoreDetailController.java b/src/main/java/com/mpnp/baechelin/store/controller/StoreDetailController.java deleted file mode 100644 index e976549..0000000 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreDetailController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.mpnp.baechelin.store.controller; - -import com.mpnp.baechelin.store.dto.StoreResponseDto; -import com.mpnp.baechelin.store.service.StoreDetailService; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.core.userdetails.User; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/store") -public class StoreDetailController { - - private final StoreDetailService storeDetailService; - - @ApiOperation(value = "업장 상세정보를 조회하는 메소드") - @GetMapping("/detail/{storeId}") - public StoreResponseDto getStore( - @PathVariable(required = false) int storeId, - @AuthenticationPrincipal User user) { - return storeDetailService.getStore(storeId, user); - } -} diff --git a/src/main/java/com/mpnp/baechelin/store/service/StoreDetailService.java b/src/main/java/com/mpnp/baechelin/store/service/StoreDetailService.java deleted file mode 100644 index 599a4f9..0000000 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreDetailService.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.mpnp.baechelin.store.service; - -import com.mpnp.baechelin.bookmark.domain.Bookmark; -import com.mpnp.baechelin.review.domain.Review; -import com.mpnp.baechelin.review.dto.ReviewResponseDto; -import com.mpnp.baechelin.store.domain.Store; -import com.mpnp.baechelin.store.domain.StoreImage; -import com.mpnp.baechelin.store.dto.StoreImgResponseDto; -import com.mpnp.baechelin.store.dto.StoreResponseDto; -import com.mpnp.baechelin.store.repository.StoreRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.userdetails.User; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.List; - -@Service -@RequiredArgsConstructor -@Transactional -public class StoreDetailService { - - private final StoreRepository storeRepository; - - /** - * 업장 상세 조회 - * @param storeId - * @param user - * @return - */ - public StoreResponseDto getStore(int storeId, User user) { - Store foundStore = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다.")); - - return storeToResDto(foundStore, user); - } - - public StoreResponseDto storeToResDto(Store store, User user) { - // StoreImage entity -> dto - List storeImageList = new ArrayList<>(); - for (StoreImage storeImage : store.getStoreImageList()) { - StoreImgResponseDto storeImgResponse = new StoreImgResponseDto(storeImage.getStoreImageUrl()); - storeImageList.add(storeImgResponse); - } - - List reviewList = store.getReviewList(); - - double totalPoint = 0; - double pointAvg; - if (reviewList.size() > 0) { - for (Review review : reviewList) { - totalPoint += review.getPoint(); - } - // 소숫점 첫째자리 수까지 별점 평균 구하기 - pointAvg = Double.parseDouble(String.format("%.1f", totalPoint / reviewList.size())); - } else { - // review가 없다면 별점 평균 0 - pointAvg = 0; - } - - // TODO 북마크 여부 가져오기 - String isBookmark = "N"; - for (Bookmark bookmark : store.getBookmarkList()) { - if (user == null) { - isBookmark = "N"; - } else { - if (bookmark.getStoreId().getId() == store.getId() - && bookmark.getUserId().getSocialId().equals(user.getUsername())) { - isBookmark = "Y"; - } - } - } - return StoreResponseDto.builder() - .storeId(store.getId()) - .category(store.getCategory()) - .name(store.getName()) - .latitude(store.getLatitude()) - .longitude(store.getLongitude()) - .address(store.getAddress()) - .elevator(store.getElevator()) - .toilet(store.getToilet()) - .parking(store.getParking()) - .phoneNumber(store.getPhoneNumber()) - .heightDifferent(store.getHeightDifferent()) - .approach(store.getApproach()) - .storeImgList(storeImageList) - .pointAvg(pointAvg) - .IsBookmark(isBookmark) - .build(); - } - -}