-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Release] 리뷰미 v1.1.2 배포
- Loading branch information
Showing
34 changed files
with
1,572 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/reviewme/review/domain/abstraction/Answer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Inheritance; | ||
import jakarta.persistence.InheritanceType; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "answer") | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(of = "id") | ||
@Getter | ||
public abstract class Answer { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
protected Long id; | ||
|
||
@Column(name = "question_id", nullable = false) | ||
protected long questionId; | ||
|
||
@Column(name = "review_id", nullable = false, insertable = false, updatable = false) | ||
private long reviewId; | ||
} |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/reviewme/review/domain/abstraction/NewCheckboxAnswer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import reviewme.review.domain.exception.QuestionNotAnsweredException; | ||
|
||
@Entity | ||
@Table(name = "new_checkbox_answer") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(callSuper = true) | ||
@Getter | ||
public class NewCheckboxAnswer extends Answer { | ||
|
||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) | ||
@JoinColumn(name = "checkbox_answer_id", nullable = false, updatable = false) | ||
private List<NewCheckboxAnswerSelectedOption> selectedOptionIds; | ||
|
||
public NewCheckboxAnswer(long questionId, List<Long> selectedOptionIds) { | ||
validateSelectedOptionIds(questionId, selectedOptionIds); | ||
this.questionId = questionId; | ||
this.selectedOptionIds = selectedOptionIds.stream() | ||
.map(NewCheckboxAnswerSelectedOption::new) | ||
.toList(); | ||
} | ||
|
||
private void validateSelectedOptionIds(long questionId, List<Long> selectedOptionIds) { | ||
if (selectedOptionIds == null || selectedOptionIds.isEmpty()) { | ||
throw new QuestionNotAnsweredException(questionId); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/reviewme/review/domain/abstraction/NewCheckboxAnswerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface NewCheckboxAnswerRepository extends JpaRepository<NewCheckboxAnswer, Long> { | ||
} |
34 changes: 34 additions & 0 deletions
34
...end/src/main/java/reviewme/review/domain/abstraction/NewCheckboxAnswerSelectedOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "new_checkbox_answer_selected_option") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(of = "id") | ||
@Getter | ||
public class NewCheckboxAnswerSelectedOption { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "checkbox_answer_id", nullable = false, insertable = false, updatable = false) | ||
private long checkboxAnswerId; | ||
|
||
@Column(name = "selected_option_id", nullable = false) | ||
private long selectedOptionId; | ||
|
||
public NewCheckboxAnswerSelectedOption(long selectedOptionId) { | ||
this.selectedOptionId = selectedOptionId; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
backend/src/main/java/reviewme/review/domain/abstraction/NewReview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "new_review") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(of = "id") | ||
@Getter | ||
public class NewReview { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "template_id", nullable = false) | ||
private long templateId; | ||
|
||
@Column(name = "review_group_id", nullable = false) | ||
private long reviewGroupId; | ||
|
||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST) | ||
@JoinColumn(name = "review_id", nullable = false, updatable = false) | ||
private List<Answer> answers; | ||
|
||
@Column(name = "created_at", nullable = false) | ||
private LocalDateTime createdAt; | ||
|
||
public NewReview(long templateId, long reviewGroupId, List<Answer> answers) { | ||
this.templateId = templateId; | ||
this.reviewGroupId = reviewGroupId; | ||
this.answers = answers; | ||
this.createdAt = LocalDateTime.now(); | ||
} | ||
|
||
public Set<Long> getAnsweredQuestionIds() { | ||
return answers.stream() | ||
.map(Answer::getQuestionId) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
public boolean hasAnsweredQuestion(long questionId) { | ||
return getAnsweredQuestionIds().contains(questionId); | ||
} | ||
|
||
public <T extends Answer> List<T> getAnswersByType(Class<T> clazz) { | ||
return answers.stream() | ||
.filter(clazz::isInstance) | ||
.map(clazz::cast) | ||
.toList(); | ||
} | ||
|
||
public LocalDate getCreatedDate() { | ||
return createdAt.toLocalDate(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/reviewme/review/domain/abstraction/NewReviewRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface NewReviewRepository extends JpaRepository<NewReview, Long> { | ||
|
||
@Query(value = """ | ||
SELECT r.* FROM new_review r | ||
WHERE r.review_group_id = :reviewGroupId | ||
ORDER BY r.created_at DESC | ||
""", nativeQuery = true) | ||
List<NewReview> findAllByGroupId(long reviewGroupId); | ||
|
||
@Query(value = """ | ||
SELECT r.* FROM new_review r | ||
WHERE r.review_group_id = :reviewGroupId | ||
AND (:lastReviewId IS NULL OR r.id < :lastReviewId) | ||
ORDER BY r.created_at DESC, r.id DESC | ||
LIMIT :limit | ||
""", nativeQuery = true) | ||
List<NewReview> findByReviewGroupIdWithLimit(long reviewGroupId, Long lastReviewId, int limit); | ||
|
||
Optional<NewReview> findByIdAndReviewGroupId(long reviewId, long reviewGroupId); | ||
|
||
@Query(value = """ | ||
SELECT COUNT(r.id) FROM new_review r | ||
WHERE r.review_group_id = :reviewGroupId | ||
AND r.id < :reviewId | ||
AND CAST(r.created_at AS DATE) <= :createdDate | ||
""", nativeQuery = true) | ||
Long existsOlderReviewInGroupInLong(long reviewGroupId, long reviewId, LocalDate createdDate); | ||
|
||
default boolean existsOlderReviewInGroup(long reviewGroupId, long reviewId, LocalDate createdDate) { | ||
return existsOlderReviewInGroupInLong(reviewGroupId, reviewId, createdDate) > 0; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/reviewme/review/domain/abstraction/NewTextAnswer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import reviewme.review.domain.exception.QuestionNotAnsweredException; | ||
|
||
@Entity | ||
@Table(name = "new_text_answer") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(callSuper = true) | ||
@Getter | ||
public class NewTextAnswer extends Answer { | ||
|
||
@Column(name = "content", nullable = false, length = 5000) | ||
private String content; | ||
|
||
public NewTextAnswer(long questionId, String content) { | ||
validateContent(questionId, content); | ||
this.questionId = questionId; | ||
this.content = content; | ||
} | ||
|
||
private void validateContent(long questionId, String content) { | ||
if (content == null || content.isEmpty()) { | ||
throw new QuestionNotAnsweredException(questionId); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/reviewme/review/domain/abstraction/NewTextAnswerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package reviewme.review.domain.abstraction; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface NewTextAnswerRepository extends JpaRepository<NewTextAnswer, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/reviewme/review/service/abstraction/mapper/AnswerMapperFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package reviewme.review.service.abstraction.mapper; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import reviewme.question.domain.QuestionType; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AnswerMapperFactory { | ||
|
||
private final List<NewAnswerMapper> answerMappers; | ||
|
||
public NewAnswerMapper getAnswerMapper(QuestionType questionType) { | ||
return answerMappers.stream() | ||
.filter(answerMapper -> answerMapper.supports(questionType)) | ||
.findFirst() | ||
.orElseThrow(() -> new UnsupportedQuestionTypeException(questionType)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/reviewme/review/service/abstraction/mapper/NewAnswerMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package reviewme.review.service.abstraction.mapper; | ||
|
||
import reviewme.question.domain.QuestionType; | ||
import reviewme.review.domain.abstraction.Answer; | ||
import reviewme.review.service.dto.request.ReviewAnswerRequest; | ||
|
||
public interface NewAnswerMapper { | ||
|
||
boolean supports(QuestionType questionType); | ||
|
||
Answer mapToAnswer(ReviewAnswerRequest answerRequest); | ||
} |
24 changes: 24 additions & 0 deletions
24
...end/src/main/java/reviewme/review/service/abstraction/mapper/NewCheckboxAnswerMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package reviewme.review.service.abstraction.mapper; | ||
|
||
import org.springframework.stereotype.Component; | ||
import reviewme.question.domain.QuestionType; | ||
import reviewme.review.domain.abstraction.NewCheckboxAnswer; | ||
import reviewme.review.service.dto.request.ReviewAnswerRequest; | ||
import reviewme.review.service.exception.CheckBoxAnswerIncludedTextException; | ||
|
||
@Component | ||
public class NewCheckboxAnswerMapper implements NewAnswerMapper { | ||
|
||
@Override | ||
public boolean supports(QuestionType questionType) { | ||
return questionType == QuestionType.CHECKBOX; | ||
} | ||
|
||
@Override | ||
public NewCheckboxAnswer mapToAnswer(ReviewAnswerRequest answerRequest) { | ||
if (answerRequest.text() != null) { | ||
throw new CheckBoxAnswerIncludedTextException(answerRequest.questionId()); | ||
} | ||
return new NewCheckboxAnswer(answerRequest.questionId(), answerRequest.selectedOptionIds()); | ||
} | ||
} |
Oops, something went wrong.