Skip to content

Commit

Permalink
refactor: 리뷰 피드백 반영
Browse files Browse the repository at this point in the history
ReviewFormQuestion으로 이름 변경
사용하지 않는 setter 제거
toList로 수정
response of 함수 추가
카테고리에 해당하는 질문이 없는 경우에 대한 error code 추가

related to: #4
  • Loading branch information
heejjinkim committed Aug 23, 2024
1 parent 941e229 commit 44969b7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum ReviewErrorCode implements ErrorCode {
OPTION_NOT_FOUND(HttpStatus.NOT_FOUND, "Option not found"),
QUESTION_NOT_FOUND(HttpStatus.NOT_FOUND, "Question not found"),
CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "Category not found"),
QUESTIONS_NOT_FOUND_FOR_CATEGORY(HttpStatus.NOT_FOUND, "No questions found for the given category")
;

private final HttpStatus httpStatus;
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/_119/wepro/review/domain/ReviewForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ public class ReviewForm extends BaseEntity {
private Project project;

@OneToMany(mappedBy = "reviewForm", cascade = CascadeType.ALL)
private List<ReviewQuestion> reviewQuestions;
private List<ReviewFormQuestion> reviewFormQuestions;

public static ReviewForm of(Member member, Project project) {
return ReviewForm.builder().member(member).project(project).build();
}

public void setReviewQuestions(List<ReviewQuestion> reviewQuestions) {
this.reviewQuestions = reviewQuestions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Entity
@Getter
@Builder
public class ReviewQuestion extends BaseEntity {
public class ReviewFormQuestion extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -33,8 +33,8 @@ public class ReviewQuestion extends BaseEntity {
@JoinColumn(name = "question_id")
private Question question;

public static ReviewQuestion of(ReviewForm reviewForm, Question question) {
return ReviewQuestion.builder()
public static ReviewFormQuestion of(ReviewForm reviewForm, Question question) {
return ReviewFormQuestion.builder()
.reviewForm(reviewForm)
.question(question)
.build();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com._119.wepro.review.dto.response;

import com._119.wepro.member.domain.Member;
import com._119.wepro.review.domain.ReviewForm;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -12,5 +13,12 @@ public static class ReviewFormCreateResponse {

private Long reviewFormId;
private Member sender;

public static ReviewFormCreateResponse of(ReviewForm reviewForm, Member member) {
return ReviewFormCreateResponse.builder()
.reviewFormId(reviewForm.getId())
.sender(member)
.build();
}
}
}
21 changes: 9 additions & 12 deletions src/main/java/com/_119/wepro/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import com._119.wepro.project.domain.repository.ProjectRepository;
import com._119.wepro.review.domain.Question;
import com._119.wepro.review.domain.ReviewForm;
import com._119.wepro.review.domain.ReviewQuestion;
import com._119.wepro.review.domain.ReviewFormQuestion;
import com._119.wepro.review.domain.repository.ReviewFormRepository;
import com._119.wepro.review.domain.repository.QuestionRepository;
import com._119.wepro.review.domain.repository.ReviewQuestionJdbcRepository;
import com._119.wepro.review.domain.repository.ReviewFormQuestionJdbcRepository;
import com._119.wepro.review.dto.request.ReviewRequest.ReviewFormCreateRequest;
import com._119.wepro.review.dto.response.ReviewResponse.ReviewFormCreateResponse;
import jakarta.transaction.Transactional;
Expand All @@ -31,7 +31,7 @@ public class ReviewService {
private final ReviewFormRepository reviewFormRepository;
private final ProjectRepository projectRepository;
private final QuestionRepository questionRepository;
private final ReviewQuestionJdbcRepository reviewQuestionJdbcRepository;
private final ReviewFormQuestionJdbcRepository reviewFormQuestionJdbcRepository;

@Transactional
public ReviewFormCreateResponse createReviewForm(ReviewFormCreateRequest request, Long memberId) {
Expand All @@ -44,24 +44,21 @@ public ReviewFormCreateResponse createReviewForm(ReviewFormCreateRequest request
List<CategoryType> categories = request.getCategories();
List<Question> questions = categories.stream()
.flatMap(category -> questionRepository.findByCategoryType(category).stream())
.collect(Collectors.toList());
.toList();
if (questions.isEmpty()) {
throw new RestApiException(ReviewErrorCode.QUESTION_NOT_FOUND);
throw new RestApiException(ReviewErrorCode.QUESTIONS_NOT_FOUND_FOR_CATEGORY);
}

// 리뷰 폼 생성 및 저장
ReviewForm reviewForm = ReviewForm.of(member, project);
ReviewForm savedReviewForm = reviewFormRepository.save(reviewForm);

List<ReviewQuestion> reviewQuestions = questions.stream()
.map(question -> ReviewQuestion.of(savedReviewForm, question))
List<ReviewFormQuestion> reviewFormQuestions = questions.stream()
.map(question -> ReviewFormQuestion.of(savedReviewForm, question))
.collect(Collectors.toList());
reviewQuestionJdbcRepository.batchInsert(reviewQuestions);
reviewFormQuestionJdbcRepository.batchInsert(reviewFormQuestions);

return ReviewFormCreateResponse.builder()
.reviewFormId(savedReviewForm.getId())
.sender(member)
.build();
return ReviewFormCreateResponse.of(savedReviewForm, member);
}

}

0 comments on commit 44969b7

Please sign in to comment.