Skip to content

Commit

Permalink
Merge pull request #1562 from woowacourse/Refactor/#1561-quiz_essayAn…
Browse files Browse the repository at this point in the history
…swer_엔드포인트_통일

refactor : 엔드포인트 통일
  • Loading branch information
java-saeng authored Oct 6, 2023
2 parents b0f6256 + 045dc98 commit f7567be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class KeywordService {
private final KeywordRepository keywordRepository;

public KeywordService(final SessionRepository sessionRepository,
final KeywordRepository keywordRepository) {
final KeywordRepository keywordRepository) {
this.sessionRepository = sessionRepository;
this.keywordRepository = keywordRepository;
}
Expand Down Expand Up @@ -93,8 +93,11 @@ public KeywordsResponse newFindSessionIncludeRootKeywords() {
return KeywordsResponse.createResponse(keywords);
}

public void updateKeyword(final Long sessionId, final Long keywordId,
final KeywordUpdateRequest request) {
public void updateKeyword(
final Long sessionId,
final Long keywordId,
final KeywordUpdateRequest request
) {
existSession(sessionId); // 세션이 없다면 예외가 발생
Keyword keyword = keywordRepository.findById(keywordId)
.orElseThrow(() -> new BadRequestException(ROADMAP_KEYWORD_NOT_FOUND_EXCEPTION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import wooteco.prolog.roadmap.application.dto.EssayAnswerResponse;
import wooteco.prolog.roadmap.application.dto.EssayAnswerSearchRequest;
import wooteco.prolog.roadmap.application.dto.EssayAnswerUpdateRequest;
import wooteco.prolog.roadmap.application.dto.QuizResponse;
import wooteco.prolog.roadmap.domain.EssayAnswer;
import wooteco.prolog.studylog.application.dto.EssayAnswersResponse;

Expand All @@ -37,14 +36,14 @@ public class EssayAnswerController {

@Autowired
public EssayAnswerController(EssayAnswerService essayAnswerService,
QuizService quizService) {
QuizService quizService) {
this.essayAnswerService = essayAnswerService;
this.quizService = quizService;
}

@PostMapping("/essay-answers")
public ResponseEntity<Long> create(@RequestBody EssayAnswerRequest request,
@AuthMemberPrincipal LoginMember member) {
@AuthMemberPrincipal LoginMember member) {

return ResponseEntity.ok(essayAnswerService.createEssayAnswer(request, member.getId()));
}
Expand All @@ -65,34 +64,30 @@ public ResponseEntity<EssayAnswerResponse> findById(@PathVariable Long essayAnsw

@PatchMapping("/essay-answers/{essayAnswerId}")
public ResponseEntity<Void> updateById(@PathVariable Long essayAnswerId,
@AuthMemberPrincipal LoginMember member,
@RequestBody EssayAnswerUpdateRequest request) {
@AuthMemberPrincipal LoginMember member,
@RequestBody EssayAnswerUpdateRequest request) {
essayAnswerService.updateEssayAnswer(essayAnswerId, request, member.getId());
return ResponseEntity.ok().build();
}

@DeleteMapping("/essay-answers/{essayAnswerId}")
public ResponseEntity<Void> deleteEssayAnswerById(@PathVariable Long essayAnswerId,
@AuthMemberPrincipal LoginMember member) {
public ResponseEntity<Void> deleteEssayAnswerById(
@PathVariable Long essayAnswerId,
@AuthMemberPrincipal LoginMember member
) {
essayAnswerService.deleteEssayAnswer(essayAnswerId, member.getId());
return ResponseEntity.noContent().build();
}

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

@GetMapping("/quizzes/{quizId}/essay-answers")
public ResponseEntity<List<EssayAnswerResponse>> findAnswersByQuizId(
@PathVariable Long quizId) {
@PathVariable Long quizId
) {

List<EssayAnswer> essayAnswers = essayAnswerService.findByQuizId(quizId);
List<EssayAnswerResponse> responses = essayAnswers.stream().map(EssayAnswerResponse::of)
.collect(toList());

return ResponseEntity.ok(responses);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ResponseEntity<QuizResponse> findQuizById(@PathVariable Long quizId,
return ResponseEntity.ok(quizService.findById(quizId, member.getId()));
}

@GetMapping("/quizs/{quizId}")
@GetMapping("/quizzes/{quizId}")
public ResponseEntity<QuizResponse> newFindQuizById(
@PathVariable Long quizId,
@AuthMemberPrincipal LoginMember member
Expand All @@ -56,9 +56,9 @@ public ResponseEntity<QuizzesResponse> findQuizzesByKeyword(@PathVariable Long s
return ResponseEntity.ok(quizService.findQuizzesByKeywordId(keywordId, member.getId()));
}

@GetMapping("/quizs")
@GetMapping("/quizzes")
public ResponseEntity<QuizzesResponse> newFindQuizzesByKeyword(
@RequestParam("keyword-id") Long keywordId,
@RequestParam("keywordId") Long keywordId,
@AuthMemberPrincipal LoginMember member
) {
return ResponseEntity.ok(quizService.findQuizzesByKeywordId(keywordId, member.getId()));
Expand Down

0 comments on commit f7567be

Please sign in to comment.