Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#1357 로드맵 답변 수정 기능 #1408

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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