-
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.
* feat: TemplateController 추가 및 리뷰 템플릿 응답 기능 구현 * feat: 리뷰 템플릿 응답을 위한 dto 생성 * refactor: 에러 응답 메세지 변경 * refactor: onSelectedOptionId 타입 변경 * refactor: 도메인 id 제외 생성자 추가 * feat: TemplateService 추가 및 기본 템플릿 응답 기능 추가 * feat: TemplateMapper 구현 * refactor: mapping url 중복으로 인한 context 로딩 에러 해결을 위해 임시적으로 url 경로 변경 * refactor: 로깅 레벨 warn으로 변경 * refactor: 질문에 옵션 그룹이 없을 경우 null을 사용하도록 변경 * refactor: id 리스트를 즉시 로딩할 수 있도록 변경 * refactor: 메서드명 변경 * test: 테스트 추가 * test: DatabaseCleaner에서 CollectionTable로 생성된 테이블 초기화 하도록 변경 * refactor: Transactional readOnly 설정 * refactor: 컨트롤러 요청 경로 변경 * refactor: response에서 null 가능한 필드 명시 * style: 오타 수정 * refactor: Question2 hasGuideline 메서드에서 guideline이 null 인 경우도 추가 * refactor: 기본 사용 템플릿을 찾을 수 없는 경우에 대한 예외명과 로그 메세지 수정 * refactor: 옵션 그룹에 옵션 아이템이 없는 경우에 대한 예외명 수정 * refactor: SectionNotFoundException의 로그 레벨 수정 (info -> warn) * refactor: 사용하지 않는 메서드 삭제 * test: 가이드라인이 제공되지 않는 경우 테스트 추가 * test: 옵션 그룹에 없는 질문이 없는 경우 테스트 추가 * test: 섹션의 선택된 옵션이 필요없는 경우 테스트 추가 * refactor: long 타입 변경
- Loading branch information
Showing
20 changed files
with
524 additions
and
10 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
...ain/java/reviewme/question/domain/exception/MissingOptionItemsInOptionGroupException.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,13 @@ | ||
package reviewme.question.domain.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import reviewme.global.exception.NotFoundException; | ||
|
||
@Slf4j | ||
public class MissingOptionItemsInOptionGroupException extends NotFoundException { | ||
|
||
public MissingOptionItemsInOptionGroupException(long optionGroupId) { | ||
super("서버 내부에서 문제가 발생했어요. 서버에 문의해주세요."); | ||
log.warn("OptionGroup has no OptionItems - optionGroupId: {}", optionGroupId); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../main/java/reviewme/question/domain/exception/OptionGroupNotFoundByQuestionException.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,13 @@ | ||
package reviewme.question.domain.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import reviewme.global.exception.NotFoundException; | ||
|
||
@Slf4j | ||
public class OptionGroupNotFoundByQuestionException extends NotFoundException { | ||
|
||
public OptionGroupNotFoundByQuestionException(long questionId) { | ||
super("서버 내부에서 문제가 발생했어요. 서버에 문의해주세요."); | ||
log.warn("OptionGroup not found by question - questionId: {}", questionId); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
backend/src/main/java/reviewme/question/repository/Question2Repository.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
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
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/reviewme/template/controller/TemplateController.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,22 @@ | ||
package reviewme.template.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reviewme.template.dto.response.TemplateResponse; | ||
import reviewme.template.service.TemplateService; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class TemplateController { | ||
|
||
private final TemplateService templateService; | ||
|
||
@GetMapping("/v2/reviews/write") | ||
public ResponseEntity<TemplateResponse> getReviewForm(@RequestParam String reviewRequestCode) { | ||
TemplateResponse response = templateService.generateReviewForm(reviewRequestCode); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...nd/src/main/java/reviewme/template/domain/exception/DefaultTemplateNotFoundException.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,13 @@ | ||
package reviewme.template.domain.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import reviewme.global.exception.NotFoundException; | ||
|
||
@Slf4j | ||
public class DefaultTemplateNotFoundException extends NotFoundException { | ||
|
||
public DefaultTemplateNotFoundException(long id) { | ||
super("서버 내부에서 문제가 발생했어요. 서버에 문의해주세요."); | ||
log.warn("DefaultTemplateNotFoundException is occurred - id: {}", id); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/reviewme/template/dto/response/OptionGroupResponse.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.template.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record OptionGroupResponse( | ||
|
||
long optionGroupId, | ||
int minCount, | ||
int maxCount, | ||
List<OptionItemResponse> options | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/reviewme/template/dto/response/OptionItemResponse.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,8 @@ | ||
package reviewme.template.dto.response; | ||
|
||
public record OptionItemResponse( | ||
|
||
long optionId, | ||
String content | ||
) { | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/reviewme/template/dto/response/QuestionResponse.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,15 @@ | ||
package reviewme.template.dto.response; | ||
|
||
import jakarta.annotation.Nullable; | ||
|
||
public record QuestionResponse( | ||
|
||
long questionId, | ||
boolean required, | ||
String content, | ||
String questionType, | ||
@Nullable OptionGroupResponse optionGroup, | ||
boolean hasGuideline, | ||
@Nullable String guideline | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/reviewme/template/dto/response/SectionResponse.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,14 @@ | ||
package reviewme.template.dto.response; | ||
|
||
import jakarta.annotation.Nullable; | ||
import java.util.List; | ||
|
||
public record SectionResponse( | ||
|
||
long sectionId, | ||
String visible, | ||
@Nullable Long onSelectedOptionId, | ||
String header, | ||
List<QuestionResponse> questions | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/reviewme/template/dto/response/TemplateResponse.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.template.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record TemplateResponse( | ||
|
||
long formId, | ||
String revieweeName, | ||
String projectName, | ||
List<SectionResponse> sections | ||
) { | ||
} |
102 changes: 102 additions & 0 deletions
102
backend/src/main/java/reviewme/template/service/TemplateMapper.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,102 @@ | ||
package reviewme.template.service; | ||
|
||
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.Question2; | ||
import reviewme.question.domain.exception.MissingOptionItemsInOptionGroupException; | ||
import reviewme.question.repository.OptionGroupRepository; | ||
import reviewme.question.repository.OptionItemRepository; | ||
import reviewme.question.repository.Question2Repository; | ||
import reviewme.reviewgroup.domain.ReviewGroup; | ||
import reviewme.template.domain.Section; | ||
import reviewme.template.domain.SectionQuestion; | ||
import reviewme.template.domain.Template; | ||
import reviewme.template.domain.TemplateSection; | ||
import reviewme.template.dto.response.OptionGroupResponse; | ||
import reviewme.template.dto.response.OptionItemResponse; | ||
import reviewme.template.dto.response.QuestionResponse; | ||
import reviewme.template.dto.response.SectionResponse; | ||
import reviewme.template.dto.response.TemplateResponse; | ||
import reviewme.template.repository.SectionRepository; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class TemplateMapper { | ||
|
||
private final SectionRepository sectionRepository; | ||
private final Question2Repository questionRepository; | ||
private final OptionGroupRepository optionGroupRepository; | ||
private final OptionItemRepository optionItemRepository; | ||
|
||
public TemplateResponse mapToTemplateResponse(ReviewGroup reviewGroup, Template template) { | ||
List<SectionResponse> sectionResponses = template.getSectionIds() | ||
.stream() | ||
.map(this::mapToSectionResponse) | ||
.toList(); | ||
|
||
return new TemplateResponse( | ||
template.getId(), | ||
reviewGroup.getReviewee(), | ||
reviewGroup.getProjectName(), | ||
sectionResponses | ||
); | ||
} | ||
|
||
private SectionResponse mapToSectionResponse(TemplateSection templateSection) { | ||
Section section = sectionRepository.getSectionById(templateSection.getSectionId()); | ||
List<QuestionResponse> questionResponses = section.getQuestionIds() | ||
.stream() | ||
.map(this::mapToQuestionResponse) | ||
.toList(); | ||
|
||
return new SectionResponse( | ||
section.getId(), | ||
section.getVisibleType().name(), | ||
section.getOnSelectedOptionId(), | ||
section.getHeader(), | ||
questionResponses | ||
); | ||
} | ||
|
||
private QuestionResponse mapToQuestionResponse(SectionQuestion sectionQuestion) { | ||
Question2 question = questionRepository.getQuestionById(sectionQuestion.getQuestionId()); | ||
OptionGroupResponse optionGroupResponse = optionGroupRepository.findByQuestionId(question.getId()) | ||
.map(this::mapToOptionGroupResponse) | ||
.orElse(null); | ||
|
||
return new QuestionResponse( | ||
question.getId(), | ||
question.isRequired(), | ||
question.getContent(), | ||
question.getContent(), | ||
optionGroupResponse, | ||
question.hasGuideline(), | ||
question.getGuideline() | ||
); | ||
} | ||
|
||
private OptionGroupResponse mapToOptionGroupResponse(OptionGroup optionGroup) { | ||
List<OptionItem> optionItems = optionItemRepository.findAllByOptionGroupId(optionGroup.getId()); | ||
if (optionItems.isEmpty()) { | ||
throw new MissingOptionItemsInOptionGroupException(optionGroup.getId()); | ||
} | ||
|
||
List<OptionItemResponse> optionItemResponses = optionItems.stream() | ||
.map(this::mapToOptionItemResponse) | ||
.toList(); | ||
|
||
return new OptionGroupResponse( | ||
optionGroup.getId(), | ||
optionGroup.getMinSelectionCount(), | ||
optionGroup.getMaxSelectionCount(), | ||
optionItemResponses | ||
); | ||
} | ||
|
||
private OptionItemResponse mapToOptionItemResponse(OptionItem optionItem) { | ||
return new OptionItemResponse(optionItem.getId(), optionItem.getContent()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
backend/src/main/java/reviewme/template/service/TemplateService.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.template.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import reviewme.review.domain.exception.ReviewGroupNotFoundByRequestReviewCodeException; | ||
import reviewme.reviewgroup.domain.ReviewGroup; | ||
import reviewme.reviewgroup.repository.ReviewGroupRepository; | ||
import reviewme.template.domain.Template; | ||
import reviewme.template.domain.exception.DefaultTemplateNotFoundException; | ||
import reviewme.template.dto.response.TemplateResponse; | ||
import reviewme.template.repository.TemplateRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TemplateService { | ||
|
||
private static final long USE_TEMPLATE_ID = 1L; | ||
|
||
private final ReviewGroupRepository reviewGroupRepository; | ||
private final TemplateRepository templateRepository; | ||
private final TemplateMapper templateMapper; | ||
|
||
@Transactional(readOnly = true) | ||
public TemplateResponse generateReviewForm(String reviewRequestCode) { | ||
ReviewGroup reviewGroup = reviewGroupRepository.findByReviewRequestCode(reviewRequestCode) | ||
.orElseThrow(() -> new ReviewGroupNotFoundByRequestReviewCodeException(reviewRequestCode)); | ||
|
||
Template defaultTemplate = templateRepository.findById(USE_TEMPLATE_ID) | ||
.orElseThrow(() -> new DefaultTemplateNotFoundException(USE_TEMPLATE_ID)); | ||
|
||
return templateMapper.mapToTemplateResponse(reviewGroup, defaultTemplate); | ||
} | ||
} |
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
Oops, something went wrong.