Skip to content

Commit

Permalink
Merge pull request #88 from kakao-tech-campus-2nd-step3/develop
Browse files Browse the repository at this point in the history
deploy: Answer 중복 저장 문제 CASCADE로 해결
  • Loading branch information
5win authored Nov 18, 2024
2 parents 55db489 + 01bfe0f commit 9f56c43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/gamsa/review/domain/Answer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Builder
public class Answer {
private Long answerId;
private Long reviewId;
private double score;
private Question question;
}
17 changes: 7 additions & 10 deletions src/main/java/com/gamsa/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.gamsa.review.domain.Review;
import com.gamsa.review.dto.ReviewResponse;
import com.gamsa.review.dto.ReviewSaveRequest;
import com.gamsa.review.repository.AnswerRepository;
import com.gamsa.review.repository.QuestionRepository;
import com.gamsa.review.repository.ReviewRepository;
import com.gamsa.user.repository.UserRepository;
Expand All @@ -28,7 +27,6 @@ public class ReviewService {
private final UserRepository userRepository;
private final QuestionRepository questionRepository;
private final ReviewRepository reviewRepository;
private final AnswerRepository answerRepository;
private final HistoryRepository historyRepository;

@Transactional
Expand All @@ -51,17 +49,16 @@ public void saveReview(Long userId, ReviewSaveRequest saveRequest) {
List<Answer> answers = saveRequest.getAnswers().stream()
.map(answer -> {
Question question = questionRepository.findById(answer.getQuestionId())
.orElseThrow(() -> new NoSuchElementException("존재하지 않는 질문"));
.orElseThrow(() -> new NoSuchElementException("존재하지 않는 질문"));

return Answer.builder()
.question(question)
.score(answer.getScore())
.build();
.question(question)
.reviewId(null)
.score(answer.getScore())
.build();
})
.toList();

answers.forEach(answerRepository::save);

// save review
Review review = Review.builder()
.activity(activity)
Expand All @@ -73,7 +70,7 @@ public void saveReview(Long userId, ReviewSaveRequest saveRequest) {
reviewRepository.save(review);
}

public BigDecimal getAverageScore(long instituteId, int questionId) {
public BigDecimal getAverageScore(Long instituteId, int questionId) {
OptionalDouble averageScore = reviewRepository.findReviews(instituteId, questionId)
.stream()
.flatMap(review -> review.getAnswers().stream())
Expand All @@ -88,7 +85,7 @@ public BigDecimal getAverageScore(long instituteId, int questionId) {
}
}

public List<ReviewResponse> getReview(long historyId) {
public List<ReviewResponse> getReview(Long historyId) {

return reviewRepository.findHistoryReview(historyId)
.orElseThrow(NoSuchElementException::new)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gamsa.activity.service;

import static org.assertj.core.api.Assertions.assertThat;

import com.gamsa.activity.constant.ActivityErrorCode;
import com.gamsa.activity.dto.ActivityDetailResponse;
import com.gamsa.activity.dto.ActivityFindSliceResponse;
Expand All @@ -9,7 +11,6 @@
import com.gamsa.history.stub.StubHistoryRepository;
import com.gamsa.review.service.QuestionService;
import com.gamsa.review.service.ReviewService;
import com.gamsa.review.stub.StubAnswerRepository;
import com.gamsa.review.stub.StubQuestionRepository;
import com.gamsa.review.stub.StubReviewRepository;
import com.gamsa.user.stub.StubExistsUserRepository;
Expand All @@ -18,8 +19,6 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;

import static org.assertj.core.api.Assertions.assertThat;

class ActivityServiceTest {


Expand All @@ -35,7 +34,6 @@ class ActivityServiceTest {
new StubExistsUserRepository(),
new StubQuestionRepository(),
new StubReviewRepository(),
new StubAnswerRepository(),
new StubHistoryRepository()
)
);
Expand All @@ -60,7 +58,6 @@ class ActivityServiceTest {
new StubExistsUserRepository(),
new StubQuestionRepository(),
new StubReviewRepository(),
new StubAnswerRepository(),
new StubHistoryRepository()
)
);
Expand All @@ -84,7 +81,6 @@ class ActivityServiceTest {
new StubExistsUserRepository(),
new StubQuestionRepository(),
new StubReviewRepository(),
new StubAnswerRepository(),
new StubHistoryRepository()
)
);
Expand Down

0 comments on commit 9f56c43

Please sign in to comment.