Skip to content

Commit

Permalink
Merge pull request #32 from gaaji/GM-253
Browse files Browse the repository at this point in the history
Gm 253
  • Loading branch information
ansm6358 authored Feb 27, 2023
2 parents eebafe9 + db176cd commit 2084f2c
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

import com.gaaji.auth.controller.dto.CommentRetrieveResponse;
import com.gaaji.auth.controller.dto.MannerRetrieveResponse;
import com.gaaji.auth.controller.dto.PreviewReviewRetrieveResponse;
import com.gaaji.auth.controller.dto.ReviewRetrieveResponse;

public interface ReviewRetriveService {

ReviewRetrieveResponse retriveMyReview(String authId, String postId);

List<CommentRetrieveResponse> retriveComment(String authId);
List<CommentRetrieveResponse> retriveComment(String userId);

MannerRetrieveResponse retriveManner(String authId, String userId);

PreviewReviewRetrieveResponse retriveReview(String userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.springframework.transaction.annotation.Transactional;

import com.gaaji.auth.controller.dto.BadMannerCount;
import com.gaaji.auth.controller.dto.CommentInfo;
import com.gaaji.auth.controller.dto.CommentRetrieveResponse;
import com.gaaji.auth.controller.dto.GoodMannerCount;
import com.gaaji.auth.controller.dto.MannerRetrieveResponse;
import com.gaaji.auth.controller.dto.PreviewReviewRetrieveResponse;
import com.gaaji.auth.controller.dto.ReviewRetrieveResponse;
import com.gaaji.auth.domain.Auth;
import com.gaaji.auth.domain.AuthId;
Expand Down Expand Up @@ -42,8 +44,8 @@ public ReviewRetrieveResponse retriveMyReview(String authId, String postId) {
}

@Override
public List<CommentRetrieveResponse> retriveComment(String authId) {
List<Review> reviewList = this.reviewRepository.findByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(AuthId.of(authId));
public List<CommentRetrieveResponse> retriveComment(String userId) {
List<Review> reviewList = this.reviewRepository.findByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(AuthId.of(userId));
List<CommentRetrieveResponse> commentList = new ArrayList<CommentRetrieveResponse>();
for(Review review : reviewList) {

Expand Down Expand Up @@ -81,8 +83,6 @@ private List<GoodMannerCount> getGoodMannerCount(String userId) {
}

for(Review review : reviewList) {
System.out.println(reviewList.size());
System.out.println(review.getReviewId().getId());
goodManners.addAll(review.getGoodManners());
}

Expand All @@ -107,8 +107,6 @@ private List<BadMannerCount> getBadMannerCount(String userId) {
}

for(Review review : reviewList) {
System.out.println(reviewList.size());
System.out.println(review.getReviewId().getId());
badManners.addAll(review.getBadManners());
}

Expand All @@ -123,5 +121,28 @@ private List<BadMannerCount> getBadMannerCount(String userId) {
return badMannerCountList;
}

@Override
public PreviewReviewRetrieveResponse retriveReview(String userId) {

List<Review> reviewList = this.reviewRepository.findTop3ByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(AuthId.of(userId));
List<CommentInfo> commentInfoList = new ArrayList<CommentInfo>();
for(Review review : reviewList) {

Auth auth = this.authRepository.findById(review.getSenderId().getId()).orElse(Auth.signUp(null, null, null));
if(auth.getAuthIdForToken()==null) {
auth.registerNickname(null);
}
commentInfoList.add(CommentInfo.of(review.getSenderId().getId(), auth.getNickname(), auth.getProfilePictureUrl(), review.getComment().getTown(), review.getComment().getContents(), review.getComment().getPictureUrl(), review.getComment().isIspurchaser(), review.getComment().getCreatedAt()));

}
List<GoodMannerCount> goodMannerCount= getGoodMannerCount(userId);
if(goodMannerCount.size() > 3) {
goodMannerCount.subList(3, goodMannerCount.size()).clear();
}


return PreviewReviewRetrieveResponse.of(commentInfoList, goodMannerCount);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.gaaji.auth.applicationservice.ReviewRetriveService;
import com.gaaji.auth.controller.dto.CommentRetrieveResponse;
import com.gaaji.auth.controller.dto.MannerRetrieveResponse;
import com.gaaji.auth.controller.dto.PreviewReviewRetrieveResponse;
import com.gaaji.auth.controller.dto.ReviewRetrieveResponse;
import com.gaaji.auth.domain.Review;

Expand All @@ -32,8 +33,8 @@ private ResponseEntity<ReviewRetrieveResponse> retriveMyReview(@RequestHeader(Ht
}

@GetMapping("/comment")
private ResponseEntity<List<CommentRetrieveResponse>> retriveComments(@RequestHeader(HttpHeaders.AUTHORIZATION) String authId, @RequestBody String postId) {
List<CommentRetrieveResponse> dto = this.reviewRetriveService.retriveComment(authId);
private ResponseEntity<List<CommentRetrieveResponse>> retriveComments(@RequestHeader(HttpHeaders.AUTHORIZATION) String authId, @RequestBody String userId) {
List<CommentRetrieveResponse> dto = this.reviewRetriveService.retriveComment(userId);
return ResponseEntity.ok(dto);
}

Expand All @@ -42,4 +43,10 @@ private ResponseEntity<MannerRetrieveResponse> retriveManner(@RequestHeader(Http
MannerRetrieveResponse dto = this.reviewRetriveService.retriveManner(authId, userId);
return ResponseEntity.ok(dto);
}

@GetMapping
private ResponseEntity<PreviewReviewRetrieveResponse> retriveReview(@RequestHeader(HttpHeaders.AUTHORIZATION) String authId, @RequestBody String userId) {
PreviewReviewRetrieveResponse dto = this.reviewRetriveService.retriveReview(userId);
return ResponseEntity.ok(dto);
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/gaaji/auth/controller/dto/CommentInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gaaji.auth.controller.dto;

import java.time.LocalDateTime;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
public class CommentInfo {

private String senderId;
private String nickname;
private String profilePictureUrl;
private String town;
private String contents;
private String pictureUrl;
private boolean ispurchaser;
private LocalDateTime createdAt;

public static CommentInfo of(String senderId, String nickname, String profilePictureUrl, String town, String contents, String pictureUrl, boolean ispurchaser, LocalDateTime createdAt) {
return new CommentInfo(senderId, nickname, profilePictureUrl, town, contents, pictureUrl, ispurchaser, createdAt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.gaaji.auth.controller.dto;

import java.util.List;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
public class PreviewReviewRetrieveResponse {

private List<CommentInfo> commentInfo;
private List<GoodMannerCount> goodMannerCount;

public static PreviewReviewRetrieveResponse of(List<CommentInfo> commentInfo,
List<GoodMannerCount> goodMannerCount) {
return new PreviewReviewRetrieveResponse(commentInfo, goodMannerCount);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface JpaReviewRepository extends JpaRepository<Review, ReviewId>{

List<Review> findDistinctByReceiverIdAndBadMannersNotNull(AuthId receiverId);

List<Review> findTop3ByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(AuthId receiverId);

}
2 changes: 2 additions & 0 deletions src/main/java/com/gaaji/auth/repository/ReviewRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ default String nextId(){

List<Review> findDistinctByReceiverIdAndBadMannersNotNull(AuthId receiverId);

List<Review> findTop3ByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(AuthId receiverId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public List<Review> findDistinctByReceiverIdAndBadMannersNotNull(AuthId receiver
return this.jpaReviewRepository.findDistinctByReceiverIdAndBadMannersNotNull(receiverId);
}

@Override
public List<Review> findTop3ByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(
AuthId receiverId) {
return this.jpaReviewRepository.findTop3ByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(receiverId);
}



}
24 changes: 24 additions & 0 deletions src/test/java/com/gaaji/auth/repository/ReviewRetriveJpaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,29 @@ void afterEach() {


}

@Test
void 후기3개조회테스트() {
List<GoodManner> good = new ArrayList<GoodManner>();
good.add(GoodManner.gm1);
List<BadManner> bad = new ArrayList<BadManner>();
bad.add(BadManner.bm2);
Review review1 = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true));

Review review2 = Review.of(ReviewId.of("review1"), PostId.of("post2"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진1", "내용2", "남가좌동", true));
Review review3 = Review.of(ReviewId.of("review2"), PostId.of("post3"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진2", "내용3", "남가좌동", true));

Review review = Review.of(ReviewId.of("review3"), PostId.of("post1"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진3", "내용1", "남가좌동", true));

this.jpaReviewRepository.save(review);
this.jpaReviewRepository.save(review1);
this.jpaReviewRepository.save(review2);
this.jpaReviewRepository.save(review3);

List<Review> reviewList = this.jpaReviewRepository.findTop3ByReceiverIdAndComment_ContentsIsNotNullOrderByComment_CreatedAtDesc(AuthId.of("receiver"));

assertThat(reviewList.size()).isEqualTo(3);

}

}
40 changes: 40 additions & 0 deletions src/test/java/com/gaaji/auth/service/ReviewRetriveServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.gaaji.auth.controller.dto.CommentRetrieveResponse;
import com.gaaji.auth.controller.dto.GoodMannerCount;
import com.gaaji.auth.controller.dto.MannerRetrieveResponse;
import com.gaaji.auth.controller.dto.PreviewReviewRetrieveResponse;
import com.gaaji.auth.controller.dto.ReviewRetrieveResponse;
import com.gaaji.auth.controller.dto.ReviewUpdateRequest;
import com.gaaji.auth.domain.Auth;
Expand Down Expand Up @@ -170,4 +171,43 @@ void afterEach() {
assertThat(badMannerCount.get(2).getCount()).isEqualTo(1);
}

@Test
void 후기3개조회서비스 (){
List<GoodManner> good = new ArrayList<GoodManner>();
good.add(GoodManner.gm1);
good.add(GoodManner.gm2);

List<BadManner> bad = new ArrayList<BadManner>();
bad.add(BadManner.bm2);
bad.add(BadManner.bm5);

List<GoodManner> good1 = new ArrayList<GoodManner>();
good1.add(GoodManner.gm1);
good1.add(GoodManner.gm3);
good1.add(GoodManner.gm4);


List<BadManner> bad1 = new ArrayList<BadManner>();
bad1.add(BadManner.bm2);
bad1.add(BadManner.bm3);
bad1.add(BadManner.bm5);

Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true));
Review review1 = Review.of(ReviewId.of("review1"), PostId.of("post1"), AuthId.of("sender"), AuthId.of("receiver"), good, bad1, Comment.of("사진", null, "남가좌동", true));
Review review2 = Review.of(ReviewId.of("review2"), PostId.of("post2"), AuthId.of("sender1"), AuthId.of("receiver"), good1, bad, Comment.of("사진", "내용1", "남가좌동", false));

this.jpaReviewRepository.save(review);
this.jpaReviewRepository.save(review1);
this.jpaReviewRepository.save(review2);


PreviewReviewRetrieveResponse reviewList = this.reviewRetriveService.retriveReview("receiver");

assertThat(reviewList.getGoodMannerCount().size()).isEqualTo(3);
assertThat(reviewList.getCommentInfo().size()).isEqualTo(2);




}
}

0 comments on commit 2084f2c

Please sign in to comment.