Skip to content

Commit

Permalink
#12 [update]
Browse files Browse the repository at this point in the history
리뷰 조회 사용자프로필 조회, 본인 리뷰 구분 구현
  • Loading branch information
kokoa322 committed Jul 27, 2022
1 parent cc91ab2 commit 24cd227
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public class ReviewController {
private final ReviewService reviewService;

@GetMapping("/review/{storeId}")
public ResponseEntity<List<ReviewResponseDto>> getStoreReview(@PathVariable int storeId
public ResponseEntity<List<ReviewResponseDto>> getStoreReview(@PathVariable int storeId,
@AuthenticationPrincipal User user
//@PageableDefault(page = 0, size = 10, sort = "id", direction = Sort.Direction.DESC) Pageable pageable
) {
List<ReviewResponseDto> reviewList = reviewService.getReview(storeId);
List<ReviewResponseDto> reviewList = reviewService.getReview(storeId, user.getUsername());
return new ResponseEntity<>(reviewList, HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Builder
public class ReviewRequestDto {
//review 테이블 컬럼
private long storeId; //업장 아이디
private long storeId; //업장 아이디
private String content; //리뷰 코멘트
private double point; //별점
private List<String> tagList; //태그
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Builder
Expand All @@ -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<ReviewImageResponseDto> reviewImageUrlList;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReviewImage, Integer> {
void deleteAllByReviewId(Review review);
void deleteByReviewId(Review review);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

public interface ReviewRepository extends JpaRepository<Review, Integer> {
List<Review> findAllByStoreId(Store store);

}
23 changes: 19 additions & 4 deletions src/main/java/com/mpnp/baechelin/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,24 @@ public void review(ReviewRequestDto reviewRequestDto, String socialId) throws IO



public List<ReviewResponseDto> getReview(long storeId) {
public List<ReviewResponseDto> 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<Review> reviewList = reviewRepository.findAllByStoreId(store);
List<ReviewResponseDto> reviewResponseDtoList = new ArrayList<>();
User myUser = userRepository.findBySocialId(socialId);

for(Review review: reviewList){
ReviewResponseDto reviewResponseDto = new ReviewResponseDto(review);
Optional<User> 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());
}


Expand All @@ -97,7 +111,7 @@ public List<ReviewResponseDto> 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("해당하는 리뷰가 없습니다."));
Expand All @@ -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);
}

Expand Down
23 changes: 14 additions & 9 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 24cd227

Please sign in to comment.