diff --git a/src/main/java/com/gaaji/auth/applicationservice/ReviewCreateServiceImpl.java b/src/main/java/com/gaaji/auth/applicationservice/ReviewCreateServiceImpl.java index 020685b..7f392a6 100644 --- a/src/main/java/com/gaaji/auth/applicationservice/ReviewCreateServiceImpl.java +++ b/src/main/java/com/gaaji/auth/applicationservice/ReviewCreateServiceImpl.java @@ -19,6 +19,7 @@ import com.gaaji.auth.exception.EqualsSellerAndPurchaserException; import com.gaaji.auth.exception.NoMatchIdException; import com.gaaji.auth.exception.NoReviewException; +import com.gaaji.auth.exception.NoTownException; import com.gaaji.auth.exception.NonexistentTargetException; import com.gaaji.auth.repository.ReviewRepository; @@ -42,6 +43,10 @@ private void saveEntity(Review review) { } private Review createReviewEntity(ReviewCreateRequest dto, MultipartFile multipartFile, String authId) { + if(dto.getTown() == null) { + throw new NoTownException(); + } + if((dto.getPurchaserId() == null) || dto.getSellerId() == null) { throw new NonexistentTargetException(); } @@ -60,12 +65,12 @@ private Review createReviewEntity(ReviewCreateRequest dto, MultipartFile multipa if (dto.getPurchaserId().equals(authId)) { return Review.of(ReviewId.of(this.reviewRepository.nextId()), PostId.of(dto.getPostId()), AuthId.of(authId), AuthId.of(dto.getSellerId()), goodManners, badManners, - Comment.of(pictureUrl, dto.getContents(), true)); + Comment.of(pictureUrl, dto.getContents(), dto.getTown(), true)); } else if (dto.getSellerId().equals(authId)) { return Review.of(ReviewId.of(this.reviewRepository.nextId()), PostId.of(dto.getPostId()), AuthId.of(authId), AuthId.of(dto.getPurchaserId()), goodManners, badManners, - Comment.of(pictureUrl, dto.getContents(), false)); + Comment.of(pictureUrl, dto.getContents(), dto.getTown(), false)); } else { throw new NoMatchIdException(); } diff --git a/src/main/java/com/gaaji/auth/controller/dto/ReviewCreateRequest.java b/src/main/java/com/gaaji/auth/controller/dto/ReviewCreateRequest.java index b5ec64f..11c6134 100644 --- a/src/main/java/com/gaaji/auth/controller/dto/ReviewCreateRequest.java +++ b/src/main/java/com/gaaji/auth/controller/dto/ReviewCreateRequest.java @@ -17,6 +17,7 @@ public class ReviewCreateRequest { private String postId; private String sellerId; private String purchaserId; + private String town; private List goodManners; private List badManners; private String contents; diff --git a/src/main/java/com/gaaji/auth/domain/Comment.java b/src/main/java/com/gaaji/auth/domain/Comment.java index 86702f7..8cc5c20 100644 --- a/src/main/java/com/gaaji/auth/domain/Comment.java +++ b/src/main/java/com/gaaji/auth/domain/Comment.java @@ -15,18 +15,20 @@ public class Comment { private String pictureUrl; private String contents; + private String town; private boolean ispurchaser; private LocalDateTime createdAt; - public Comment(String pictureUrl, String contents, boolean ispurchaser) { + public Comment(String pictureUrl, String contents, String town, boolean ispurchaser) { this.pictureUrl = pictureUrl; this.contents = contents; this.ispurchaser = ispurchaser; + this.town = town; this.createdAt = LocalDateTime.now(); } - public static Comment of(String pictureUrl, String contents, boolean ispurchaser) { - return new Comment(pictureUrl, contents, ispurchaser); + public static Comment of(String pictureUrl, String contents, String town, boolean ispurchaser) { + return new Comment(pictureUrl, contents, town, ispurchaser); } diff --git a/src/main/java/com/gaaji/auth/domain/Review.java b/src/main/java/com/gaaji/auth/domain/Review.java index f68a355..0d55140 100644 --- a/src/main/java/com/gaaji/auth/domain/Review.java +++ b/src/main/java/com/gaaji/auth/domain/Review.java @@ -62,7 +62,7 @@ public static Review of(ReviewId reviewId, PostId postId, AuthId senderId, AuthI public void modify(String pictureUrl, List goodManners, List badManners, String contents) { this.goodManners = goodManners; this.badManners = badManners; - this.comment = Comment.of(pictureUrl, contents, this.comment.isIspurchaser()); + this.comment = Comment.of(pictureUrl, contents, this.comment.getTown(), this.comment.isIspurchaser()); } diff --git a/src/main/java/com/gaaji/auth/exception/AuthErrorCode.java b/src/main/java/com/gaaji/auth/exception/AuthErrorCode.java index 2469223..d7109fd 100644 --- a/src/main/java/com/gaaji/auth/exception/AuthErrorCode.java +++ b/src/main/java/com/gaaji/auth/exception/AuthErrorCode.java @@ -18,6 +18,7 @@ public enum AuthErrorCode implements ErrorCode{ Equals_Seller_And_Purchaser(HttpStatus.BAD_REQUEST, "r-0006","판매자와 구매자가 동일합니다."), No_Search_Review(HttpStatus.BAD_REQUEST, "r-0007","해당 후기를 찾지 못했습니다."), No_Match_Sender(HttpStatus.BAD_REQUEST, "r-0008","해당 후기 작성자와 정보가 맞지 않습니다."), + No_Town(HttpStatus.BAD_REQUEST, "r-0009","해당 지역을 알 수 없습니다."), ; private final HttpStatus httpStatus; diff --git a/src/main/java/com/gaaji/auth/exception/NoTownException.java b/src/main/java/com/gaaji/auth/exception/NoTownException.java new file mode 100644 index 0000000..faa2f5f --- /dev/null +++ b/src/main/java/com/gaaji/auth/exception/NoTownException.java @@ -0,0 +1,11 @@ +package com.gaaji.auth.exception; + +import static com.gaaji.auth.exception.AuthErrorCode.No_Town; + +public class NoTownException extends AbstractApiException { + + public NoTownException() { + super(No_Town); + } + +} \ No newline at end of file diff --git a/src/test/java/com/gaaji/auth/repository/ReviewCreateJpaTest.java b/src/test/java/com/gaaji/auth/repository/ReviewCreateJpaTest.java index a28d298..dd86a71 100644 --- a/src/test/java/com/gaaji/auth/repository/ReviewCreateJpaTest.java +++ b/src/test/java/com/gaaji/auth/repository/ReviewCreateJpaTest.java @@ -36,7 +36,7 @@ void afterEach() { good.add(GoodManner.gm1); List bad = new ArrayList(); bad.add(BadManner.bm2); - Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", true)); + Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true)); this.jpaReviewRepository.save(review); @@ -51,6 +51,7 @@ void afterEach() { assertThat(newReview.getComment().getPictureUrl()).isEqualTo("사진"); assertThat(newReview.getComment().getContents()).isEqualTo("내용"); + assertThat(newReview.getComment().getTown()).isEqualTo("남가좌동"); assertThat(newReview.getComment().isIspurchaser()).isEqualTo(true); } diff --git a/src/test/java/com/gaaji/auth/repository/ReviewRetriveJpaTest.java b/src/test/java/com/gaaji/auth/repository/ReviewRetriveJpaTest.java index f10448d..138420e 100644 --- a/src/test/java/com/gaaji/auth/repository/ReviewRetriveJpaTest.java +++ b/src/test/java/com/gaaji/auth/repository/ReviewRetriveJpaTest.java @@ -37,7 +37,7 @@ void afterEach() { good.add(GoodManner.gm1); List bad = new ArrayList(); bad.add(BadManner.bm2); - Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", true)); + Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true)); this.jpaReviewRepository.save(review); @@ -52,6 +52,7 @@ void afterEach() { assertThat(newReview.getComment().getPictureUrl()).isEqualTo("사진"); assertThat(newReview.getComment().getContents()).isEqualTo("내용"); + assertThat(newReview.getComment().getTown()).isEqualTo("남가좌동"); assertThat(newReview.getComment().isIspurchaser()).isEqualTo(true); } diff --git a/src/test/java/com/gaaji/auth/service/ReviewCreateServiceTest.java b/src/test/java/com/gaaji/auth/service/ReviewCreateServiceTest.java index 44f6c27..ba1da4b 100644 --- a/src/test/java/com/gaaji/auth/service/ReviewCreateServiceTest.java +++ b/src/test/java/com/gaaji/auth/service/ReviewCreateServiceTest.java @@ -25,6 +25,7 @@ import com.gaaji.auth.exception.NoMatchIdException; import com.gaaji.auth.exception.NoReviewException; import com.gaaji.auth.exception.NoSearchReviewException; +import com.gaaji.auth.exception.NoTownException; import com.gaaji.auth.exception.NonexistentTargetException; import com.gaaji.auth.repository.JpaReviewRepository; @@ -53,8 +54,8 @@ void afterEach() { bad.add("bm3"); bad.add("bm4"); - ReviewCreateRequest dto1 = new ReviewCreateRequest("post", "aaa", "purchaser", no, no, "빨라요"); - ReviewCreateRequest dto2 = new ReviewCreateRequest("post1", "seller", "aaa", good, bad, null); + ReviewCreateRequest dto1 = new ReviewCreateRequest("post", "aaa", "purchaser", "남가좌동", no, no, "빨라요"); + ReviewCreateRequest dto2 = new ReviewCreateRequest("post1", "seller", "aaa", "남가좌동", good, bad, null); reviewCreateService.createReview("aaa", null, dto1); @@ -72,6 +73,7 @@ void afterEach() { assertThat(newReview.getComment().getPictureUrl()).isEqualTo(null); assertThat(newReview.getComment().getContents()).isEqualTo("빨라요"); + assertThat(newReview.getComment().getTown()).isEqualTo("남가좌동"); assertThat(newReview.getComment().isIspurchaser()).isEqualTo(false); Review newReview1 = this.jpaReviewRepository.findByPostIdAndSenderId(PostId.of("post1"), AuthId.of("aaa")).orElseThrow(NoSearchReviewException::new); @@ -85,20 +87,28 @@ void afterEach() { assertThat(newReview1.getBadManners().get(1)).isEqualTo(BadManner.bm4); assertThat(newReview1.getComment().getPictureUrl()).isEqualTo(null); assertThat(newReview1.getComment().getContents()).isEqualTo(null); + assertThat(newReview.getComment().getTown()).isEqualTo("남가좌동"); assertThat(newReview1.getComment().isIspurchaser()).isEqualTo(true); } + @Test + void 추가서비스에러케이스5타운이없는경우 (){ + List no = new ArrayList(); + ReviewCreateRequest dto = new ReviewCreateRequest("post", "purchaser", "purchaser", null, no, no, "123"); + assertThatThrownBy(()->reviewCreateService.createReview("aaa", null, dto)).isInstanceOf(NoTownException.class); + } + @Test void 추가서비스에러케이스4판매자와구매자가같은경우 (){ List no = new ArrayList(); - ReviewCreateRequest dto = new ReviewCreateRequest("post", "purchaser", "purchaser", no, no, "123"); + ReviewCreateRequest dto = new ReviewCreateRequest("post", "purchaser", "purchaser", "남가좌동", no, no, "123"); assertThatThrownBy(()->reviewCreateService.createReview("aaa", null, dto)).isInstanceOf(EqualsSellerAndPurchaserException.class); } @Test void 추가서비스에러케이스3후기작성자가구매자와판매자가아닌경우 (){ List no = new ArrayList(); - ReviewCreateRequest dto = new ReviewCreateRequest("post", "seller", "purchaser", no, no, "123"); + ReviewCreateRequest dto = new ReviewCreateRequest("post", "seller", "purchaser", "남가좌동", no, no, "123"); assertThatThrownBy(()->reviewCreateService.createReview("aaa", null, dto)).isInstanceOf(NoMatchIdException.class); } @@ -106,7 +116,7 @@ void afterEach() { @Test void 추가서비스에러케이스2후기가없는경우 (){ List no = new ArrayList(); - ReviewCreateRequest dto = new ReviewCreateRequest("post", "aaa", "purchaser", no, no, null); + ReviewCreateRequest dto = new ReviewCreateRequest("post", "aaa", "purchaser", "남가좌동", no, no, null); assertThatThrownBy(()->reviewCreateService.createReview("aaa", null, dto)).isInstanceOf(NoReviewException.class); } @@ -114,7 +124,7 @@ void afterEach() { @Test void 추가서비스에러케이스1글과관련된아이디없는경우 (){ List no = new ArrayList(); - ReviewCreateRequest dto = new ReviewCreateRequest("aaa", null, null, no, no, "123"); + ReviewCreateRequest dto = new ReviewCreateRequest("aaa", null, null, "남가좌동", no, no, "123"); assertThatThrownBy(()->reviewCreateService.createReview("aaa", null, dto)).isInstanceOf(NonexistentTargetException.class); } diff --git a/src/test/java/com/gaaji/auth/service/ReviewRetriveServiceTest.java b/src/test/java/com/gaaji/auth/service/ReviewRetriveServiceTest.java index a450136..bb06339 100644 --- a/src/test/java/com/gaaji/auth/service/ReviewRetriveServiceTest.java +++ b/src/test/java/com/gaaji/auth/service/ReviewRetriveServiceTest.java @@ -49,7 +49,7 @@ void afterEach() { good.add(GoodManner.gm1); List bad = new ArrayList(); bad.add(BadManner.bm2); - Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", true)); + Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true)); this.jpaReviewRepository.save(review); diff --git a/src/test/java/com/gaaji/auth/service/ReviewUpdateServiceTest.java b/src/test/java/com/gaaji/auth/service/ReviewUpdateServiceTest.java index fbac74e..3820e11 100644 --- a/src/test/java/com/gaaji/auth/service/ReviewUpdateServiceTest.java +++ b/src/test/java/com/gaaji/auth/service/ReviewUpdateServiceTest.java @@ -47,7 +47,7 @@ void afterEach() { good.add(GoodManner.gm1); List bad = new ArrayList(); bad.add(BadManner.bm2); - Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", true)); + Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true)); this.jpaReviewRepository.save(review); @@ -74,6 +74,7 @@ void afterEach() { assertThat(newReview.getComment().getPictureUrl()).isEqualTo("사진"); assertThat(newReview.getComment().getContents()).isEqualTo("수정"); + assertThat(newReview.getComment().getTown()).isEqualTo("남가좌동"); assertThat(newReview.getComment().isIspurchaser()).isEqualTo(true); } @@ -84,7 +85,7 @@ void afterEach() { good.add(GoodManner.gm1); List bad = new ArrayList(); bad.add(BadManner.bm2); - Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", true)); + Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true)); this.jpaReviewRepository.save(review); @@ -104,7 +105,7 @@ void afterEach() { good.add(GoodManner.gm1); List bad = new ArrayList(); bad.add(BadManner.bm2); - Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", true)); + Review review = Review.of(ReviewId.of("review"), PostId.of("post"), AuthId.of("sender"), AuthId.of("receiver"), good, bad, Comment.of("사진", "내용", "남가좌동", true)); this.jpaReviewRepository.save(review);