diff --git a/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java b/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java index bfb78df..c11a4bf 100644 --- a/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java +++ b/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java @@ -33,10 +33,11 @@ public class ReviewController { private final ReviewService reviewService; @GetMapping("/review/{storeId}") - public ResponseEntity> getStoreReview(@PathVariable int storeId + public ResponseEntity> getStoreReview(@PathVariable int storeId, + @AuthenticationPrincipal User user //@PageableDefault(page = 0, size = 10, sort = "id", direction = Sort.Direction.DESC) Pageable pageable ) { - List reviewList = reviewService.getReview(storeId); + List reviewList = reviewService.getReview(storeId, user.getUsername()); return new ResponseEntity<>(reviewList, HttpStatus.OK); } diff --git a/src/main/java/com/mpnp/baechelin/review/dto/ReviewRequestDto.java b/src/main/java/com/mpnp/baechelin/review/dto/ReviewRequestDto.java index acd7272..0b3ac4e 100644 --- a/src/main/java/com/mpnp/baechelin/review/dto/ReviewRequestDto.java +++ b/src/main/java/com/mpnp/baechelin/review/dto/ReviewRequestDto.java @@ -12,7 +12,7 @@ @Builder public class ReviewRequestDto { //review 테이블 컬럼 - private long storeId; //업장 아이디 + private long storeId; //업장 아이디 private String content; //리뷰 코멘트 private double point; //별점 private List tagList; //태그 diff --git a/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDto.java b/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDto.java index 6e5db53..6333183 100644 --- a/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDto.java @@ -7,7 +7,6 @@ import java.time.LocalDateTime; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; @Builder @@ -18,8 +17,16 @@ public class ReviewResponseDto { private int reviewId; // storeId private long storeId; private int userId; - private Double point; + private String email; + + private String name; + + private String profile_image_url; + + private String myReview; + + private Double point; private String content; private List reviewImageUrlList; @@ -36,9 +43,24 @@ public ReviewResponseDto(Review review) { this.createdAt = review.getCreatedAt(); this.modifiedAt = review.getModifiedAt(); + this.reviewImageUrlList = review.getReviewImageList().parallelStream().map(ReviewImageResponseDto::new).collect(Collectors.toList()); this.tagList = review.getTagList().parallelStream().map(TagResponseDto::new).collect(Collectors.toList()); } + + public void userInfo(User user, User myUser){ + this.email = user.getEmail(); + this.name = user.getName(); + this.profile_image_url = user.getProfileImageUrl(); + + if(this.userId == myUser.getId()){ + this.myReview = "Y"; + } else if (this.userId != myUser.getId()){ + this.myReview = "N"; + } + + + } @Builder @AllArgsConstructor @NoArgsConstructor diff --git a/src/main/java/com/mpnp/baechelin/review/repository/ReviewImageRepository.java b/src/main/java/com/mpnp/baechelin/review/repository/ReviewImageRepository.java index 1155891..22887c7 100644 --- a/src/main/java/com/mpnp/baechelin/review/repository/ReviewImageRepository.java +++ b/src/main/java/com/mpnp/baechelin/review/repository/ReviewImageRepository.java @@ -4,6 +4,8 @@ import com.mpnp.baechelin.review.domain.ReviewImage; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ReviewImageRepository extends JpaRepository { void deleteAllByReviewId(Review review); void deleteByReviewId(Review review); diff --git a/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java b/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java index 1353f42..232816a 100644 --- a/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java +++ b/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java @@ -10,4 +10,5 @@ public interface ReviewRepository extends JpaRepository { List findAllByStoreId(Store store); + } diff --git a/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java b/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java index b00be96..67a2edd 100644 --- a/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java +++ b/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java @@ -84,10 +84,24 @@ public void review(ReviewRequestDto reviewRequestDto, String socialId) throws IO - public List getReview(long storeId) { + public List getReview(long storeId, String socialId) { + Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당 가게가 없습니다")); - return reviewRepository.findAllByStoreId(store) - .stream().map(ReviewResponseDto::new).collect(Collectors.toList()); + List reviewList = reviewRepository.findAllByStoreId(store); + List reviewResponseDtoList = new ArrayList<>(); + User myUser = userRepository.findBySocialId(socialId); + + for(Review review: reviewList){ + ReviewResponseDto reviewResponseDto = new ReviewResponseDto(review); + Optional user = userRepository.findById(reviewResponseDto.getUserId()); + + reviewResponseDto.userInfo(user.get(), myUser); + reviewResponseDtoList.add(reviewResponseDto); + } + + + return reviewResponseDtoList; +// return reviewRepository.findAllByStoreId(store).stream().map(ReviewResponseDto::new).collect(Collectors.toList()); } @@ -97,7 +111,7 @@ public List getReview(long storeId) { /** 리뷰 수정 */ public void reviewUpdate(ReviewRequestDto reviewRequestDto, String socialId, int reviewId) throws IOException { - long storeId = reviewRequestDto.getStoreId(); + long storeId = reviewRequestDto.getStoreId(); User user = userRepository.findBySocialId(socialId); if(user == null){ new IllegalArgumentException("해당하는 소셜아이디를 찾을 수 없습니다."); } Store store = storeRepository.findById(storeId) .orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다.")); Review review = reviewRepository.findById(reviewId) .orElseThrow(() -> new IllegalArgumentException("해당하는 리뷰가 없습니다.")); @@ -117,6 +131,7 @@ public void reviewUpdate(ReviewRequestDto reviewRequestDto, String socialId, int awsS3Manager.deleteFile(reviewImage.getReviewImageUrl().substring(reviewImage.getReviewImageUrl().indexOf("com/") + 4)); } + System.out.println(review.getId()); reviewImageRepository.deleteAllByReviewId(review); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f9b1dbc..0de368f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,16 +3,15 @@ spring.datasource.username= admin spring.datasource.password=cz_hyy6848 spring.jpa.open-in-view=false spring.jpa.generate-ddl=true -spring.jpa.hibernate.ddl-auto=none +spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.use-new-id-generator-mappings=false -spring.jpa.properties.hibernate.dialect=com.mpnp.baechelin.config.mysql.MySqlDialectCustom spring.jpa.properties.hibernate.format_sql=true spring.jackson.serialization.fail-on-empty-beans=false logging.level.org.hibernate.SQL=debug server.port=9000 #CORS -cors.allowed-origins=http://localhost:12345 +cors.allowed-origins=https://bae-chelin.com:12345,http://localhost:12345 cors.allowed-methods=GET,POST,PUT,DELETE,OPTIONS cors.allowed-headers=* cors.max-age=3600 @@ -21,41 +20,47 @@ jwt.secret=MeongPanNyaengPanBaechelinhanghae99secretKey app.auth.tokenSecret=thisToken2sforMeongPanNyaengPanBaechelin app.auth.tokenExpiry=1800000 app.auth.refreshTokenExpiry=604800000 -app.oauth2.authorizedRedirectUris=http://localhost:12345/oauth/redirect +app.oauth2.authorizedRedirectUris=https://bae-chelin.com:12345/user/oauth/redirect #OAUTH2 +#google spring.security.oauth2.client.registration.google.clientId=1024820989252-osui4ppvp6d26qg5cpb5ap19c93ombpv.apps.googleusercontent.com spring.security.oauth2.client.registration.google.clientSecret=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 -spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:9000/user/oauth2/code/google spring.security.oauth2.client.registration.google.scope=email, profile + +#naver spring.security.oauth2.client.registration.naver.clientId=lnfBJwiFCXxf4KDtCUjK spring.security.oauth2.client.registration.naver.clientSecret=S99V7ezlik spring.security.oauth2.client.registration.naver.clientAuthenticationMethod=post spring.security.oauth2.client.registration.naver.authorizationGrantType=authorization_code -spring.security.oauth2.client.registration.naver.redirectUri=http://localhost:9000/user/oauth2/code/naver +spring.security.oauth2.client.registration.naver.redirectUri=https://api.bae-chelin.com/user/oauth2/code/naver spring.security.oauth2.client.registration.naver.scope=nickname, email, profile_image spring.security.oauth2.client.registration.naver.clientName=Naver + +#kakao spring.security.oauth2.client.registration.kakao.clientId=708d5b42ebe5e4a252a73873a9cc475c spring.security.oauth2.client.registration.kakao.clientSecret=iXUbULiZk7O6ODw1SKGws7KUNfF0BGmM4e spring.security.oauth2.client.registration.kakao.clientAuthenticationMethod=post spring.security.oauth2.client.registration.kakao.authorizationGrantType=authorization_code -spring.security.oauth2.client.registration.kakao.redirectUri=http://localhost:9000/user/oauth2/code/kakao +spring.security.oauth2.client.registration.kakao.redirectUri=https://api.bae-chelin.com/user/oauth2/code/kakao spring.security.oauth2.client.registration.kakao.scope=profile_nickname, profile_image, account_email spring.security.oauth2.client.registration.kakao.clientName=Kakao + +#provider +#naver spring.security.oauth2.client.provider.naver.authorizationUri=https://nid.naver.com/oauth2.0/authorize spring.security.oauth2.client.provider.naver.tokenUri=https://nid.naver.com/oauth2.0/token spring.security.oauth2.client.provider.naver.userInfoUri=https://openapi.naver.com/v1/nid/me spring.security.oauth2.client.provider.naver.userNameAttribute=response +# kakao spring.security.oauth2.client.provider.kakao.authorizationUri=https://kauth.kakao.com/oauth/authorize spring.security.oauth2.client.provider.kakao.tokenUri=https://kauth.kakao.com/oauth/token spring.security.oauth2.client.provider.kakao.userInfoUri=https://kapi.kakao.com/v2/user/me spring.security.oauth2.client.provider.kakao.userNameAttribute=id - #S3 cloud.aws.region.static=ap-northeast-2 cloud.aws.credentials.access-key=AKIA6F6Q3HYAFQWJW5OB cloud.aws.credentials.secret-key=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 cloud.aws.s3.bucket=mykokoa - #swagger spring.mvc.pathmatch.matching-strategy=ant_path_matcher