Skip to content

Commit

Permalink
도메인에 town도 같이 저장 하게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ansm6 committed Feb 21, 2023
1 parent 298665f commit 88a92e7
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ReviewCreateRequest {
private String postId;
private String sellerId;
private String purchaserId;
private String town;
private List<String> goodManners;
private List<String> badManners;
private String contents;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/gaaji/auth/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gaaji/auth/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Review of(ReviewId reviewId, PostId postId, AuthId senderId, AuthI
public void modify(String pictureUrl, List<GoodManner> goodManners, List<BadManner> 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());
}


Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/gaaji/auth/exception/AuthErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/gaaji/auth/exception/NoTownException.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void afterEach() {
good.add(GoodManner.gm1);
List<BadManner> bad = new ArrayList<BadManner>();
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);

Expand All @@ -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);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void afterEach() {
good.add(GoodManner.gm1);
List<BadManner> bad = new ArrayList<BadManner>();
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);

Expand All @@ -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);

}
Expand Down
22 changes: 16 additions & 6 deletions src/test/java/com/gaaji/auth/service/ReviewCreateServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -85,36 +87,44 @@ 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<String> no = new ArrayList<String>();
ReviewCreateRequest dto = new ReviewCreateRequest("post", "purchaser", "purchaser", null, no, no, "123");
assertThatThrownBy(()->reviewCreateService.createReview("aaa", null, dto)).isInstanceOf(NoTownException.class);
}

@Test
void 추가서비스에러케이스4판매자와구매자가같은경우 (){
List<String> no = new ArrayList<String>();
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<String> no = new ArrayList<String>();
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);
}

@Test
void 추가서비스에러케이스2후기가없는경우 (){
List<String> no = new ArrayList<String>();
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);
}

@Test
void 추가서비스에러케이스1글과관련된아이디없는경우 (){
List<String> no = new ArrayList<String>();
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void afterEach() {
good.add(GoodManner.gm1);
List<BadManner> bad = new ArrayList<BadManner>();
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void afterEach() {
good.add(GoodManner.gm1);
List<BadManner> bad = new ArrayList<BadManner>();
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);

Expand All @@ -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);

}
Expand All @@ -84,7 +85,7 @@ void afterEach() {
good.add(GoodManner.gm1);
List<BadManner> bad = new ArrayList<BadManner>();
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);

Expand All @@ -104,7 +105,7 @@ void afterEach() {
good.add(GoodManner.gm1);
List<BadManner> bad = new ArrayList<BadManner>();
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);

Expand Down

0 comments on commit 88a92e7

Please sign in to comment.