Skip to content

Commit

Permalink
Merge pull request #1408 from woowacourse/feature/1357-roadmap-update
Browse files Browse the repository at this point in the history
Feature/#1357 로드맵 답변 수정 기능
  • Loading branch information
nuyh99 authored Jul 14, 2023
2 parents abb794e + 52c9afc commit 0488681
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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;
import org.springframework.transaction.annotation.Transactional;
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
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public ResponseEntity<EssayAnswerResponse> findById(@PathVariable Long essayAnsw
public ResponseEntity<Void> 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<Void> deleteEssayAnswerById(@PathVariable Long essayAnswerId,
@AuthMemberPrincipal LoginMember member) {
Expand All @@ -61,7 +61,7 @@ public ResponseEntity<Void> deleteEssayAnswerById(@PathVariable Long essayAnswer
}

@GetMapping("/quizzes/{quizId}")
public ResponseEntity<QuizResponse> findEssayAnswerById(@PathVariable Long quizId) {
public ResponseEntity<QuizResponse> findQuizById(@PathVariable Long quizId) {
return ResponseEntity.ok(quizService.findById(quizId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 0488681

Please sign in to comment.