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 dd53c30b8..f7430eb40 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/application/EssayAnswerService.java @@ -1,6 +1,5 @@ package wooteco.prolog.roadmap.application; -import java.util.List; import org.hibernate.Hibernate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -8,12 +7,13 @@ import wooteco.prolog.member.application.MemberService; import wooteco.prolog.member.domain.Member; import wooteco.prolog.roadmap.application.dto.EssayAnswerRequest; +import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest; import wooteco.prolog.roadmap.domain.EssayAnswer; import wooteco.prolog.roadmap.domain.Quiz; import wooteco.prolog.roadmap.domain.repository.EssayAnswerRepository; import wooteco.prolog.roadmap.domain.repository.QuizRepository; -import javax.persistence.PersistenceContext; +import java.util.List; @Transactional @Service @@ -46,11 +46,11 @@ public Long createEssayAnswer(EssayAnswerRequest essayAnswerRequest, Long member } @Transactional - public void updateEssayAnswer(Long answerId, String answer, Long memberId) { + public void updateEssayAnswer(Long answerId, EssayAnswerUpdateRequest request, Long memberId) { EssayAnswer essayAnswer = getById(answerId); Member member = memberService.findById(memberId); - essayAnswer.update(answer, member); + essayAnswer.update(request.getAnswer(), member); essayAnswerRepository.save(essayAnswer); } diff --git a/backend/src/main/java/wooteco/prolog/roadmap/ui/EssayAnswerController.java b/backend/src/main/java/wooteco/prolog/roadmap/ui/EssayAnswerController.java index 5261095e5..bce13ff0f 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/ui/EssayAnswerController.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/ui/EssayAnswerController.java @@ -49,10 +49,10 @@ public ResponseEntity findById(@PathVariable Long essayAnsw public ResponseEntity updateById(@PathVariable Long essayAnswerId, @AuthMemberPrincipal LoginMember member, @RequestBody EssayAnswerUpdateRequest request) { - essayAnswerService.updateEssayAnswer(essayAnswerId, request.getAnswer(), member.getId()); + essayAnswerService.updateEssayAnswer(essayAnswerId, request, member.getId()); return ResponseEntity.ok().build(); } - + @DeleteMapping("/essay-answers/{essayAnswerId}") public ResponseEntity deleteEssayAnswerById(@PathVariable Long essayAnswerId, @AuthMemberPrincipal LoginMember member) { @@ -61,7 +61,7 @@ public ResponseEntity deleteEssayAnswerById(@PathVariable Long essayAnswer } @GetMapping("/quizzes/{quizId}") - public ResponseEntity findEssayAnswerById(@PathVariable Long quizId) { + public ResponseEntity findQuizById(@PathVariable Long quizId) { return ResponseEntity.ok(quizService.findById(quizId)); } diff --git a/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java b/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java index 146bfade3..5943af59f 100644 --- a/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java +++ b/backend/src/test/java/wooteco/prolog/roadmap/application/EssayAnswerServiceTest.java @@ -10,6 +10,7 @@ import wooteco.prolog.member.domain.Member; import wooteco.prolog.member.exception.MemberNotFoundException; import wooteco.prolog.roadmap.application.dto.EssayAnswerRequest; +import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest; import wooteco.prolog.roadmap.domain.EssayAnswer; import wooteco.prolog.roadmap.domain.Quiz; import wooteco.prolog.roadmap.domain.repository.EssayAnswerRepository; @@ -22,10 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class EssayAnswerServiceTest { @@ -77,7 +75,7 @@ void updateEssayAnswer() { .thenReturn(new Member(null, null, null, 1L, null)); //when - essayAnswerService.updateEssayAnswer(1L, "answer", 1L); + essayAnswerService.updateEssayAnswer(1L, new EssayAnswerUpdateRequest("answer"), 1L); //then verify(essayAnswerRepository, times(1)).save(any());