Skip to content

Commit

Permalink
[BE] Question 패키지를 Template 하위로 이동 (#956)
Browse files Browse the repository at this point in the history
* refactor: Question 도메인을 Template 아래로 이동

- 전체적인 경계를 아래와 같이 나눔:
1. 템플릿 (질문, 옵션, 섹션, 템플릿)
2. 리뷰 (답변)
3. 하이라이트
4. 리뷰 그룹

* refactor: TemplateService에서 리뷰 그룹 Repository 계층을 참조하지 않도록 수정
  • Loading branch information
donghoony authored Nov 5, 2024
1 parent 28ee86d commit cfdaeac
Show file tree
Hide file tree
Showing 53 changed files with 161 additions and 171 deletions.
16 changes: 8 additions & 8 deletions backend/src/main/java/reviewme/DatabaseInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import reviewme.question.domain.OptionGroup;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.OptionType;
import reviewme.question.domain.Question;
import reviewme.question.domain.QuestionType;
import reviewme.question.repository.OptionGroupRepository;
import reviewme.question.repository.OptionItemRepository;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.OptionGroup;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.OptionType;
import reviewme.template.domain.Question;
import reviewme.template.domain.QuestionType;
import reviewme.template.repository.OptionGroupRepository;
import reviewme.template.repository.OptionItemRepository;
import reviewme.template.repository.QuestionRepository;
import reviewme.template.domain.Section;
import reviewme.template.domain.Template;
import reviewme.template.domain.VisibleType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.springframework.transaction.annotation.Transactional;
import reviewme.highlight.domain.Highlight;
import reviewme.highlight.repository.HighlightRepository;
import reviewme.question.domain.Question;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.Question;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Answer;
import reviewme.review.repository.AnswerRepository;
import reviewme.review.service.dto.response.gathered.ReviewsGatheredBySectionResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package reviewme.review.service.dto.response.detail;

import jakarta.annotation.Nullable;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;

public record QuestionAnswerResponse(
long questionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package reviewme.review.service.dto.response.gathered;

import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;

public record SimpleQuestionResponse(
long id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package reviewme.review.service.mapper;

import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;
import reviewme.review.domain.Answer;
import reviewme.review.service.dto.request.ReviewAnswerRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;

@Component
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package reviewme.review.service.mapper;

import org.springframework.stereotype.Component;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;
import reviewme.review.domain.CheckboxAnswer;
import reviewme.review.service.dto.request.ReviewAnswerRequest;
import reviewme.review.service.exception.CheckBoxAnswerIncludedTextException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.OptionGroup;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.Question;
import reviewme.question.repository.OptionGroupRepository;
import reviewme.question.repository.OptionItemRepository;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.OptionGroup;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.Question;
import reviewme.template.repository.OptionGroupRepository;
import reviewme.template.repository.OptionItemRepository;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.CheckboxAnswer;
import reviewme.review.domain.CheckboxAnswerSelectedOption;
import reviewme.review.domain.Review;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.highlight.domain.Highlight;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.Question;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.Question;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Answer;
import reviewme.review.domain.CheckboxAnswer;
import reviewme.review.domain.CheckboxAnswerSelectedOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.OptionType;
import reviewme.question.repository.OptionItemRepository;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.OptionType;
import reviewme.template.repository.OptionItemRepository;
import reviewme.review.domain.CheckboxAnswer;
import reviewme.review.domain.CheckboxAnswerSelectedOption;
import reviewme.review.domain.Review;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.Question;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.Question;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Answer;
import reviewme.review.domain.Review;
import reviewme.review.service.dto.request.ReviewAnswerRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package reviewme.review.service.mapper;

import org.springframework.stereotype.Component;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;
import reviewme.review.domain.TextAnswer;
import reviewme.review.service.dto.request.ReviewAnswerRequest;
import reviewme.review.service.exception.TextAnswerIncludedOptionItemException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import reviewme.global.exception.DataInconsistencyException;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;

@Slf4j
public class UnsupportedQuestionTypeException extends DataInconsistencyException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.OptionGroup;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.Question;
import reviewme.question.repository.OptionGroupRepository;
import reviewme.question.repository.OptionItemRepository;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.OptionGroup;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.Question;
import reviewme.template.repository.OptionGroupRepository;
import reviewme.template.repository.OptionItemRepository;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Answer;
import reviewme.review.domain.CheckboxAnswerSelectedOption;
import reviewme.review.domain.CheckboxAnswer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.Question;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.Question;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Answer;
import reviewme.review.domain.CheckboxAnswerSelectedOption;
import reviewme.review.domain.CheckboxAnswer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.Question;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.Question;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Answer;
import reviewme.review.domain.TextAnswer;
import reviewme.review.service.exception.InvalidTextAnswerLengthException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reviewme.question.domain;
package reviewme.template.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reviewme.question.domain;
package reviewme.template.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reviewme.question.domain;
package reviewme.template.domain;

public enum OptionType {
CATEGORY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reviewme.question.domain;
package reviewme.template.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reviewme.question.domain;
package reviewme.template.domain;

public enum QuestionType {
CHECKBOX,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package reviewme.question.repository;
package reviewme.template.repository;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import reviewme.question.domain.OptionGroup;
import reviewme.template.domain.OptionGroup;

@Repository
public interface OptionGroupRepository extends JpaRepository<OptionGroup, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package reviewme.question.repository;
package reviewme.template.repository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.OptionType;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.OptionType;

@Repository
public interface OptionItemRepository extends JpaRepository<OptionItem, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package reviewme.question.repository;
package reviewme.template.repository;

import java.util.List;
import java.util.Set;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.Question;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.Question;

@Repository
public interface QuestionRepository extends JpaRepository<Question, Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reviewme.review.service.exception.ReviewGroupNotFoundByReviewRequestCodeException;
import reviewme.reviewgroup.domain.ReviewGroup;
import reviewme.reviewgroup.repository.ReviewGroupRepository;
import reviewme.reviewgroup.service.ReviewGroupService;
import reviewme.template.service.dto.response.TemplateResponse;
import reviewme.template.service.mapper.TemplateMapper;

@Service
@RequiredArgsConstructor
public class TemplateService {

private final ReviewGroupRepository reviewGroupRepository;
private final ReviewGroupService reviewGroupService;
private final TemplateMapper templateMapper;

@Transactional(readOnly = true)
public TemplateResponse generateReviewForm(String reviewRequestCode) {
ReviewGroup reviewGroup = findReviewGroupByRequestCodeOrThrow(reviewRequestCode);
ReviewGroup reviewGroup = reviewGroupService.getReviewGroupByReviewRequestCode(reviewRequestCode);
return templateMapper.mapToTemplateResponse(reviewGroup);
}

private ReviewGroup findReviewGroupByRequestCodeOrThrow(String reviewRequestCode) {
return reviewGroupRepository.findByReviewRequestCode(reviewRequestCode)
.orElseThrow(() -> new ReviewGroupNotFoundByReviewRequestCodeException(reviewRequestCode));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reviewme.question.domain.OptionGroup;
import reviewme.question.domain.OptionItem;
import reviewme.question.domain.Question;
import reviewme.question.repository.OptionGroupRepository;
import reviewme.question.repository.OptionItemRepository;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.domain.OptionGroup;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.Question;
import reviewme.template.repository.OptionGroupRepository;
import reviewme.template.repository.OptionItemRepository;
import reviewme.template.repository.QuestionRepository;
import reviewme.reviewgroup.domain.ReviewGroup;
import reviewme.template.domain.Section;
import reviewme.template.domain.SectionQuestion;
Expand Down
3 changes: 1 addition & 2 deletions backend/src/test/java/reviewme/api/ReviewApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.springframework.restdocs.cookies.CookieDocumentation.cookieWithName;
import static org.springframework.restdocs.cookies.CookieDocumentation.requestCookies;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
Expand All @@ -22,7 +21,7 @@
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.request.ParameterDescriptor;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;
import reviewme.review.service.dto.request.ReviewRegisterRequest;
import reviewme.review.service.dto.response.gathered.HighlightResponse;
import reviewme.review.service.dto.response.gathered.RangeResponse;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/test/java/reviewme/api/TemplateFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalDate;
import java.util.List;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.QuestionType;
import reviewme.review.service.dto.response.detail.OptionGroupAnswerResponse;
import reviewme.review.service.dto.response.detail.OptionItemAnswerResponse;
import reviewme.review.service.dto.response.detail.QuestionAnswerResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package reviewme.fixture;

import reviewme.question.domain.OptionGroup;
import reviewme.template.domain.OptionGroup;

public class OptionGroupFixture {

Expand Down
4 changes: 2 additions & 2 deletions backend/src/test/java/reviewme/fixture/OptionItemFixture.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package reviewme.fixture;

import reviewme.question.domain.OptionItem;
import reviewme.question.domain.OptionType;
import reviewme.template.domain.OptionItem;
import reviewme.template.domain.OptionType;

public class OptionItemFixture {

Expand Down
4 changes: 2 additions & 2 deletions backend/src/test/java/reviewme/fixture/QuestionFixture.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package reviewme.fixture;

import reviewme.question.domain.Question;
import reviewme.question.domain.QuestionType;
import reviewme.template.domain.Question;
import reviewme.template.domain.QuestionType;

public class QuestionFixture {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import reviewme.highlight.service.dto.HighlightRequest;
import reviewme.highlight.service.dto.HighlightedLineRequest;
import reviewme.highlight.service.dto.HighlightsRequest;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Review;
import reviewme.review.domain.TextAnswer;
import reviewme.review.repository.ReviewRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import reviewme.highlight.service.dto.HighlightRequest;
import reviewme.highlight.service.dto.HighlightedLineRequest;
import reviewme.highlight.service.dto.HighlightsRequest;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Review;
import reviewme.review.domain.TextAnswer;
import reviewme.review.repository.ReviewRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import reviewme.highlight.service.dto.HighlightRequest;
import reviewme.highlight.service.dto.HighlightsRequest;
import reviewme.highlight.service.exception.SubmittedAnswerAndProvidedAnswerMismatchException;
import reviewme.question.repository.QuestionRepository;
import reviewme.template.repository.QuestionRepository;
import reviewme.review.domain.Review;
import reviewme.review.domain.TextAnswer;
import reviewme.review.repository.ReviewRepository;
Expand Down
Loading

0 comments on commit cfdaeac

Please sign in to comment.