diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/CurriculumService.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminCurriculumService.java similarity index 94% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/application/CurriculumService.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminCurriculumService.java index f9ebcc9c7..b2f891efd 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/CurriculumService.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminCurriculumService.java @@ -13,11 +13,11 @@ @Transactional @Service -public class CurriculumService { +public class AdminCurriculumService { private final CurriculumRepository curriculumRepository; - public CurriculumService(CurriculumRepository repository) { + public AdminCurriculumService(CurriculumRepository repository) { this.curriculumRepository = repository; } diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/KeywordService.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminKeywordService.java similarity index 97% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/application/KeywordService.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminKeywordService.java index e6fe687ae..b0803b194 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/KeywordService.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminKeywordService.java @@ -18,12 +18,12 @@ @Transactional @Service -public class KeywordService { +public class AdminKeywordService { private final SessionRepository sessionRepository; private final KeywordRepository keywordRepository; - public KeywordService(final SessionRepository sessionRepository, + public AdminKeywordService(final SessionRepository sessionRepository, final KeywordRepository keywordRepository) { this.sessionRepository = sessionRepository; this.keywordRepository = keywordRepository; diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/NewSessionService.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminNewSessionService.java similarity index 98% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/application/NewSessionService.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminNewSessionService.java index 93b7219da..7bfdc237d 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/NewSessionService.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminNewSessionService.java @@ -17,7 +17,7 @@ @Transactional(readOnly = true) @RequiredArgsConstructor @Service -public class NewSessionService { +public class AdminNewSessionService { private final SessionRepository sessionRepository; diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/QuizService.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminQuizService.java similarity index 98% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/application/QuizService.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminQuizService.java index c44fbc139..f4868b5e6 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/QuizService.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminQuizService.java @@ -22,7 +22,7 @@ @Service @Transactional(readOnly = true) @AllArgsConstructor -public class QuizService { +public class AdminQuizService { private final KeywordRepository keywordRepository; private final QuizRepository quizRepository; diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/RecommendedPostService.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminRecommendedPostService.java similarity index 94% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/application/RecommendedPostService.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminRecommendedPostService.java index 1f7ee3172..652ebeaf4 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/RecommendedPostService.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/AdminRecommendedPostService.java @@ -15,12 +15,12 @@ @Transactional(readOnly = true) @Service -public class RecommendedPostService { +public class AdminRecommendedPostService { private final RecommendedPostRepository recommendedPostRepository; private final KeywordRepository keywordRepository; - public RecommendedPostService(final RecommendedPostRepository recommendedPostRepository, + public AdminRecommendedPostService(final RecommendedPostRepository recommendedPostRepository, final KeywordRepository keywordRepository) { this.recommendedPostRepository = recommendedPostRepository; this.keywordRepository = keywordRepository; diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/EssayAnswerService.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/EssayAnswerService.java deleted file mode 100644 index 22803269d..000000000 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/EssayAnswerService.java +++ /dev/null @@ -1,136 +0,0 @@ -package wooteco.prolog.admin.roadmap.application; - -import static wooteco.prolog.common.exception.BadRequestCode.CURRICULUM_NOT_FOUND_EXCEPTION; -import static wooteco.prolog.common.exception.BadRequestCode.ESSAY_ANSWER_NOT_FOUND_EXCEPTION; -import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_QUIZ_NOT_FOUND_EXCEPTION; -import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_SESSION_NOT_FOUND_EXCEPTION; - -import java.util.List; -import java.util.stream.Collectors; -import org.hibernate.Hibernate; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import wooteco.prolog.common.exception.BadRequestException; -import wooteco.prolog.member.application.MemberService; -import wooteco.prolog.member.domain.Member; -import wooteco.prolog.admin.roadmap.application.dto.EssayAnswerRequest; -import wooteco.prolog.admin.roadmap.application.dto.EssayAnswerSearchRequest; -import wooteco.prolog.admin.roadmap.application.dto.EssayAnswerUpdateRequest; -import wooteco.prolog.roadmap.domain.Curriculum; -import wooteco.prolog.roadmap.domain.EssayAnswer; -import wooteco.prolog.roadmap.domain.Quiz; -import wooteco.prolog.roadmap.domain.repository.CurriculumRepository; -import wooteco.prolog.roadmap.domain.repository.EssayAnswerRepository; -import wooteco.prolog.roadmap.domain.repository.EssayAnswerSpecification; -import wooteco.prolog.roadmap.domain.repository.QuizRepository; -import wooteco.prolog.session.domain.Session; -import wooteco.prolog.session.domain.repository.SessionRepository; -import wooteco.prolog.studylog.application.dto.EssayAnswersResponse; - -@Transactional -@Service -public class EssayAnswerService { - - private final EssayAnswerRepository essayAnswerRepository; - private final QuizRepository quizRepository; - private final MemberService memberService; - private final CurriculumRepository curriculumRepository; - private final SessionRepository sessionRepository; - - public EssayAnswerService( - EssayAnswerRepository essayAnswerRepository, - QuizRepository quizRepository, - MemberService memberService, - CurriculumRepository curriculumRepository, - SessionRepository sessionRepository) { - this.essayAnswerRepository = essayAnswerRepository; - this.quizRepository = quizRepository; - this.memberService = memberService; - this.curriculumRepository = curriculumRepository; - this.sessionRepository = sessionRepository; - } - - @Transactional - public Long createEssayAnswer(EssayAnswerRequest essayAnswerRequest, Long memberId) { - Long quizId = essayAnswerRequest.getQuizId(); - Quiz quiz = quizRepository.findById(quizId) - .orElseThrow(() -> new BadRequestException(ROADMAP_QUIZ_NOT_FOUND_EXCEPTION)); - - Member member = memberService.findById(memberId); - EssayAnswer essayAnswer = new EssayAnswer(quiz, essayAnswerRequest.getAnswer(), member); - essayAnswerRepository.save(essayAnswer); - - return essayAnswer.getId(); - } - - @Transactional - public void updateEssayAnswer(Long answerId, EssayAnswerUpdateRequest request, Long memberId) { - EssayAnswer essayAnswer = getById(answerId); - Member member = memberService.findById(memberId); - - essayAnswer.update(request.getAnswer(), member); - essayAnswerRepository.save(essayAnswer); - } - - @Transactional - public void deleteEssayAnswer(Long answerId, Long memberId) { - EssayAnswer essayAnswer = essayAnswerRepository.findByIdAndMemberId(answerId, memberId) - .orElseThrow(() -> new BadRequestException(ESSAY_ANSWER_NOT_FOUND_EXCEPTION)); - essayAnswerRepository.deleteById(essayAnswer.getId()); - } - - @Transactional(readOnly = true) - public EssayAnswer getById(Long answerId) { - EssayAnswer essayAnswer = essayAnswerRepository.findById(answerId) - .orElseThrow(() -> new BadRequestException(ESSAY_ANSWER_NOT_FOUND_EXCEPTION)); - Hibernate.initialize(essayAnswer.getQuiz()); - Hibernate.initialize(essayAnswer.getMember()); - - return essayAnswer; - } - - @Transactional(readOnly = true) - public List findByQuizId(Long quizId) { - List essayAnswers = essayAnswerRepository.findByQuizIdOrderByIdDesc(quizId); - essayAnswers.forEach(it -> { - Hibernate.initialize(it.getQuiz()); - Hibernate.initialize(it.getMember()); - }); - - return essayAnswers; - } - - public EssayAnswersResponse searchEssayAnswers( - final EssayAnswerSearchRequest request, - final Pageable pageable - ) { - - final Long curriculumId = request.getCurriculumId(); - - final Curriculum curriculum = curriculumRepository.findById(curriculumId) - .orElseThrow(() -> new BadRequestException(CURRICULUM_NOT_FOUND_EXCEPTION)); - - final List sessionIds = sessionRepository.findAllByCurriculumId(curriculum.getId()) - .stream() - .map(Session::getId) - .collect(Collectors.toList()); - - if (sessionIds.isEmpty()) { - throw new BadRequestException(ROADMAP_SESSION_NOT_FOUND_EXCEPTION); - } - - final Specification essayAnswerSpecification = EssayAnswerSpecification.equalsSessionIdsIn( - sessionIds) - .and(EssayAnswerSpecification.equalsKeywordId(request.getKeywordId())) - .and(EssayAnswerSpecification.inQuizIds(request.getQuizIds())) - .and(EssayAnswerSpecification.inMemberIds(request.getMemberIds())) - .and(EssayAnswerSpecification.orderByIdDesc()); - - final Page essayAnswers = essayAnswerRepository.findAll(essayAnswerSpecification, - pageable); - return EssayAnswersResponse.of(essayAnswers); - } -} diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/RoadMapService.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/RoadMapService.java deleted file mode 100644 index d71a48344..000000000 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/RoadMapService.java +++ /dev/null @@ -1,116 +0,0 @@ -package wooteco.prolog.admin.roadmap.application; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import wooteco.prolog.common.exception.BadRequestException; -import wooteco.prolog.admin.roadmap.application.dto.KeywordResponse; -import wooteco.prolog.admin.roadmap.application.dto.KeywordsResponse; -import wooteco.prolog.admin.roadmap.application.dto.RecommendedPostResponse; -import wooteco.prolog.roadmap.domain.Curriculum; -import wooteco.prolog.roadmap.domain.EssayAnswer; -import wooteco.prolog.roadmap.domain.Keyword; -import wooteco.prolog.roadmap.domain.Quiz; -import wooteco.prolog.roadmap.domain.repository.CurriculumRepository; -import wooteco.prolog.roadmap.domain.repository.EssayAnswerRepository; -import wooteco.prolog.roadmap.domain.repository.KeywordRepository; -import wooteco.prolog.roadmap.domain.repository.QuizRepository; -import wooteco.prolog.session.domain.Session; -import wooteco.prolog.session.domain.repository.SessionRepository; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static java.util.stream.Collectors.groupingBy; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; -import static wooteco.prolog.common.exception.BadRequestCode.CURRICULUM_NOT_FOUND_EXCEPTION; - -@RequiredArgsConstructor -@Transactional -@Service -public class RoadMapService { - - private final CurriculumRepository curriculumRepository; - private final SessionRepository sessionRepository; - private final KeywordRepository keywordRepository; - private final QuizRepository quizRepository; - private final EssayAnswerRepository essayAnswerRepository; - - @Transactional(readOnly = true) - public KeywordsResponse findAllKeywordsWithProgress(final Long curriculumId, final Long memberId) { - final Curriculum curriculum = curriculumRepository.findById(curriculumId) - .orElseThrow(() -> new BadRequestException(CURRICULUM_NOT_FOUND_EXCEPTION)); - - final List keywordsInCurriculum = getKeywordsInCurriculum(curriculum); - - final Map> quizzesInKeywords = quizRepository.findAll().stream() - .collect(groupingBy(Quiz::getKeyword, toSet())); - - return createResponsesWithProgress(keywordsInCurriculum, quizzesInKeywords, getDoneQuizzes(memberId)); - } - - private Set getDoneQuizzes(final Long memberId) { - return essayAnswerRepository.findAllByMemberId(memberId).stream() - .map(EssayAnswer::getQuiz) - .collect(toSet()); - } - - private List getKeywordsInCurriculum(final Curriculum curriculum) { - final Set sessionIds = sessionRepository.findAllByCurriculumId(curriculum.getId()) - .stream() - .map(Session::getId) - .collect(toSet()); - - return keywordRepository.findBySessionIdIn(sessionIds); - } - - private KeywordsResponse createResponsesWithProgress(final List keywords, - final Map> quizzesPerKeyword, - final Set doneQuizzes) { - final List keywordResponses = keywords.stream() - .filter(Keyword::isRoot) - .map(keyword -> createResponseWithProgress(keyword, quizzesPerKeyword, doneQuizzes)) - .collect(toList()); - - return new KeywordsResponse(keywordResponses); - } - - private KeywordResponse createResponseWithProgress(final Keyword keyword, - final Map> quizzesPerKeyword, - final Set doneQuizzes) { - final int totalQuizCount = quizzesPerKeyword.get(keyword).size(); - final int doneQuizCount = getDoneQuizCount(quizzesPerKeyword.get(keyword), doneQuizzes); - - final List recommendedPostResponses = keyword.getRecommendedPosts().stream() - .map(RecommendedPostResponse::from) - .collect(toList()); - - return new KeywordResponse( - keyword.getId(), - keyword.getName(), - keyword.getDescription(), - keyword.getSeq(), - keyword.getImportance(), - totalQuizCount, - doneQuizCount, - keyword.getParentIdOrNull(), - recommendedPostResponses, - createChildrenWithProgress(keyword.getChildren(), quizzesPerKeyword, doneQuizzes) - ); - } - - private int getDoneQuizCount(final Set quizzes, final Set doneQuizzes) { - quizzes.retainAll(doneQuizzes); - return quizzes.size(); - } - - private Set createChildrenWithProgress(final Set children, - final Map> quizzesPerKeyword, - final Set userAnswers) { - return children.stream() - .map(child -> createResponseWithProgress(child, quizzesPerKeyword, userAnswers)) - .collect(toSet()); - } -} diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerRequest.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerRequest.java deleted file mode 100644 index 48cc1f4ee..000000000 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package wooteco.prolog.admin.roadmap.application.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@AllArgsConstructor -@NoArgsConstructor -@Getter -public class EssayAnswerRequest { - - private Long quizId; - private String answer; -} diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerSearchRequest.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerSearchRequest.java deleted file mode 100644 index be9e4c78a..000000000 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerSearchRequest.java +++ /dev/null @@ -1,20 +0,0 @@ -package wooteco.prolog.admin.roadmap.application.dto; - -import java.util.List; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Setter -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -public class EssayAnswerSearchRequest { - - private Long curriculumId; - private Long keywordId; - private List quizIds; - private List memberIds; -} diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerUpdateRequest.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerUpdateRequest.java deleted file mode 100644 index 4774042b7..000000000 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/application/dto/EssayAnswerUpdateRequest.java +++ /dev/null @@ -1,12 +0,0 @@ -package wooteco.prolog.admin.roadmap.application.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -public final class EssayAnswerUpdateRequest { - private String answer; -} diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/CurriculumController.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminCurriculumController.java similarity index 70% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/ui/CurriculumController.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminCurriculumController.java index 0cffc8020..099493132 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/CurriculumController.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminCurriculumController.java @@ -10,42 +10,41 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import wooteco.prolog.admin.roadmap.application.CurriculumService; +import wooteco.prolog.admin.roadmap.application.AdminCurriculumService; import wooteco.prolog.admin.roadmap.application.dto.CurriculumRequest; import wooteco.prolog.admin.roadmap.application.dto.CurriculumResponses; @RestController -@RequestMapping("/curriculums") -public class CurriculumController { +@RequestMapping("/admin/curriculums") +public class AdminCurriculumController { - private final CurriculumService curriculumService; + private final AdminCurriculumService adminCurriculumService; - public CurriculumController(CurriculumService curriculumService) { - this.curriculumService = curriculumService; + public AdminCurriculumController(AdminCurriculumService adminCurriculumService) { + this.adminCurriculumService = adminCurriculumService; + } + + @GetMapping + public ResponseEntity findAll() { + return ResponseEntity.ok(adminCurriculumService.findCurriculums()); } @PostMapping public ResponseEntity createCurriculum(@RequestBody CurriculumRequest createRequest) { - Long curriculumId = curriculumService.create(createRequest); + Long curriculumId = adminCurriculumService.create(createRequest); return ResponseEntity.created(URI.create("/curriculums/" + curriculumId)).build(); } - @GetMapping - public ResponseEntity findAll() { - return ResponseEntity.ok(curriculumService.findCurriculums()); - } - @PutMapping("/{curriculumId}") public ResponseEntity updateCurriculum(@PathVariable Long curriculumId, @RequestBody CurriculumRequest createRequest) { - curriculumService.update(curriculumId, createRequest); + adminCurriculumService.update(curriculumId, createRequest); return ResponseEntity.noContent().build(); } @DeleteMapping("/{curriculumId}") public ResponseEntity deleteCurriculum(@PathVariable Long curriculumId) { - curriculumService.delete(curriculumId); + adminCurriculumService.delete(curriculumId); return ResponseEntity.noContent().build(); } - } diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/KeywordController.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminKeywordController.java similarity index 70% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/ui/KeywordController.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminKeywordController.java index 628300b63..372caee7f 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/KeywordController.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminKeywordController.java @@ -10,63 +10,63 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import wooteco.prolog.admin.roadmap.application.KeywordService; +import wooteco.prolog.admin.roadmap.application.AdminKeywordService; import wooteco.prolog.admin.roadmap.application.dto.KeywordCreateRequest; import wooteco.prolog.admin.roadmap.application.dto.KeywordResponse; import wooteco.prolog.admin.roadmap.application.dto.KeywordUpdateRequest; import wooteco.prolog.admin.roadmap.application.dto.KeywordsResponse; @RestController -@RequestMapping("/sessions/{sessionId}/keywords") -public class KeywordController { +@RequestMapping("/admin/sessions/{sessionId}/keywords") +public class AdminKeywordController { - private final KeywordService keywordService; + private final AdminKeywordService adminKeywordService; - public KeywordController(final KeywordService keywordService) { - this.keywordService = keywordService; + public AdminKeywordController(final AdminKeywordService adminKeywordService) { + this.adminKeywordService = adminKeywordService; } - @PostMapping - public ResponseEntity createKeyword(@PathVariable Long sessionId, - @RequestBody KeywordCreateRequest createRequest) { - Long keywordId = keywordService.createKeyword(sessionId, createRequest); - return ResponseEntity.created( - URI.create("/sessions/" + sessionId + "/keywords/" + keywordId)).build(); + @GetMapping + public ResponseEntity findSessionIncludeRootKeywords( + @PathVariable Long sessionId) { + KeywordsResponse response = adminKeywordService.findSessionIncludeRootKeywords(sessionId); + return ResponseEntity.ok(response); } @GetMapping("/{keywordId}") public ResponseEntity findKeyword(@PathVariable Long sessionId, - @PathVariable Long keywordId) { - KeywordResponse response = keywordService.findKeyword(sessionId, keywordId); + @PathVariable Long keywordId) { + KeywordResponse response = adminKeywordService.findKeyword(sessionId, keywordId); + return ResponseEntity.ok(response); + } + + @GetMapping("/{keywordId}/children") + public ResponseEntity find(@PathVariable Long sessionId, + @PathVariable Long keywordId) { + KeywordResponse response = adminKeywordService.findKeywordWithAllChild(sessionId, keywordId); return ResponseEntity.ok(response); } + @PostMapping + public ResponseEntity createKeyword(@PathVariable Long sessionId, + @RequestBody KeywordCreateRequest createRequest) { + Long keywordId = adminKeywordService.createKeyword(sessionId, createRequest); + return ResponseEntity.created( + URI.create("/sessions/" + sessionId + "/keywords/" + keywordId)).build(); + } + @PutMapping("/{keywordId}") public ResponseEntity updateKeyword(@PathVariable Long sessionId, @PathVariable Long keywordId, @RequestBody KeywordUpdateRequest updateRequest) { - keywordService.updateKeyword(sessionId, keywordId, updateRequest); + adminKeywordService.updateKeyword(sessionId, keywordId, updateRequest); return ResponseEntity.noContent().build(); } @DeleteMapping("/{keywordId}") public ResponseEntity deleteKeyword(@PathVariable Long sessionId, @PathVariable Long keywordId) { - keywordService.deleteKeyword(sessionId, keywordId); + adminKeywordService.deleteKeyword(sessionId, keywordId); return ResponseEntity.noContent().build(); } - - @GetMapping - public ResponseEntity findSessionIncludeRootKeywords( - @PathVariable Long sessionId) { - KeywordsResponse response = keywordService.findSessionIncludeRootKeywords(sessionId); - return ResponseEntity.ok(response); - } - - @GetMapping("/{keywordId}/children") - public ResponseEntity find(@PathVariable Long sessionId, - @PathVariable Long keywordId) { - KeywordResponse response = keywordService.findKeywordWithAllChild(sessionId, keywordId); - return ResponseEntity.ok(response); - } } diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/NewSessionController.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminNewSessionController.java similarity index 90% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/ui/NewSessionController.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminNewSessionController.java index 5a69169af..6b73aa897 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/NewSessionController.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminNewSessionController.java @@ -11,16 +11,23 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import wooteco.prolog.admin.roadmap.application.NewSessionService; +import wooteco.prolog.admin.roadmap.application.AdminNewSessionService; import wooteco.prolog.admin.roadmap.application.dto.SessionRequest; import wooteco.prolog.admin.roadmap.application.dto.SessionsResponse; @RequiredArgsConstructor @RestController -@RequestMapping("/curriculums/{curriculumId}/sessions") -public class NewSessionController { +@RequestMapping("/admin/curriculums/{curriculumId}/sessions") +public class AdminNewSessionController { - private final NewSessionService sessionService; + private final AdminNewSessionService sessionService; + + @GetMapping + public ResponseEntity findSessions(@PathVariable Long curriculumId) { + SessionsResponse response = sessionService.findSessions(curriculumId); + + return ResponseEntity.ok(response); + } @PostMapping public ResponseEntity createSession(@PathVariable Long curriculumId, @@ -30,13 +37,6 @@ public ResponseEntity createSession(@PathVariable Long curriculumId, return ResponseEntity.created(URI.create("/sessions/" + sessionId)).build(); } - @GetMapping - public ResponseEntity findSessions(@PathVariable Long curriculumId) { - SessionsResponse response = sessionService.findSessions(curriculumId); - - return ResponseEntity.ok(response); - } - @PutMapping("/{sessionId}") public ResponseEntity updateSession(@PathVariable Long curriculumId, @PathVariable Long sessionId, diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/QuizController.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminQuizController.java similarity index 65% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/ui/QuizController.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminQuizController.java index 33534963b..709de58eb 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/QuizController.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminQuizController.java @@ -13,48 +13,40 @@ import org.springframework.web.bind.annotation.RestController; import wooteco.prolog.login.domain.AuthMemberPrincipal; import wooteco.prolog.login.ui.LoginMember; -import wooteco.prolog.admin.roadmap.application.QuizService; +import wooteco.prolog.admin.roadmap.application.AdminQuizService; import wooteco.prolog.admin.roadmap.application.dto.QuizRequest; -import wooteco.prolog.admin.roadmap.application.dto.QuizResponse; import wooteco.prolog.admin.roadmap.application.dto.QuizzesResponse; @RestController @AllArgsConstructor -@RequestMapping("/sessions/{sessionId}/keywords/{keywordId}/quizs") -public class QuizController { +@RequestMapping("/admin/sessions/{sessionId}/keywords/{keywordId}/quizs") +public class AdminQuizController { - private final QuizService quizService; + private final AdminQuizService adminQuizService; + + @GetMapping + public ResponseEntity findQuizzesByKeyword(@PathVariable Long sessionId, + @PathVariable Long keywordId, + @AuthMemberPrincipal LoginMember member) { + return ResponseEntity.ok(adminQuizService.findQuizzesByKeywordId(keywordId, member.getId())); + } - //: todo admin login 생기면 검증 추가 @PostMapping public ResponseEntity create(@PathVariable Long sessionId, @PathVariable Long keywordId, @RequestBody QuizRequest quizRequest) { - final Long quizId = quizService.createQuiz(keywordId, quizRequest); + final Long quizId = adminQuizService.createQuiz(keywordId, quizRequest); return ResponseEntity.created( URI.create("/sessions/" + sessionId + "/keywords/" + keywordId + "/quizs/" + quizId)) .build(); } - @GetMapping("/{quizId}") - public ResponseEntity findQuizById(@PathVariable Long quizId, - @AuthMemberPrincipal LoginMember member) { - return ResponseEntity.ok(quizService.findById(quizId, member.getId())); - } - - @GetMapping - public ResponseEntity findQuizzesByKeyword(@PathVariable Long sessionId, - @PathVariable Long keywordId, - @AuthMemberPrincipal LoginMember member) { - return ResponseEntity.ok(quizService.findQuizzesByKeywordId(keywordId, member.getId())); - } - @PutMapping("/{quizId}") ResponseEntity updateQuiz(@PathVariable Long sessionId, @PathVariable Long keywordId, @PathVariable Long quizId, @RequestBody QuizRequest quizRequest) { - quizService.updateQuiz(quizId, quizRequest); + adminQuizService.updateQuiz(quizId, quizRequest); return ResponseEntity.noContent().build(); } @@ -63,7 +55,7 @@ ResponseEntity updateQuiz(@PathVariable Long sessionId, public ResponseEntity deleteQuiz(@PathVariable Long sessionId, @PathVariable Long keywordId, @PathVariable Long quizId) { - quizService.deleteQuiz(quizId); + adminQuizService.deleteQuiz(quizId); return ResponseEntity.noContent().build(); } } diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/RecommendedController.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminRecommendedController.java similarity index 74% rename from backend/src/main/java/wooteco/prolog/admin/roadmap/ui/RecommendedController.java rename to backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminRecommendedController.java index 7614c3a5c..d28a467b7 100644 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/RecommendedController.java +++ b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/AdminRecommendedController.java @@ -9,24 +9,24 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import wooteco.prolog.admin.roadmap.application.RecommendedPostService; +import wooteco.prolog.admin.roadmap.application.AdminRecommendedPostService; import wooteco.prolog.admin.roadmap.application.dto.RecommendedRequest; import wooteco.prolog.admin.roadmap.application.dto.RecommendedUpdateRequest; @RestController -@RequestMapping("/keywords/{keywordId}/recommended-posts") -public class RecommendedController { +@RequestMapping("/admin/keywords/{keywordId}/recommended-posts") +public class AdminRecommendedController { - private final RecommendedPostService recommendedPostService; + private final AdminRecommendedPostService adminRecommendedPostService; - public RecommendedController(final RecommendedPostService recommendedPostService) { - this.recommendedPostService = recommendedPostService; + public AdminRecommendedController(final AdminRecommendedPostService adminRecommendedPostService) { + this.adminRecommendedPostService = adminRecommendedPostService; } @PostMapping public ResponseEntity createRecommendedPost(@PathVariable("keywordId") final Long keywordId, @RequestBody final RecommendedRequest request) { - recommendedPostService.create(keywordId, request); + adminRecommendedPostService.create(keywordId, request); return ResponseEntity.status(HttpStatus.CREATED).build(); } @@ -34,14 +34,14 @@ public ResponseEntity createRecommendedPost(@PathVariable("keywordId") fin public ResponseEntity updateRecommendedPost(@PathVariable("keywordId") final Long keywordId, @PathVariable("recommendedId") final Long recommendedId, @RequestBody final RecommendedUpdateRequest request) { - recommendedPostService.update(recommendedId, request); + adminRecommendedPostService.update(recommendedId, request); return ResponseEntity.noContent().build(); } @DeleteMapping("/{recommendedId}") public ResponseEntity deleteRecommendedPost(@PathVariable("keywordId") final Long keywordId, @PathVariable("recommendedId") final Long recommendedId) { - recommendedPostService.delete(recommendedId); + adminRecommendedPostService.delete(recommendedId); return ResponseEntity.noContent().build(); } } diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/EssayAnswerController.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/EssayAnswerController.java deleted file mode 100644 index a325dfb9f..000000000 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/EssayAnswerController.java +++ /dev/null @@ -1,98 +0,0 @@ -package wooteco.prolog.admin.roadmap.ui; - -import static java.util.stream.Collectors.toList; - -import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Pageable; -import org.springframework.data.web.PageableDefault; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import wooteco.prolog.login.domain.AuthMemberPrincipal; -import wooteco.prolog.login.ui.LoginMember; -import wooteco.prolog.admin.roadmap.application.EssayAnswerService; -import wooteco.prolog.admin.roadmap.application.QuizService; -import wooteco.prolog.admin.roadmap.application.dto.EssayAnswerRequest; -import wooteco.prolog.admin.roadmap.application.dto.EssayAnswerResponse; -import wooteco.prolog.admin.roadmap.application.dto.EssayAnswerSearchRequest; -import wooteco.prolog.admin.roadmap.application.dto.EssayAnswerUpdateRequest; -import wooteco.prolog.admin.roadmap.application.dto.QuizResponse; -import wooteco.prolog.roadmap.domain.EssayAnswer; -import wooteco.prolog.studylog.application.dto.EssayAnswersResponse; - - -@RestController -@RequestMapping -public class EssayAnswerController { - - private final EssayAnswerService essayAnswerService; - private final QuizService quizService; - - @Autowired - public EssayAnswerController(EssayAnswerService essayAnswerService, - QuizService quizService) { - this.essayAnswerService = essayAnswerService; - this.quizService = quizService; - } - - @PostMapping("/essay-answers") - public ResponseEntity create(@RequestBody EssayAnswerRequest request, - @AuthMemberPrincipal LoginMember member) { - - return ResponseEntity.ok(essayAnswerService.createEssayAnswer(request, member.getId())); - } - - @GetMapping("/essay-answers") - public ResponseEntity search( - EssayAnswerSearchRequest request, - @PageableDefault Pageable pageable) { - return ResponseEntity.ok(essayAnswerService.searchEssayAnswers(request, pageable)); - } - - @GetMapping("/essay-answers/{essayAnswerId}") - public ResponseEntity findById(@PathVariable Long essayAnswerId) { - EssayAnswer essayAnswer = essayAnswerService.getById(essayAnswerId); - EssayAnswerResponse response = EssayAnswerResponse.of(essayAnswer); - return ResponseEntity.ok(response); - } - - @PatchMapping("/essay-answers/{essayAnswerId}") - public ResponseEntity updateById(@PathVariable Long essayAnswerId, - @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) { - 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) { - - List essayAnswers = essayAnswerService.findByQuizId(quizId); - List responses = essayAnswers.stream().map(EssayAnswerResponse::of) - .collect(toList()); - - return ResponseEntity.ok(responses); - } - -} diff --git a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/RoadmapController.java b/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/RoadmapController.java deleted file mode 100644 index 48e5f4863..000000000 --- a/backend/src/main/java/wooteco/prolog/admin/roadmap/ui/RoadmapController.java +++ /dev/null @@ -1,23 +0,0 @@ -package wooteco.prolog.admin.roadmap.ui; - -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import wooteco.prolog.login.domain.AuthMemberPrincipal; -import wooteco.prolog.login.ui.LoginMember; -import wooteco.prolog.admin.roadmap.application.RoadMapService; -import wooteco.prolog.admin.roadmap.application.dto.KeywordsResponse; - -@RequiredArgsConstructor -@RestController -public class RoadmapController { - - private final RoadMapService roadMapService; - - @GetMapping("/roadmaps") - public KeywordsResponse findRoadMapKeyword(@AuthMemberPrincipal final LoginMember member, - @RequestParam final Long curriculumId) { - return roadMapService.findAllKeywordsWithProgress(curriculumId, member.getId()); - } -} diff --git a/backend/src/test/java/wooteco/prolog/roadmap/application/CurriculumServiceTest.java b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminCurriculumServiceTest.java similarity index 99% rename from backend/src/test/java/wooteco/prolog/roadmap/application/CurriculumServiceTest.java rename to backend/src/test/java/wooteco/prolog/roadmap/application/AdminCurriculumServiceTest.java index 629980719..69e3d6e7d 100644 --- a/backend/src/test/java/wooteco/prolog/roadmap/application/CurriculumServiceTest.java +++ b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminCurriculumServiceTest.java @@ -24,7 +24,7 @@ import wooteco.prolog.roadmap.domain.repository.CurriculumRepository; @ExtendWith(MockitoExtension.class) -class CurriculumServiceTest { +class AdminCurriculumServiceTest { @InjectMocks private CurriculumService curriculumService; diff --git a/backend/src/test/java/wooteco/prolog/roadmap/application/KeywordServiceTest.java b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminKeywordServiceTest.java similarity index 99% rename from backend/src/test/java/wooteco/prolog/roadmap/application/KeywordServiceTest.java rename to backend/src/test/java/wooteco/prolog/roadmap/application/AdminKeywordServiceTest.java index 2bb5f86ec..d366a528d 100644 --- a/backend/src/test/java/wooteco/prolog/roadmap/application/KeywordServiceTest.java +++ b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminKeywordServiceTest.java @@ -21,7 +21,7 @@ import static wooteco.prolog.common.exception.BadRequestCode.ROADMAP_KEYWORD_NOT_FOUND_EXCEPTION; @ExtendWith(MockitoExtension.class) -class KeywordServiceTest { +class AdminKeywordServiceTest { @InjectMocks private KeywordService keywordService; diff --git a/backend/src/test/java/wooteco/prolog/roadmap/application/QuizServiceTest.java b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminQuizServiceTest.java similarity index 99% rename from backend/src/test/java/wooteco/prolog/roadmap/application/QuizServiceTest.java rename to backend/src/test/java/wooteco/prolog/roadmap/application/AdminQuizServiceTest.java index 964b437ff..ce2836e74 100644 --- a/backend/src/test/java/wooteco/prolog/roadmap/application/QuizServiceTest.java +++ b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminQuizServiceTest.java @@ -32,7 +32,7 @@ import wooteco.prolog.roadmap.domain.repository.QuizRepository; @ExtendWith(MockitoExtension.class) -class QuizServiceTest { +class AdminQuizServiceTest { @Mock private KeywordRepository keywordRepository; diff --git a/backend/src/test/java/wooteco/prolog/roadmap/application/RecommendedPostServiceTest.java b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminRecommendedPostServiceTest.java similarity index 98% rename from backend/src/test/java/wooteco/prolog/roadmap/application/RecommendedPostServiceTest.java rename to backend/src/test/java/wooteco/prolog/roadmap/application/AdminRecommendedPostServiceTest.java index 5f3932c58..cf6ee2359 100644 --- a/backend/src/test/java/wooteco/prolog/roadmap/application/RecommendedPostServiceTest.java +++ b/backend/src/test/java/wooteco/prolog/roadmap/application/AdminRecommendedPostServiceTest.java @@ -20,7 +20,7 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; @SpringBootTest -class RecommendedPostServiceTest { +class AdminRecommendedPostServiceTest { @Autowired private RecommendedPostService recommendedPostService;