From 045dc982a9831d2f28de9b10d88a01943040f7d3 Mon Sep 17 00:00:00 2001 From: java-saeng Date: Wed, 27 Sep 2023 17:32:43 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=97=94=EB=93=9C=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roadmap/application/KeywordService.java | 20 ++++++++------- .../roadmap/ui/EssayAnswerController.java | 25 ++++++++----------- .../prolog/roadmap/ui/QuizController.java | 6 ++--- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/backend/src/main/java/wooteco/prolog/roadmap/application/KeywordService.java b/backend/src/main/java/wooteco/prolog/roadmap/application/KeywordService.java index febb602c7..b7dd4b696 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/application/KeywordService.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/application/KeywordService.java @@ -1,5 +1,9 @@ package wooteco.prolog.roadmap.application; +import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_KEYWORD_NOT_FOUND_EXCEPTION; +import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_SESSION_NOT_FOUND_EXCEPTION; + +import java.util.List; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import wooteco.prolog.common.exception.BadRequestException; @@ -11,11 +15,6 @@ import wooteco.prolog.roadmap.domain.repository.KeywordRepository; import wooteco.prolog.session.domain.repository.SessionRepository; -import java.util.List; - -import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_KEYWORD_NOT_FOUND_EXCEPTION; -import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_SESSION_NOT_FOUND_EXCEPTION; - @Transactional @Service public class KeywordService { @@ -24,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; } @@ -89,13 +88,16 @@ public KeywordsResponse findSessionIncludeRootKeywords(final Long sessionId) { @Transactional(readOnly = true) public KeywordsResponse newFindSessionIncludeRootKeywords() { - List keywords = keywordRepository.newFindParentIsNull(); + List keywords = keywordRepository.newFindByParentIsNull(); 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)); 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 d90b85fda..f56807baf 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/ui/EssayAnswerController.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/ui/EssayAnswerController.java @@ -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; @@ -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 create(@RequestBody EssayAnswerRequest request, - @AuthMemberPrincipal LoginMember member) { + @AuthMemberPrincipal LoginMember member) { return ResponseEntity.ok(essayAnswerService.createEssayAnswer(request, member.getId())); } @@ -65,28 +64,25 @@ public ResponseEntity findById(@PathVariable Long essayAnsw @PatchMapping("/essay-answers/{essayAnswerId}") public ResponseEntity 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 deleteEssayAnswerById(@PathVariable Long essayAnswerId, - @AuthMemberPrincipal LoginMember member) { + public ResponseEntity deleteEssayAnswerById( + @PathVariable Long essayAnswerId, + @AuthMemberPrincipal LoginMember member + ) { essayAnswerService.deleteEssayAnswer(essayAnswerId, member.getId()); return ResponseEntity.noContent().build(); } - @GetMapping("/quizzes/{quizId}") - public ResponseEntity findQuizById(@PathVariable Long quizId, - @AuthMemberPrincipal LoginMember member) { - return ResponseEntity.ok(quizService.findById(quizId, member.getId())); - } - @GetMapping("/quizzes/{quizId}/essay-answers") public ResponseEntity> findAnswersByQuizId( - @PathVariable Long quizId) { + @PathVariable Long quizId + ) { List essayAnswers = essayAnswerService.findByQuizId(quizId); List responses = essayAnswers.stream().map(EssayAnswerResponse::of) @@ -94,5 +90,4 @@ public ResponseEntity> findAnswersByQuizId( return ResponseEntity.ok(responses); } - } diff --git a/backend/src/main/java/wooteco/prolog/roadmap/ui/QuizController.java b/backend/src/main/java/wooteco/prolog/roadmap/ui/QuizController.java index e95a5d9b5..fd3e0a597 100644 --- a/backend/src/main/java/wooteco/prolog/roadmap/ui/QuizController.java +++ b/backend/src/main/java/wooteco/prolog/roadmap/ui/QuizController.java @@ -41,7 +41,7 @@ public ResponseEntity findQuizById(@PathVariable Long quizId, return ResponseEntity.ok(quizService.findById(quizId, member.getId())); } - @GetMapping("/quizs/{quizId}") + @GetMapping("/quizzes/{quizId}") public ResponseEntity newFindQuizById( @PathVariable Long quizId, @AuthMemberPrincipal LoginMember member @@ -56,9 +56,9 @@ public ResponseEntity findQuizzesByKeyword(@PathVariable Long s return ResponseEntity.ok(quizService.findQuizzesByKeywordId(keywordId, member.getId())); } - @GetMapping("/quizs") + @GetMapping("/quizzes") public ResponseEntity newFindQuizzesByKeyword( - @RequestParam("keyword-id") Long keywordId, + @RequestParam("keywordId") Long keywordId, @AuthMemberPrincipal LoginMember member ) { return ResponseEntity.ok(quizService.findQuizzesByKeywordId(keywordId, member.getId()));