Skip to content

Commit

Permalink
feat: EssayAnswer 작성 시 비크루인원의 경우 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-sile committed Oct 11, 2023
1 parent 854d401 commit 3c9ee5e
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static wooteco.prolog.common.exception.BadRequestCode.CURRICULUM_NOT_FOUND_EXCEPTION;
import static wooteco.prolog.common.exception.BadRequestCode.ESSAY_ANSWER_NOT_FOUND_EXCEPTION;
import static wooteco.prolog.common.exception.BadRequestCode.MEMBER_NOT_ALLOWED;
import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_QUIZ_NOT_FOUND_EXCEPTION;
import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_SESSION_NOT_FOUND_EXCEPTION;

Expand All @@ -16,6 +17,7 @@
import wooteco.prolog.common.exception.BadRequestException;
import wooteco.prolog.member.application.MemberService;
import wooteco.prolog.member.domain.Member;
import wooteco.prolog.member.domain.Role;
import wooteco.prolog.roadmap.application.dto.EssayAnswerRequest;
import wooteco.prolog.roadmap.application.dto.EssayAnswerSearchRequest;
import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest;
Expand Down Expand Up @@ -61,12 +63,19 @@ public Long createEssayAnswer(EssayAnswerRequest essayAnswerRequest, Long member
.orElseThrow(() -> new BadRequestException(ROADMAP_QUIZ_NOT_FOUND_EXCEPTION));

Member member = memberService.findById(memberId);
validateMemberIsCrew(member);
EssayAnswer essayAnswer = new EssayAnswer(quiz, essayAnswerRequest.getAnswer(), member);
essayAnswerRepository.save(essayAnswer);

return essayAnswer.getId();
}

private void validateMemberIsCrew(final Member member) {
if (member.hasLowerImportanceRoleThan(Role.CREW)) {
throw new BadRequestException(MEMBER_NOT_ALLOWED);
}
}

@Transactional
public void updateEssayAnswer(Long answerId, EssayAnswerUpdateRequest request, Long memberId) {
EssayAnswer essayAnswer = getById(answerId);
Expand Down

0 comments on commit 3c9ee5e

Please sign in to comment.