diff --git a/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java b/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java index d87e08d6d..1b2943dc4 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java @@ -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; @@ -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; @@ -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);