-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] feat: 리뷰어 그룹 도메인 구체화, 정책 구현 #45
Changes from all commits
d84a1c6
1791df9
ad15c64
7c4f7db
ca454df
7201ff0
e016c8e
c4c481e
e8b13f8
0fa761d
62f5287
1e71db6
26ec62c
6a91069
9e7001d
d221ebe
fa6df80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package reviewme.global.exception; | ||
|
||
public abstract class UnAuthorizedException extends ReviewMeException { | ||
|
||
protected UnAuthorizedException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package reviewme.member.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "github_reviewer_group") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class GithubReviewerGroup { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "github_id", nullable = false) | ||
private String githubId; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "reviewer_group_id") | ||
private ReviewerGroup reviewerGroup; | ||
|
||
public GithubReviewerGroup(String githubId, ReviewerGroup reviewerGroup) { | ||
this.githubId = githubId; | ||
this.reviewerGroup = reviewerGroup; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package reviewme.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import reviewme.member.domain.GithubReviewerGroup; | ||
import reviewme.member.domain.ReviewerGroup; | ||
|
||
@Repository | ||
public interface GithubReviewerGroupRepository extends JpaRepository<GithubReviewerGroup, Long> { | ||
|
||
boolean existsByGithubIdAndReviewerGroup(String githubId, ReviewerGroup reviewerGroup); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
|
@@ -24,7 +23,7 @@ public class Review { | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@OneToOne | ||
@ManyToOne | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍👍👍👍 |
||
@JoinColumn(name = "reviewer_id", nullable = false) | ||
private Member reviewer; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package reviewme.review.exception; | ||
|
||
import reviewme.global.exception.UnAuthorizedException; | ||
|
||
public class GithubReviewerGroupUnAuthorizedException extends UnAuthorizedException { | ||
|
||
public GithubReviewerGroupUnAuthorizedException() { | ||
super("리뷰어 그룹에 등록되지 않은 github 사용자입니다."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package reviewme.review.exception; | ||
|
||
import reviewme.global.exception.BadRequestException; | ||
|
||
public class ReviewAlreadySubmittedException extends BadRequestException { | ||
|
||
public ReviewAlreadySubmittedException() { | ||
super("이미 리뷰를 작성한 경우 리뷰를 작성할 수 없습니다."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,20 @@ | |
import org.springframework.beans.factory.annotation.Autowired; | ||
import reviewme.keyword.domain.Keyword; | ||
import reviewme.keyword.repository.KeywordRepository; | ||
import reviewme.member.domain.GithubReviewerGroup; | ||
import reviewme.member.domain.Member; | ||
import reviewme.member.domain.ReviewerGroup; | ||
import reviewme.member.repository.GithubReviewerGroupRepository; | ||
import reviewme.member.repository.MemberRepository; | ||
import reviewme.member.repository.ReviewerGroupRepository; | ||
import reviewme.review.domain.Review; | ||
import reviewme.review.domain.exception.DeadlineExpiredException; | ||
import reviewme.review.dto.request.CreateReviewContentRequest; | ||
import reviewme.review.dto.request.CreateReviewRequest; | ||
import reviewme.review.dto.response.ReviewResponse; | ||
import reviewme.review.exception.GithubReviewerGroupUnAuthorizedException; | ||
import reviewme.review.exception.ReviewAlreadySubmittedException; | ||
import reviewme.review.repository.ReviewContentRepository; | ||
import reviewme.review.repository.ReviewRepository; | ||
import reviewme.review.service.ReviewService; | ||
import reviewme.support.ServiceTest; | ||
|
@@ -37,17 +42,24 @@ class ReviewServiceTest { | |
@Autowired | ||
ReviewerGroupRepository reviewerGroupRepository; | ||
|
||
@Autowired | ||
GithubReviewerGroupRepository githubReviewerGroupRepository; | ||
|
||
@Autowired | ||
KeywordRepository keywordRepository; | ||
|
||
@Autowired | ||
ReviewContentRepository reviewContentRepository; | ||
|
||
@Test | ||
void 리뷰를_작성한다() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 테스트 깨지는 것 같은데 확인해주세요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리뷰 작성 테스트 시, 깃헙 사용자 그룹 데이터 저장 부분을 추가하지 않았군요! 테스트 터지는 거 확인 꼭 하겠습니당..😂 |
||
// given | ||
memberRepository.save(new Member("산초")); | ||
Member reviewee = memberRepository.save(new Member("아루")); | ||
reviewerGroupRepository.save( | ||
new ReviewerGroup(reviewee, "그룹A", "그룹 설명", LocalDateTime.of(2099, 1, 1, 1, 1)) | ||
memberRepository.save(new Member("산초", "sancho")); | ||
Member reviewee = memberRepository.save(new Member("아루", "aru")); | ||
ReviewerGroup reviewerGroup = reviewerGroupRepository.save( | ||
new ReviewerGroup(reviewee, "그룹A", "그룹 설명", LocalDateTime.of(2024, 1, 1, 1, 1)) | ||
); | ||
githubReviewerGroupRepository.save(new GithubReviewerGroup("sancho", reviewerGroup)); | ||
Keyword keyword1 = keywordRepository.save(new Keyword("꼼꼼해요")); | ||
Keyword keyword2 = keywordRepository.save(new Keyword("친절해요")); | ||
|
||
|
@@ -75,9 +87,9 @@ class ReviewServiceTest { | |
@Test | ||
void 리뷰를_조회한다() { | ||
// given | ||
Member reviewer = memberRepository.save(new Member("테드")); | ||
Member reviewee = memberRepository.save(new Member("아루")); | ||
memberRepository.save(new Member("산초")); | ||
Member reviewer = memberRepository.save(new Member("테드", "ted")); | ||
Member reviewee = memberRepository.save(new Member("아루", "aru")); | ||
memberRepository.save(new Member("산초", "sancho")); | ||
ReviewerGroup reviewerGroup = reviewerGroupRepository.save(new ReviewerGroup( | ||
reviewee, | ||
"그룹A", | ||
|
@@ -95,6 +107,57 @@ class ReviewServiceTest { | |
} | ||
|
||
@Test | ||
void 리뷰어_그룹에_속하지_않는_리뷰어가_리뷰를_작성할_경우_예외를_발생한다() { | ||
// given | ||
Member reviewee = memberRepository.save(new Member("아루", "aru")); | ||
Member reviewer = memberRepository.save(new Member("테드", "ted")); | ||
ReviewerGroup reviewerGroup = reviewerGroupRepository.save(new ReviewerGroup( | ||
reviewee, | ||
"그룹A", | ||
"그룹 설명", | ||
LocalDateTime.of(2024, 1, 1, 1, 1)) | ||
); | ||
githubReviewerGroupRepository.save(new GithubReviewerGroup("kirby", reviewerGroup)); | ||
|
||
CreateReviewRequest createReviewRequest = new CreateReviewRequest( | ||
reviewer.getId(), | ||
reviewerGroup.getId(), | ||
List.of(), | ||
List.of() | ||
); | ||
|
||
// when, then | ||
assertThatThrownBy(() -> reviewService.createReview(createReviewRequest)) | ||
.isInstanceOf(GithubReviewerGroupUnAuthorizedException.class); | ||
} | ||
|
||
@Test | ||
void 이미_작성한_리뷰가_있는데_리뷰를_작성할_경우_예외를_발생한다() { | ||
// given | ||
Member reviewee = memberRepository.save(new Member("아루", "aru")); | ||
Member reviewer = memberRepository.save(new Member("테드", "ted")); | ||
ReviewerGroup reviewerGroup = reviewerGroupRepository.save(new ReviewerGroup( | ||
reviewee, | ||
"그룹A", | ||
"그룹 설명", | ||
LocalDateTime.of(2024, 1, 1, 1, 1)) | ||
); | ||
githubReviewerGroupRepository.save(new GithubReviewerGroup("ted", reviewerGroup)); | ||
|
||
CreateReviewRequest createReviewRequest = new CreateReviewRequest( | ||
reviewer.getId(), | ||
reviewerGroup.getId(), | ||
List.of(), | ||
List.of() | ||
); | ||
|
||
reviewRepository.save(new Review(reviewer, reviewerGroup)); | ||
|
||
// when, then | ||
assertThatThrownBy(() -> reviewService.createReview(createReviewRequest)) | ||
.isInstanceOf(ReviewAlreadySubmittedException.class); | ||
} | ||
|
||
void 데드라인이_지난_리뷰그룹에_대해_리뷰를_작성하려하면_예외가_발생한다() { | ||
// given | ||
memberRepository.save(new Member("산초")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것은 TODO 일수도 있지만 이 부분도 나중에 깃허브 연동하면
github_nickname 요런식으로 바뀌어야 하겠군요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용자의 프로필을 아예 깃헙과 연동으로 처리한다면 그렇겠네요!
어떤 방법이 나을지 함께 얘기해보면 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
산초의 코멘트에 대한 의견 : 깃허브 아이디랑 닉네임이 똑같지 않나요? 그럼 둘 중 하나만 있어도 될 것 같은데, 실명 정보가 따로 필요할까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제 기준 skylar1220이라는 것은 깃헙 기준 username이고 숫자로 된 unique한 id가 따로 있군요!(by 아루)
그렇다면 githubId, githubUserName을 갖게 하는 게 맞겠네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞습니다! 저도 github_nickname 은 nayonsoso 인데, 고유한 id 는 1330909287 요런식이었어요