Skip to content
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: 리뷰 폼 응답 재구현 #295

Merged
merged 28 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2ea69e6
feat: TemplateController 추가 및 리뷰 템플릿 응답 기능 구현
Kimprodp Aug 10, 2024
c424c06
feat: 리뷰 템플릿 응답을 위한 dto 생성
Kimprodp Aug 10, 2024
5abbf92
refactor: 에러 응답 메세지 변경
Kimprodp Aug 10, 2024
8d10101
refactor: onSelectedOptionId 타입 변경
Kimprodp Aug 10, 2024
d532c2b
refactor: 도메인 id 제외 생성자 추가
Kimprodp Aug 10, 2024
8cdaabe
feat: TemplateService 추가 및 기본 템플릿 응답 기능 추가
Kimprodp Aug 10, 2024
9039ec8
feat: TemplateMapper 구현
Kimprodp Aug 10, 2024
d6f708f
refactor: mapping url 중복으로 인한 context 로딩 에러 해결을 위해 임시적으로 url 경로 변경
Kimprodp Aug 10, 2024
9c50413
refactor: 로깅 레벨 warn으로 변경
Kimprodp Aug 10, 2024
fa0ae42
refactor: 질문에 옵션 그룹이 없을 경우 null을 사용하도록 변경
Kimprodp Aug 10, 2024
1811deb
refactor: id 리스트를 즉시 로딩할 수 있도록 변경
Kimprodp Aug 10, 2024
f2edd17
refactor: 메서드명 변경
Kimprodp Aug 10, 2024
2c93220
test: 테스트 추가
Kimprodp Aug 10, 2024
bb2245c
test: DatabaseCleaner에서 CollectionTable로 생성된 테이블 초기화 하도록 변경
Kimprodp Aug 11, 2024
040cbea
refactor: Transactional readOnly 설정
Kimprodp Aug 11, 2024
274d8d3
refactor: 컨트롤러 요청 경로 변경
Kimprodp Aug 11, 2024
31999b1
refactor: response에서 null 가능한 필드 명시
Kimprodp Aug 11, 2024
de0c64d
style: 오타 수정
Kimprodp Aug 11, 2024
f6c309c
refactor: Question2 hasGuideline 메서드에서 guideline이 null 인 경우도 추가
Kimprodp Aug 11, 2024
f7b1ec3
refactor: 기본 사용 템플릿을 찾을 수 없는 경우에 대한 예외명과 로그 메세지 수정
Kimprodp Aug 11, 2024
207eccc
refactor: 옵션 그룹에 옵션 아이템이 없는 경우에 대한 예외명 수정
Kimprodp Aug 11, 2024
fef29f6
refactor: SectionNotFoundException의 로그 레벨 수정 (info -> warn)
Kimprodp Aug 11, 2024
bc28681
refactor: 사용하지 않는 메서드 삭제
Kimprodp Aug 11, 2024
d26b268
test: 가이드라인이 제공되지 않는 경우 테스트 추가
Kimprodp Aug 11, 2024
3092be1
test: 옵션 그룹에 없는 질문이 없는 경우 테스트 추가
Kimprodp Aug 11, 2024
892c73b
test: 섹션의 선택된 옵션이 필요없는 경우 테스트 추가
Kimprodp Aug 11, 2024
be6b8d5
refactor: long 타입 변경
Kimprodp Aug 11, 2024
d5c3b3d
Merge remote-tracking branch 'refs/remotes/origin/develop' into be/fe…
Kimprodp Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public class OptionGroup {

@Column(name = "max_selection_count", nullable = false)
private int maxSelectionCount;

public OptionGroup(long questionId, int minSelectionCount, int maxSelectionCount) {
this.questionId = questionId;
this.minSelectionCount = minSelectionCount;
this.maxSelectionCount = maxSelectionCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public class OptionItem {

@Column(name = "position", nullable = false)
private int position;

public OptionItem(String content, long optionGroupId, int position) {
this.content = content;
this.optionGroupId = optionGroupId;
this.position = position;
}
}
12 changes: 12 additions & 0 deletions backend/src/main/java/reviewme/question/domain/Question2.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ public class Question2 {

@Column(name = "position", nullable = false)
private int position;

public Question2(boolean required, QuestionType questionType, String content, String guideline, int position) {
this.required = required;
this.questionType = questionType;
this.content = content;
this.guideline = guideline;
this.position = position;
}

public boolean hasGuideline() {
return guideline != null && !guideline.isEmpty();
}
}
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);
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package reviewme.question.repository;

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

@Repository
public interface OptionGroupRepository extends JpaRepository<OptionGroup, Long> {

Optional<OptionGroup> findByQuestionId(long questionId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package reviewme.question.repository;

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

@Repository
public interface OptionItemRepository extends JpaRepository<OptionItem, Long> {

List<OptionItem> findAllByOptionGroupId(long optionGroupId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package reviewme.question.repository;

import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import reviewme.question.domain.Question2;
import reviewme.question.domain.exception.QuestionNotFoundException;

@Repository
public interface Question2Repository extends JpaRepository<Question2, Long> {

Optional<Question2> findById(long id);

default Question2 getQuestionById(long id) {
return findById(id).orElseThrow(() -> new QuestionNotFoundException(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
public class InvalidAnswerLengthException extends BadRequestException {

public InvalidAnswerLengthException(int answerLength, int minLength, int maxLength) {
super("답변의 길이는 %d자 이상 %d자 이하여야 합니다.".formatted(minLength, maxLength));
log.info("AnswerLength is out of bound - answerLength:{}, minLength: {}, maxLength: {}",
super("답변의 길이는 %d자 이상 %d자 이하여야 해요.".formatted(minLength, maxLength));
log.info("AnswerLength is out of bound - answerLength: {}, minLength: {}, maxLength: {}",
answerLength, minLength, maxLength);
}
}
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);
}
}
12 changes: 11 additions & 1 deletion backend/src/main/java/reviewme/template/domain/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand All @@ -30,7 +31,7 @@ public class Section {
@Enumerated(EnumType.STRING)
private VisibleType visibleType;

@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "question_ids", joinColumns = @JoinColumn(name = "section_id"))
private List<Long> questionIds;

Expand All @@ -42,4 +43,13 @@ public class Section {

@Column(name = "position", nullable = false)
private int position;

public Section(VisibleType visibleType, List<Long> questionIds, Long onSelectedOptionId, String header,
int position) {
this.visibleType = visibleType;
this.questionIds = questionIds;
this.onSelectedOptionId = onSelectedOptionId;
this.header = header;
this.position = position;
}
}
7 changes: 6 additions & 1 deletion backend/src/main/java/reviewme/template/domain/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand All @@ -23,7 +24,11 @@ public class Template {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "section_ids", joinColumns = @JoinColumn(name = "template_id"))
List<Long> sectionIds;

public Template(List<Long> sectionIds) {
this.sectionIds = sectionIds;
}
}
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);
}
}
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 SectionNotFoundException extends NotFoundException {

public SectionNotFoundException(long id) {
super("서버 내부에서 문제가 발생했어요. 서버에 문의해주세요.");
log.warn("SectionNotFoundException is occurred - id: {}", id);
}
}
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
) {
}
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
) {
}
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
) {
}
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
) {
}
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
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package reviewme.template.repository;

import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import reviewme.template.domain.Section;
import reviewme.template.domain.exception.SectionNotFoundException;

@Repository
public interface SectionRepository extends JpaRepository<Section, Long> {

Optional<Section> findById(long id);

default Section getSectionById(long id) {
return findById(id).orElseThrow(() -> new SectionNotFoundException(id));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package reviewme.template.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import reviewme.template.domain.Template;

@Repository
public interface TemplateRepository extends JpaRepository<Template, Long> {

}
Loading