Skip to content

Commit

Permalink
chore: 임시저장 예외케이스 수정 (#136)
Browse files Browse the repository at this point in the history
* chore: 임시저장 예외케이스 수정

* chore: validation 수정
  • Loading branch information
mikekks authored Aug 9, 2024
1 parent 5c6bd38 commit cbbf89a
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ public class AnswerService {

@Transactional
public void create(AnswerListCreateRequest request, Long spaceId, Long retrospectId, Long memberId) {
// 스페이스 팀원인지 검증
Optional<MemberSpaceRelation> team = memberSpaceRelationRepository.findBySpaceIdAndMemberId(
spaceId, memberId);
if (team.isEmpty()) {
throw new MemberSpaceRelationException(NOT_FOUND_MEMBER_SPACE_RELATION);
}
// 해당 스페이스 팀원인지 검증
Team team = new Team(memberSpaceRelationRepository.findAllBySpaceId(spaceId));
team.validateTeamMembership(memberId);

// 회고 존재 검증
Retrospect retrospect = retrospectRepository.findByIdOrThrow(retrospectId);
Expand All @@ -62,14 +59,16 @@ public void create(AnswerListCreateRequest request, Long spaceId, Long retrospec
List<Long> questionIds = request.requests().stream()
.map(AnswerCreateRequest::questionId)
.toList();
Questions questions = new Questions(questionRepository.findAllByIdIn(questionIds));
Questions questions = new Questions(questionRepository.findAllByRetrospectIdOrderByQuestionOrder(retrospectId));
questions.validateQuestionSize(questionIds.size());

// 회고 질문 유효성 검사 - 이미 응답을 하지 않았는지
Answers answers = new Answers(
if (!request.isTemporarySave()) {
Answers answers = new Answers(
answerRepository.findByRetrospectIdAndMemberIdAndAnswerStatusAndQuestionIdIn(retrospectId, memberId,
AnswerStatus.DONE, questionIds));
answers.validateNoAnswer();
AnswerStatus.DONE, questionIds));
answers.validateNoAnswer();
}

// 기존 임시답변 제거
answerRepository.deleteAllByRetrospectIdAndMemberIdAndAnswerStatus(retrospectId, memberId,
Expand Down

0 comments on commit cbbf89a

Please sign in to comment.