diff --git a/application/src/main/java/com/comssa/api/question/service/rest/common/implement/BasicQuestionSelectorService.java b/application/src/main/java/com/comssa/api/question/service/rest/common/implement/BasicQuestionSelectorService.java index a0b298f..9d3d666 100644 --- a/application/src/main/java/com/comssa/api/question/service/rest/common/implement/BasicQuestionSelectorService.java +++ b/application/src/main/java/com/comssa/api/question/service/rest/common/implement/BasicQuestionSelectorService.java @@ -8,8 +8,8 @@ import com.comssa.persistence.question.domain.license.LicenseCategory; import com.comssa.persistence.question.domain.license.LicenseSession; import com.comssa.persistence.question.repository.jpa.LicenseSessionRepository; -import com.comssa.persistence.question.repository.querydsl.LicenseMultipleChoiceQuestionDslRepository; -import com.comssa.persistence.question.repository.querydsl.MajorMultipleChoiceQuestionDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.LicenseMultipleChoiceQuestionDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.MajorMultipleChoiceQuestionDslRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -56,10 +56,10 @@ public List getLicenseSessions(LicenseCategory licenseCategory) public List getAllQuestions(List questionCategories, boolean multipleChoice) { List questions = new ArrayList<>(); if (multipleChoice) { - questions.addAll(licenseMultipleChoiceQuestionDslRepository.findAllWhereQuestionCategories( + questions.addAll(licenseMultipleChoiceQuestionDslRepository.findAllWhereCategories( questionCategories)); questions.addAll(majorMultipleChoiceQuestionDslRepository - .findAllWhereQuestionCategories( + .findAllWhereCategories( questionCategories)); } return questions; diff --git a/application/src/main/java/com/comssa/api/question/service/rest/license/implement/AdminLicenseQuestionGetService.java b/application/src/main/java/com/comssa/api/question/service/rest/license/implement/AdminLicenseQuestionGetService.java index dfee091..fb74cdf 100644 --- a/application/src/main/java/com/comssa/api/question/service/rest/license/implement/AdminLicenseQuestionGetService.java +++ b/application/src/main/java/com/comssa/api/question/service/rest/license/implement/AdminLicenseQuestionGetService.java @@ -6,7 +6,7 @@ import com.comssa.persistence.question.domain.common.Question; import com.comssa.persistence.question.domain.common.QuestionCategory; import com.comssa.persistence.question.domain.license.LicenseMultipleChoiceQuestion; -import com.comssa.persistence.question.repository.querydsl.LicenseMultipleChoiceQuestionDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.LicenseMultipleChoiceQuestionDslRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,19 +19,19 @@ @RequiredArgsConstructor public class AdminLicenseQuestionGetService implements LicenseQuestionGetService { - private final LicenseMultipleChoiceQuestionDslRepository licenseMultipleChoiceQuestionDslRepository; - private final QuestionClassifyByCategoryService questionClassifyByCategoryService; + private final LicenseMultipleChoiceQuestionDslRepository licenseMultipleChoiceQuestionDslRepository; + private final QuestionClassifyByCategoryService questionClassifyByCategoryService; - /** - * 관리자 조회시 허용 여부와 관련 없이 모든 문제를 가져온다. - * 문제지도 섞지 않는다. - * 허용 여부 순대로 섞는다 - */ - @Override - public Map> getClassifiedLicenseMultipleChoiceQuestion( - Long sessionId) { - List licenseMultipleChoiceQuestions = licenseMultipleChoiceQuestionDslRepository - .findAllWhereLicenseSessionId(sessionId); - return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(licenseMultipleChoiceQuestions); - } + /** + * 관리자 조회시 허용 여부와 관련 없이 모든 문제를 가져온다. + * 문제지도 섞지 않는다. + * 허용 여부 순대로 섞는다 + */ + @Override + public Map> getClassifiedLicenseMultipleChoiceQuestion( + Long sessionId) { + List licenseMultipleChoiceQuestions = licenseMultipleChoiceQuestionDslRepository + .findAllWhereLicenseSessionId(sessionId); + return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(licenseMultipleChoiceQuestions); + } } diff --git a/application/src/main/java/com/comssa/api/question/service/rest/license/implement/UserLicenseQuestionGetService.java b/application/src/main/java/com/comssa/api/question/service/rest/license/implement/UserLicenseQuestionGetService.java index 30e7d06..3d55ec4 100644 --- a/application/src/main/java/com/comssa/api/question/service/rest/license/implement/UserLicenseQuestionGetService.java +++ b/application/src/main/java/com/comssa/api/question/service/rest/license/implement/UserLicenseQuestionGetService.java @@ -6,7 +6,7 @@ import com.comssa.persistence.question.domain.common.Question; import com.comssa.persistence.question.domain.common.QuestionCategory; import com.comssa.persistence.question.domain.license.LicenseMultipleChoiceQuestion; -import com.comssa.persistence.question.repository.querydsl.LicenseMultipleChoiceQuestionDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.LicenseMultipleChoiceQuestionDslRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/application/src/main/java/com/comssa/api/question/service/rest/major/AdminMajorQuestionMakeService.java b/application/src/main/java/com/comssa/api/question/service/rest/major/AdminMajorQuestionMakeService.java index f9f6fc0..3914bee 100644 --- a/application/src/main/java/com/comssa/api/question/service/rest/major/AdminMajorQuestionMakeService.java +++ b/application/src/main/java/com/comssa/api/question/service/rest/major/AdminMajorQuestionMakeService.java @@ -17,7 +17,7 @@ List makeMultipleChoiceQuestions( List requestNormalQuestionDto); MajorMultipleChoiceQuestion makeMultipleChoiceQuestion( - RequestMakeMultipleChoiceQuestionDto requestNormalQuestionDto) throws DuplicateQuestionContentException, DuplicateQuestionContentException; + RequestMakeMultipleChoiceQuestionDto requestNormalQuestionDto) throws DuplicateQuestionContentException; List makeDescriptiveQuestions( List requestNormalQuestionDto diff --git a/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionClassifiedGetService.java b/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionClassifiedGetService.java index 670f3ed..9fb7237 100644 --- a/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionClassifiedGetService.java +++ b/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionClassifiedGetService.java @@ -7,8 +7,8 @@ import com.comssa.persistence.question.domain.common.QuestionCategory; import com.comssa.persistence.question.domain.major.MajorDescriptiveQuestion; import com.comssa.persistence.question.domain.major.MajorMultipleChoiceQuestion; -import com.comssa.persistence.question.repository.querydsl.MajorDescriptiveDslRepository; -import com.comssa.persistence.question.repository.querydsl.MajorMultipleChoiceQuestionDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.MajorDescriptiveDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.MajorMultipleChoiceQuestionDslRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,27 +20,27 @@ @RequiredArgsConstructor @Transactional public class BasicAdminMajorQuestionClassifiedGetService implements AdminMajorQuestionClassifiedGetService { - private final QuestionClassifyByCategoryService questionClassifyByCategoryService; - private final MajorDescriptiveDslRepository majorDescriptiveQuestionChooseRepository; - private final MajorMultipleChoiceQuestionDslRepository majorMultipleChoiceQuestionDslRepository; + private final QuestionClassifyByCategoryService questionClassifyByCategoryService; + private final MajorDescriptiveDslRepository majorDescriptiveQuestionChooseRepository; + private final MajorMultipleChoiceQuestionDslRepository majorMultipleChoiceQuestionDslRepository; - /** - * 관리자가 조회시 Approve됐는지 기준으로 정렬되며(false인 것부터), - * 이후엔 객관식 -> 주관식으로 정렬된다. - * - * @return - */ - @Override - public Map> getClassifiedAllMajorMultipleChoiceQuestions() { - List majorMultipleChoiceQuestions = majorMultipleChoiceQuestionDslRepository - .findAllOrderByIfApprovedAsc(); - return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorMultipleChoiceQuestions); - } + /** + * 관리자가 조회시 Approve됐는지 기준으로 정렬되며(false인 것부터), + * 이후엔 객관식 -> 주관식으로 정렬된다. + * + * @return + */ + @Override + public Map> getClassifiedAllMajorMultipleChoiceQuestions() { + List majorMultipleChoiceQuestions = majorMultipleChoiceQuestionDslRepository + .findAllOrderByIfApprovedAsc(); + return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorMultipleChoiceQuestions); + } - @Override - public Map> getClassifiedAllMajorDescriptiveQuestions() { - List majorDescriptiveQuestions = - majorDescriptiveQuestionChooseRepository.findAllOrderByIfApprovedAsc(); - return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorDescriptiveQuestions); - } + @Override + public Map> getClassifiedAllMajorDescriptiveQuestions() { + List majorDescriptiveQuestions = + majorDescriptiveQuestionChooseRepository.findAllOrderByIfApprovedAsc(); + return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorDescriptiveQuestions); + } } diff --git a/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionMakeService.java b/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionMakeService.java index ef2f13f..4c8eab5 100644 --- a/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionMakeService.java +++ b/application/src/main/java/com/comssa/api/question/service/rest/major/implement/BasicAdminMajorQuestionMakeService.java @@ -22,74 +22,74 @@ @Transactional public class BasicAdminMajorQuestionMakeService implements AdminMajorQuestionMakeService { - private final QuestionRepository questionRepository; - private final MajorMultipleChoiceQuestionRepository majorMultipleChoiceQuestionRepository; - private final QuestionChoiceService questionChoiceService; - private final DuplicateQuestionDetector duplicateQuestionDetector; + private final QuestionRepository questionRepository; + private final MajorMultipleChoiceQuestionRepository majorMultipleChoiceQuestionRepository; + private final QuestionChoiceService questionChoiceService; + private final DuplicateQuestionDetector duplicateQuestionDetector; - /** - * 리스트로 생성 - */ - @Override - public List makeMultipleChoiceQuestions( - List requestDtos) { - // 중복되지 않은 질문을 필터링하여 저장 - return requestDtos.stream() - .filter(this::isNotDuplicateQuestion) - .map(this::saveMajorMultipleChoiceQuestion) - .collect(Collectors.toList()); - } + /** + * 리스트로 생성 + */ + @Override + public List makeMultipleChoiceQuestions( + List requestDtos) { + // 중복되지 않은 질문을 필터링하여 저장 + return requestDtos.stream() + .filter(this::isNotDuplicateQuestion) + .map(this::saveMajorMultipleChoiceQuestion) + .collect(Collectors.toList()); + } - /** - * 단일 생성 - */ - @Override - public MajorMultipleChoiceQuestion makeMultipleChoiceQuestion( - RequestMakeMultipleChoiceQuestionDto requestDto) throws DuplicateQuestionContentException { - if (!isNotDuplicateQuestion(requestDto)) { - throw new DuplicateQuestionContentException(); - } - return saveMajorMultipleChoiceQuestion(requestDto); - } + /** + * 단일 생성 + */ + @Override + public MajorMultipleChoiceQuestion makeMultipleChoiceQuestion( + RequestMakeMultipleChoiceQuestionDto requestDto) throws DuplicateQuestionContentException { + if (!isNotDuplicateQuestion(requestDto)) { + throw new DuplicateQuestionContentException(); + } + return saveMajorMultipleChoiceQuestion(requestDto); + } - @Override - public List makeDescriptiveQuestions( - List requestNormalQuestionDto) { + @Override + public List makeDescriptiveQuestions( + List requestNormalQuestionDto) { - return requestNormalQuestionDto.stream() - .map(this::saveMajorDescriptiveQuestion) - .collect(Collectors.toList()); - } + return requestNormalQuestionDto.stream() + .map(this::saveMajorDescriptiveQuestion) + .collect(Collectors.toList()); + } - /** - * 중복되지 않은 질문인지 확인하는 메서드 - * 매번 DB에서 새롭게 조회 후 검증한다.(DTO 자체의 중복된 데이터) - */ - private boolean isNotDuplicateQuestion(RequestMakeMultipleChoiceQuestionDto requestDto) { - return majorMultipleChoiceQuestionRepository.findAll().stream() - .noneMatch(existingQuestion -> duplicateQuestionDetector.isQuestionDuplicate( - existingQuestion.getContent(), requestDto.getContent())); - } + /** + * 중복되지 않은 질문인지 확인하는 메서드 + * 매번 DB에서 새롭게 조회 후 검증한다.(DTO 자체의 중복된 데이터) + */ + private boolean isNotDuplicateQuestion(RequestMakeMultipleChoiceQuestionDto requestDto) { + return majorMultipleChoiceQuestionRepository.findAll().stream() + .noneMatch(existingQuestion -> duplicateQuestionDetector.isQuestionDuplicate( + existingQuestion.getContent(), requestDto.getContent())); + } - /** - * 새로운 질문을 저장하고 선택지를 저장하는 메서드 - */ - private MajorMultipleChoiceQuestion saveMajorMultipleChoiceQuestion( - RequestMakeMultipleChoiceQuestionDto requestDto) { - MajorMultipleChoiceQuestion question = MajorMultipleChoiceQuestion.makeWithDto(requestDto); - questionRepository.save(question); - questionChoiceService.saveWith(requestDto, question); - return question; - } + /** + * 새로운 질문을 저장하고 선택지를 저장하는 메서드 + */ + private MajorMultipleChoiceQuestion saveMajorMultipleChoiceQuestion( + RequestMakeMultipleChoiceQuestionDto requestDto) { + MajorMultipleChoiceQuestion question = MajorMultipleChoiceQuestion.makeWithDto(requestDto); + questionRepository.save(question); + questionChoiceService.saveWith(requestDto, question); + return question; + } - private MajorDescriptiveQuestion saveMajorDescriptiveQuestion( - RequestMakeMajorDescriptiveQuestionDto requestDto - ) { - MajorDescriptiveQuestion question = MajorDescriptiveQuestion.makeWithDto( - requestDto - ); - questionRepository.save(question); - return question; - } + private MajorDescriptiveQuestion saveMajorDescriptiveQuestion( + RequestMakeMajorDescriptiveQuestionDto requestDto + ) { + MajorDescriptiveQuestion question = MajorDescriptiveQuestion.makeWithDto( + requestDto + ); + questionRepository.save(question); + return question; + } } diff --git a/application/src/main/java/com/comssa/api/question/service/rest/major/implement/UserMajorQuestionClassifiedGetService.java b/application/src/main/java/com/comssa/api/question/service/rest/major/implement/UserMajorQuestionClassifiedGetService.java index 2573ddd..bba3ae7 100644 --- a/application/src/main/java/com/comssa/api/question/service/rest/major/implement/UserMajorQuestionClassifiedGetService.java +++ b/application/src/main/java/com/comssa/api/question/service/rest/major/implement/UserMajorQuestionClassifiedGetService.java @@ -8,8 +8,8 @@ import com.comssa.persistence.question.domain.major.MajorDescriptiveQuestion; import com.comssa.persistence.question.domain.major.MajorMultipleChoiceQuestion; import com.comssa.persistence.question.dto.major.request.RequestGetQuestionByCategoryAndLevelDto; -import com.comssa.persistence.question.repository.querydsl.MajorDescriptiveDslRepository; -import com.comssa.persistence.question.repository.querydsl.MajorMultipleChoiceQuestionDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.MajorDescriptiveDslRepository; +import com.comssa.persistence.question.repository.querydsl.impl.MajorMultipleChoiceQuestionDslRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,41 +20,41 @@ @Service @RequiredArgsConstructor public class UserMajorQuestionClassifiedGetService implements MajorQuestionClassifiedGetService { - private final MajorMultipleChoiceQuestionDslRepository majorMultipleChoiceQuestionDslRepository; - private final QuestionClassifyByCategoryService questionClassifyByCategoryService; - private final MajorDescriptiveDslRepository majorDescriptiveQuestionDslRepository; + private final MajorMultipleChoiceQuestionDslRepository majorMultipleChoiceQuestionDslRepository; + private final QuestionClassifyByCategoryService questionClassifyByCategoryService; + private final MajorDescriptiveDslRepository majorDescriptiveQuestionDslRepository; - /** - * 분야, 난이도 파라미터로 문제를 조회하는 경우 - 객관식. - * 문제 선택지들을 섞어준다. - */ - @Override - public Map> getApprovedClassifiedMajorMultipleChoiceQuestions( - RequestGetQuestionByCategoryAndLevelDto requestGetQuestionByCategoryAndLevelDto) { - List majorMultipleChoiceQuestions = majorMultipleChoiceQuestionDslRepository - .findAllWhereCategoriesAndLevelsAndIfApproved( - requestGetQuestionByCategoryAndLevelDto.getQuestionCategories(), - requestGetQuestionByCategoryAndLevelDto.getQuestionLevels(), - true); - for (MajorMultipleChoiceQuestion question : majorMultipleChoiceQuestions) { - Collections.shuffle(question.getQuestionChoices()); - } - return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorMultipleChoiceQuestions); - } + /** + * 분야, 난이도 파라미터로 문제를 조회하는 경우 - 객관식. + * 문제 선택지들을 섞어준다. + */ + @Override + public Map> getApprovedClassifiedMajorMultipleChoiceQuestions( + RequestGetQuestionByCategoryAndLevelDto requestGetQuestionByCategoryAndLevelDto) { + List majorMultipleChoiceQuestions = majorMultipleChoiceQuestionDslRepository + .findAllCategoriesAndLevelsAndIfApproved( + requestGetQuestionByCategoryAndLevelDto.getQuestionCategories(), + requestGetQuestionByCategoryAndLevelDto.getQuestionLevels(), + true); + for (MajorMultipleChoiceQuestion question : majorMultipleChoiceQuestions) { + Collections.shuffle(question.getQuestionChoices()); + } + return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorMultipleChoiceQuestions); + } - /** - * 분야, 난이도 파라미터로 문제를 조회하는 경우 - 서술형 - */ - @Override - public Map> getApprovedClassifiedDescriptiveQuestions( - RequestGetQuestionByCategoryAndLevelDto dto) { - List majorDescriptiveQuestions = majorDescriptiveQuestionDslRepository - .findWithCategoriesAndLevelsAndIfApproved( - dto.getQuestionCategories(), - dto.getQuestionLevels(), - true - ); - return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorDescriptiveQuestions); - } + /** + * 분야, 난이도 파라미터로 문제를 조회하는 경우 - 서술형 + */ + @Override + public Map> getApprovedClassifiedDescriptiveQuestions( + RequestGetQuestionByCategoryAndLevelDto dto) { + List majorDescriptiveQuestions = majorDescriptiveQuestionDslRepository + .findAllCategoriesAndLevelsAndIfApproved( + dto.getQuestionCategories(), + dto.getQuestionLevels(), + true + ); + return questionClassifyByCategoryService.classifyQuestionByCategoryOrdered(majorDescriptiveQuestions); + } } diff --git a/application/src/main/kotlin/com/comssa/api/config/SwaggerConfig.kt b/application/src/main/kotlin/com/comssa/api/config/SwaggerConfig.kt index d243aa0..e9bb67b 100644 --- a/application/src/main/kotlin/com/comssa/api/config/SwaggerConfig.kt +++ b/application/src/main/kotlin/com/comssa/api/config/SwaggerConfig.kt @@ -83,13 +83,13 @@ class SwaggerConfig { // WebMvcEndpointHandlerMapping 객체를 생성하여 반환합니다. return WebMvcEndpointHandlerMapping( - endpointMapping, // 엔드포인트 매핑 - webEndpoints, // 웹 엔드포인트 컬렉션 - endpointMediaTypes, // 엔드포인트 미디어 타입 - corsProperties.toCorsConfiguration(), // CORS 설정 - EndpointLinksResolver(allEndpoints, basePath), // 엔드포인트 링크 리졸버 - shouldRegisterLinksMapping, // 링크 매핑 등록 여부 - null, // 추가적인 설정 (여기서는 null로 설정) + endpointMapping, + webEndpoints, + endpointMediaTypes, + corsProperties.toCorsConfiguration(), + EndpointLinksResolver(allEndpoints, basePath), + shouldRegisterLinksMapping, + null, ) } diff --git a/application/src/test/java/com/comssa/api/question/license/AdminLicenseQuestionControllerTest.java b/application/src/test/java/com/comssa/api/question/license/AdminLicenseQuestionControllerTest.java index 762d8eb..00236fd 100644 --- a/application/src/test/java/com/comssa/api/question/license/AdminLicenseQuestionControllerTest.java +++ b/application/src/test/java/com/comssa/api/question/license/AdminLicenseQuestionControllerTest.java @@ -50,7 +50,7 @@ void setUp() { responseMultipleChoiceQuestionDtos = new ArrayList<>(); licenseMultipleChoiceQuestion = LicenseMultipleChoiceQuestion.makeForTest("test"); licenseMultipleChoiceQuestions.add(licenseMultipleChoiceQuestion); - responseMultipleChoiceQuestionDto = ResponseMultipleChoiceQuestionDto.forLicense(licenseMultipleChoiceQuestion); + responseMultipleChoiceQuestionDto = ResponseMultipleChoiceQuestionDto.from(licenseMultipleChoiceQuestion); responseMultipleChoiceQuestionDtos.add(responseMultipleChoiceQuestionDto); } diff --git a/build.gradle b/build.gradle index a2d3652..59a6fc0 100644 --- a/build.gradle +++ b/build.gradle @@ -154,6 +154,6 @@ subprojects { } -bootJar.enabled = false; -jar.enabled = false; +bootJar.enabled = false +jar.enabled = false diff --git a/persistence/src/main/java/com/comssa/persistence/question/domain/common/ChoiceBehavior.java b/persistence/src/main/java/com/comssa/persistence/question/domain/common/ChoiceBehavior.java new file mode 100644 index 0000000..93bfa45 --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/domain/common/ChoiceBehavior.java @@ -0,0 +1,7 @@ +package com.comssa.persistence.question.domain.common; + +import java.util.List; + +public interface ChoiceBehavior { + List getQuestionChoices(); +} diff --git a/persistence/src/main/java/com/comssa/persistence/question/domain/common/ChoiceProvider.java b/persistence/src/main/java/com/comssa/persistence/question/domain/common/ChoiceProvider.java deleted file mode 100644 index ab4641b..0000000 --- a/persistence/src/main/java/com/comssa/persistence/question/domain/common/ChoiceProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.comssa.persistence.question.domain.common; - -import java.util.List; - -public interface ChoiceProvider { - List getQuestionChoices(); -} diff --git a/persistence/src/main/java/com/comssa/persistence/question/domain/license/LicenseMultipleChoiceQuestion.java b/persistence/src/main/java/com/comssa/persistence/question/domain/license/LicenseMultipleChoiceQuestion.java index db61aef..fa87496 100644 --- a/persistence/src/main/java/com/comssa/persistence/question/domain/license/LicenseMultipleChoiceQuestion.java +++ b/persistence/src/main/java/com/comssa/persistence/question/domain/license/LicenseMultipleChoiceQuestion.java @@ -1,6 +1,6 @@ package com.comssa.persistence.question.domain.license; -import com.comssa.persistence.question.domain.common.ChoiceProvider; +import com.comssa.persistence.question.domain.common.ChoiceBehavior; import com.comssa.persistence.question.domain.common.Question; import com.comssa.persistence.question.domain.common.QuestionCategory; import com.comssa.persistence.question.domain.common.QuestionLevel; @@ -27,54 +27,56 @@ @NoArgsConstructor @ToString @DiscriminatorValue("LM") -public class LicenseMultipleChoiceQuestion extends Question implements ChoiceProvider { +public class LicenseMultipleChoiceQuestion extends Question implements ChoiceBehavior { - @Enumerated(value = EnumType.STRING) - protected LicenseCategory licenseCategory; - @ManyToOne - @JoinColumn(name = "license_session_id") - private LicenseSession licenseSession; - @OneToMany(mappedBy = "question", cascade = CascadeType.ALL, orphanRemoval = true) - private List questionChoices; + @Enumerated(value = EnumType.STRING) + protected LicenseCategory licenseCategory; + @ManyToOne + @JoinColumn(name = "license_session_id") + private LicenseSession licenseSession; + @OneToMany(mappedBy = "question", cascade = CascadeType.ALL, orphanRemoval = true) + private List questionChoices; - public static LicenseMultipleChoiceQuestion makeWithDto( - RequestMakeMultipleChoiceQuestionDto dto, - LicenseSession licenseSession, - LicenseCategory licenseCategory) { - LicenseMultipleChoiceQuestion licenseMultipleChoiceQuestion = LicenseMultipleChoiceQuestion.builder() - .content(dto.getContent()) - .questionCategory(dto.getQuestionCategory()) - .questionLevel(dto.getQuestionLevel()) - .description(dto.getDescription()) - .imageUrl(null) - .licenseSession(licenseSession) - .licenseCategory(licenseCategory) - .build(); - licenseMultipleChoiceQuestion.initDefaults(); - return licenseMultipleChoiceQuestion; - } - public static LicenseMultipleChoiceQuestion makeForTest(String test) { - LicenseMultipleChoiceQuestion licenseMultipleChoiceQuestion = LicenseMultipleChoiceQuestion.builder() - .id(1L) - .content(test) - .questionCategory(QuestionCategory.ALGORITHM) - .questionLevel(QuestionLevel.LOW) - .description(test) - .imageUrl(null) - .licenseSession(LicenseSession.builder() - .licenseCategory(LicenseCategory.SQLD) - .content(test) - .build()) - .licenseCategory(LicenseCategory.SQLD) - .build(); - licenseMultipleChoiceQuestion.initDefaults(); - return licenseMultipleChoiceQuestion; - } + public static LicenseMultipleChoiceQuestion makeWithDto( + RequestMakeMultipleChoiceQuestionDto dto, + LicenseSession licenseSession, + LicenseCategory licenseCategory) { + LicenseMultipleChoiceQuestion licenseMultipleChoiceQuestion = LicenseMultipleChoiceQuestion.builder() + .content(dto.getContent()) + .questionCategory(dto.getQuestionCategory()) + .questionLevel(dto.getQuestionLevel()) + .description(dto.getDescription()) + .imageUrl(null) + .licenseSession(licenseSession) + .licenseCategory(licenseCategory) + .build(); + licenseMultipleChoiceQuestion.initDefaults(); + return licenseMultipleChoiceQuestion; + } - @Override - public void initDefaults() { - this.questionChoices = new ArrayList<>(); - } + + public static LicenseMultipleChoiceQuestion makeForTest(String test) { + LicenseMultipleChoiceQuestion licenseMultipleChoiceQuestion = LicenseMultipleChoiceQuestion.builder() + .id(1L) + .content(test) + .questionCategory(QuestionCategory.ALGORITHM) + .questionLevel(QuestionLevel.LOW) + .description(test) + .imageUrl(null) + .licenseSession(LicenseSession.builder() + .licenseCategory(LicenseCategory.SQLD) + .content(test) + .build()) + .licenseCategory(LicenseCategory.SQLD) + .build(); + licenseMultipleChoiceQuestion.initDefaults(); + return licenseMultipleChoiceQuestion; + } + + @Override + public void initDefaults() { + this.questionChoices = new ArrayList<>(); + } } diff --git a/persistence/src/main/java/com/comssa/persistence/question/domain/major/MajorMultipleChoiceQuestion.java b/persistence/src/main/java/com/comssa/persistence/question/domain/major/MajorMultipleChoiceQuestion.java index 1c17668..3750106 100644 --- a/persistence/src/main/java/com/comssa/persistence/question/domain/major/MajorMultipleChoiceQuestion.java +++ b/persistence/src/main/java/com/comssa/persistence/question/domain/major/MajorMultipleChoiceQuestion.java @@ -1,6 +1,6 @@ package com.comssa.persistence.question.domain.major; -import com.comssa.persistence.question.domain.common.ChoiceProvider; +import com.comssa.persistence.question.domain.common.ChoiceBehavior; import com.comssa.persistence.question.domain.common.Question; import com.comssa.persistence.question.domain.common.QuestionCategory; import com.comssa.persistence.question.domain.common.QuestionLevel; @@ -23,7 +23,7 @@ @NoArgsConstructor @ToString @DiscriminatorValue("MM") -public class MajorMultipleChoiceQuestion extends Question implements ChoiceProvider { +public class MajorMultipleChoiceQuestion extends Question implements ChoiceBehavior { public boolean canBeShortAnswered; @OneToMany(mappedBy = "question", cascade = CascadeType.ALL, orphanRemoval = true) diff --git a/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseMultipleChoiceQuestionDto.kt b/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseMultipleChoiceQuestionDto.kt index 629af56..f530bcf 100644 --- a/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseMultipleChoiceQuestionDto.kt +++ b/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseMultipleChoiceQuestionDto.kt @@ -1,8 +1,7 @@ package com.comssa.persistence.question.dto.common.response +import com.comssa.persistence.question.domain.common.ChoiceBehavior import com.comssa.persistence.question.domain.common.Question -import com.comssa.persistence.question.domain.license.LicenseMultipleChoiceQuestion -import com.comssa.persistence.question.domain.major.MajorMultipleChoiceQuestion open class ResponseMultipleChoiceQuestionDto( val questionChoices: List, @@ -13,14 +12,7 @@ open class ResponseMultipleChoiceQuestionDto( ) { companion object { @JvmStatic - fun forLicense(question: LicenseMultipleChoiceQuestion): ResponseMultipleChoiceQuestionDto = - ResponseMultipleChoiceQuestionDto( - question = question, - questionChoices = question.questionChoices.map { ResponseQuestionChoiceDto.from(it) }, - ) - - @JvmStatic - fun forMajor(question: MajorMultipleChoiceQuestion): ResponseMultipleChoiceQuestionDto = + fun from(question: Q): ResponseMultipleChoiceQuestionDto where Q : Question, Q : ChoiceBehavior = ResponseMultipleChoiceQuestionDto( question = question, questionChoices = question.questionChoices.map { ResponseQuestionChoiceDto.from(it) }, diff --git a/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseQuestionDto.kt b/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseQuestionDto.kt index 904dba1..5695883 100644 --- a/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseQuestionDto.kt +++ b/persistence/src/main/java/com/comssa/persistence/question/dto/common/response/ResponseQuestionDto.kt @@ -1,11 +1,10 @@ package com.comssa.persistence.question.dto.common.response +import com.comssa.persistence.question.domain.common.ChoiceBehavior import com.comssa.persistence.question.domain.common.Question import com.comssa.persistence.question.domain.common.QuestionCategory import com.comssa.persistence.question.domain.common.QuestionLevel -import com.comssa.persistence.question.domain.license.LicenseMultipleChoiceQuestion import com.comssa.persistence.question.domain.major.MajorDescriptiveQuestion -import com.comssa.persistence.question.domain.major.MajorMultipleChoiceQuestion abstract class ResponseQuestionDto( question: Question, @@ -23,8 +22,7 @@ abstract class ResponseQuestionDto( @JvmStatic fun from(question: Question): R = when (question) { - is LicenseMultipleChoiceQuestion -> ResponseMultipleChoiceQuestionDto.forLicense(question) as R - is MajorMultipleChoiceQuestion -> ResponseMultipleChoiceQuestionDto.forMajor(question) as R + is ChoiceBehavior -> ResponseMultipleChoiceQuestionDto.from(question) as R is MajorDescriptiveQuestion -> ResponseDescriptiveQuestionDto.forMajor(question) as R else -> throw IllegalArgumentException("Unsupported question type: ${question.javaClass.name}") } diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/LevelsAndCategoryBooleanBuilder.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/LevelsAndCategoryBooleanBuilder.java deleted file mode 100644 index ed23219..0000000 --- a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/LevelsAndCategoryBooleanBuilder.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.comssa.persistence.question.repository.querydsl; - -import com.comssa.persistence.question.domain.common.QQuestion; -import com.comssa.persistence.question.domain.common.QuestionCategory; -import com.comssa.persistence.question.domain.common.QuestionLevel; -import com.querydsl.core.BooleanBuilder; - -import java.util.List; - - -public interface LevelsAndCategoryBooleanBuilder { - /** - * @param question 호출부에선 QQuestion 그대로 삽입하거나 - * 실제 상속받는 관계일 떄는 Q*Question._super를 인자로 넣어 호출한다 - */ - default BooleanBuilder whereCategoriesAndLevels( - QQuestion question, - List questionCategories, - List questionLevels - ) { - BooleanBuilder condition = new BooleanBuilder(); - // 카테고리 조건 - if (questionCategories != null && !questionCategories.isEmpty()) { - condition.and(question.questionCategory.in(questionCategories)); - } - // 레벨 조건 - if (questionLevels != null && !questionLevels.isEmpty()) { - condition.and(question.questionLevel.in(questionLevels)); - } - - return condition; - } -} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/LicenseMultipleChoiceQuestionDslRepository.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/LicenseMultipleChoiceQuestionDslRepository.java deleted file mode 100644 index 21f1200..0000000 --- a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/LicenseMultipleChoiceQuestionDslRepository.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.comssa.persistence.question.repository.querydsl; - - -import com.comssa.persistence.question.domain.common.QuestionCategory; -import com.comssa.persistence.question.domain.license.LicenseMultipleChoiceQuestion; -import com.comssa.persistence.question.domain.license.QLicenseMultipleChoiceQuestion; -import com.querydsl.jpa.impl.JPAQueryFactory; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public class LicenseMultipleChoiceQuestionDslRepository - extends QueryDslJpaQueryMaker - implements LevelsAndCategoryBooleanBuilder { - - public LicenseMultipleChoiceQuestionDslRepository(JPAQueryFactory jpaQueryFactory) { - super(jpaQueryFactory); - } - - private final QLicenseMultipleChoiceQuestion question = QLicenseMultipleChoiceQuestion - .licenseMultipleChoiceQuestion; - - public List findAllWhereLicenseSessionId( - Long licenseId - ) { - return getQuery(question) - .where( - question.licenseSession.id.eq(licenseId) - ) - .distinct() - .leftJoin(question.questionChoices).fetchJoin() - .orderBy(question.ifApproved.asc()) - .fetch(); - } - - public List findAllWhereLicenseSessionIdAndIfApproved( - Long licenseId, - boolean ifApproved - ) { - return getQuery(question) - .where( - question.licenseSession.id.eq(licenseId) - .and(question.ifApproved.eq(ifApproved)) - ) - .distinct() - .leftJoin(question.questionChoices).fetchJoin() - .fetch(); - } - - public List findAllWhereQuestionCategories( - List questionCategories - ) { - return getQuery( - question, - whereCategoriesAndLevels(question._super, questionCategories, null)) - .distinct() - .leftJoin(question.questionChoices).fetchJoin() - .fetch(); - } -} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/MajorDescriptiveDslRepository.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/MajorDescriptiveDslRepository.java deleted file mode 100644 index ba78ea9..0000000 --- a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/MajorDescriptiveDslRepository.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.comssa.persistence.question.repository.querydsl; - -import com.comssa.persistence.question.domain.common.QuestionCategory; -import com.comssa.persistence.question.domain.common.QuestionLevel; -import com.comssa.persistence.question.domain.major.MajorDescriptiveQuestion; -import com.comssa.persistence.question.domain.major.QMajorDescriptiveQuestion; -import com.querydsl.jpa.impl.JPAQueryFactory; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class MajorDescriptiveDslRepository - extends QueryDslJpaQueryMaker - implements LevelsAndCategoryBooleanBuilder { - private final QMajorDescriptiveQuestion question = QMajorDescriptiveQuestion.majorDescriptiveQuestion; - - public MajorDescriptiveDslRepository(JPAQueryFactory jpaQueryFactory) { - super(jpaQueryFactory); - } - - public List findWithCategoriesAndLevelsAndIfApproved( - List questionCategories, - List questionLevels, - boolean approved) { - return getQuery(question, whereCategoriesAndLevels( - question._super, - questionCategories, - questionLevels) - .and(question.ifApproved.eq(approved))) - .fetch(); - } - - public List findAllOrderByIfApprovedAsc() { - return getQuery(question) - // 정렬 기준 - .orderBy(question.ifApproved.asc()) - .fetch(); - } - -} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/MajorMultipleChoiceQuestionDslRepository.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/MajorMultipleChoiceQuestionDslRepository.java deleted file mode 100644 index 253962f..0000000 --- a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/MajorMultipleChoiceQuestionDslRepository.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.comssa.persistence.question.repository.querydsl; - - -import com.comssa.persistence.question.domain.common.QuestionCategory; -import com.comssa.persistence.question.domain.common.QuestionLevel; -import com.comssa.persistence.question.domain.major.MajorMultipleChoiceQuestion; -import com.comssa.persistence.question.domain.major.QMajorMultipleChoiceQuestion; -import com.querydsl.jpa.impl.JPAQueryFactory; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public class MajorMultipleChoiceQuestionDslRepository - extends QueryDslJpaQueryMaker - implements LevelsAndCategoryBooleanBuilder { - - public MajorMultipleChoiceQuestionDslRepository(JPAQueryFactory jpaQueryFactory) { - super(jpaQueryFactory); - } - - private final QMajorMultipleChoiceQuestion question = QMajorMultipleChoiceQuestion.majorMultipleChoiceQuestion; - - public List findAllWhereCategoriesAndLevelsAndIfApproved( - List questionCategories, - List questionLevels, - boolean approved - ) { - - return getQuery(question, whereCategoriesAndLevels( - question._super, - questionCategories, - questionLevels - ).and(question.ifApproved.eq(approved))) - .distinct() - .leftJoin(question.questionChoices).fetchJoin() - .fetch(); - } - - public List findAllWhereQuestionCategories( - List questionCategories - ) { - return getQuery( - question, - whereCategoriesAndLevels(question._super, questionCategories, null)) - .distinct() - .leftJoin(question.questionChoices).fetchJoin() - .fetch(); - } - - public List findAllOrderByIfApprovedAsc() { - return getQuery(question) - .distinct() - .leftJoin(question.questionChoices).fetchJoin() - .orderBy(question.ifApproved.asc()) - .fetch(); - } - - -} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/QueryDslJpaQueryMaker.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/QueryDslJpaQueryMaker.java index c75e545..75eb7e5 100644 --- a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/QueryDslJpaQueryMaker.java +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/QueryDslJpaQueryMaker.java @@ -1,7 +1,6 @@ package com.comssa.persistence.question.repository.querydsl; -import com.querydsl.core.types.Predicate; import com.querydsl.core.types.dsl.EntityPathBase; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -22,14 +21,8 @@ public abstract class QueryDslJpaQueryMaker { protected final JPAQueryFactory jpaQueryFactory; - - public JPAQuery getQuery(EntityPathBase entityPathBase, - Predicate condition) { - return jpaQueryFactory.selectFrom(entityPathBase) - .where(condition); - } - public JPAQuery getQuery(EntityPathBase entityPathBase) { return jpaQueryFactory.selectFrom(entityPathBase); } + } diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/LicenseMultipleChoiceQuestionDslRepository.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/LicenseMultipleChoiceQuestionDslRepository.java new file mode 100644 index 0000000..13473bb --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/LicenseMultipleChoiceQuestionDslRepository.java @@ -0,0 +1,74 @@ +package com.comssa.persistence.question.repository.querydsl.impl; + + +import com.comssa.persistence.question.domain.common.QQuestion; +import com.comssa.persistence.question.domain.common.QuestionCategory; +import com.comssa.persistence.question.domain.license.LicenseMultipleChoiceQuestion; +import com.comssa.persistence.question.domain.license.QLicenseMultipleChoiceQuestion; +import com.comssa.persistence.question.repository.querydsl.QueryDslJpaQueryMaker; +import com.comssa.persistence.question.repository.querydsl.query.QuestionApiTransmissionQuery; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public class LicenseMultipleChoiceQuestionDslRepository + extends QueryDslJpaQueryMaker + implements QuestionApiTransmissionQuery { + + private final QLicenseMultipleChoiceQuestion question = QLicenseMultipleChoiceQuestion + .licenseMultipleChoiceQuestion; + + public LicenseMultipleChoiceQuestionDslRepository(JPAQueryFactory jpaQueryFactory) { + super(jpaQueryFactory); + } + + public List findAllWhereLicenseSessionId( + Long licenseId + ) { + return getQuery(question) + .where( + question.licenseSession.id.eq(licenseId) + ) + .distinct() + .leftJoin(question.questionChoices).fetchJoin() + .orderBy(question.ifApproved.asc()) + .fetch(); + } + + public List findAllWhereLicenseSessionIdAndIfApproved( + Long licenseId, + boolean ifApproved + ) { + return getQuery(question) + .where( + question.licenseSession.id.eq(licenseId) + .and(question.ifApproved.eq(ifApproved)) + ) + .distinct() + .leftJoin(question.questionChoices).fetchJoin() + .fetch(); + } + + @Override + public List findAllWhereCategories( + List questionCategories + ) { + return selectWhereCategories(questionCategories) + .leftJoin(question.questionChoices).fetchJoin() + .fetch(); + } + + + @Override + public QQuestion getQuestionQClass() { + return question._super; + } + + @Override + public JPAQuery getQuestion() { + return getQuery(question); + } +} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/MajorDescriptiveDslRepository.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/MajorDescriptiveDslRepository.java new file mode 100644 index 0000000..bed4ce9 --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/MajorDescriptiveDslRepository.java @@ -0,0 +1,33 @@ +package com.comssa.persistence.question.repository.querydsl.impl; + +import com.comssa.persistence.question.domain.common.QQuestion; +import com.comssa.persistence.question.domain.major.MajorDescriptiveQuestion; +import com.comssa.persistence.question.domain.major.QMajorDescriptiveQuestion; +import com.comssa.persistence.question.repository.querydsl.QueryDslJpaQueryMaker; +import com.comssa.persistence.question.repository.querydsl.query.MajorQuestionSearchQuery; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.stereotype.Service; + +@Service +public class MajorDescriptiveDslRepository + extends QueryDslJpaQueryMaker + implements MajorQuestionSearchQuery { + private final QMajorDescriptiveQuestion question = QMajorDescriptiveQuestion.majorDescriptiveQuestion; + + public MajorDescriptiveDslRepository(JPAQueryFactory jpaQueryFactory) { + super(jpaQueryFactory); + } + + + @Override + public JPAQuery getQuestion() { + return getQuery(question); + } + + @Override + public QQuestion getQuestionQClass() { + return question._super; + } + +} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/MajorMultipleChoiceQuestionDslRepository.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/MajorMultipleChoiceQuestionDslRepository.java new file mode 100644 index 0000000..60d312f --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/MajorMultipleChoiceQuestionDslRepository.java @@ -0,0 +1,74 @@ +package com.comssa.persistence.question.repository.querydsl.impl; + + +import com.comssa.persistence.question.domain.common.QQuestion; +import com.comssa.persistence.question.domain.common.QuestionCategory; +import com.comssa.persistence.question.domain.common.QuestionLevel; +import com.comssa.persistence.question.domain.major.MajorMultipleChoiceQuestion; +import com.comssa.persistence.question.domain.major.QMajorMultipleChoiceQuestion; +import com.comssa.persistence.question.repository.querydsl.QueryDslJpaQueryMaker; +import com.comssa.persistence.question.repository.querydsl.query.MajorQuestionSearchQuery; +import com.comssa.persistence.question.repository.querydsl.query.QuestionApiTransmissionQuery; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public class MajorMultipleChoiceQuestionDslRepository + extends QueryDslJpaQueryMaker + implements QuestionApiTransmissionQuery, + MajorQuestionSearchQuery { + + private final QMajorMultipleChoiceQuestion question = QMajorMultipleChoiceQuestion.majorMultipleChoiceQuestion; + + public MajorMultipleChoiceQuestionDslRepository(JPAQueryFactory jpaQueryFactory) { + super(jpaQueryFactory); + } + + @Override + public List findAllCategoriesAndLevelsAndIfApproved( + List questionCategories, + List questionLevels, + boolean approved) { + return selectWhereCategoriesAndLevelsAndIfApproved( + questionCategories, + questionLevels, + approved + ) + .distinct() + .leftJoin(question.questionChoices).fetchJoin() + .fetch(); + } + + @Override + public List findAllWhereCategories( + List questionCategories + ) { + return selectWhereCategories(questionCategories) + .distinct() + .leftJoin(question.questionChoices).fetchJoin() + .fetch(); + } + + @Override + public JPAQuery getQuestion() { + return getQuery(question); + } + + @Override + public QQuestion getQuestionQClass() { + return question._super; + } + + @Override + public List findAllOrderByIfApprovedAsc() { + return selectOrderByIfApprovedAsc() + .distinct() + .leftJoin(question.questionChoices).fetchJoin() + .fetch(); + } + + +} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/QuestionCustomRepositoryImpl.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/QuestionCustomRepositoryImpl.java similarity index 88% rename from persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/QuestionCustomRepositoryImpl.java rename to persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/QuestionCustomRepositoryImpl.java index ea8a0c2..161cb21 100644 --- a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/QuestionCustomRepositoryImpl.java +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/impl/QuestionCustomRepositoryImpl.java @@ -1,9 +1,10 @@ -package com.comssa.persistence.question.repository.querydsl; +package com.comssa.persistence.question.repository.querydsl.impl; import com.comssa.persistence.comment.domain.QComment; import com.comssa.persistence.question.domain.common.QQuestion; import com.comssa.persistence.question.domain.common.Question; +import com.comssa.persistence.question.repository.querydsl.QuestionCustomRepository; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.Optional; diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/MajorQuestionSearchQuery.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/MajorQuestionSearchQuery.java new file mode 100644 index 0000000..487513c --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/MajorQuestionSearchQuery.java @@ -0,0 +1,46 @@ +package com.comssa.persistence.question.repository.querydsl.query; + +import com.comssa.persistence.question.domain.common.Question; +import com.comssa.persistence.question.domain.common.QuestionCategory; +import com.comssa.persistence.question.domain.common.QuestionLevel; +import com.comssa.persistence.question.repository.querydsl.query.booleanbuilder.LevelsAndCategoryBooleanBuilder; +import com.querydsl.jpa.impl.JPAQuery; + +import java.util.List; + +public interface MajorQuestionSearchQuery + extends LevelsAndCategoryBooleanBuilder, QuestionQuerySupport { + + default List findAllCategoriesAndLevelsAndIfApproved( + List questionCategories, + List questionLevels, + boolean approved + ) { + return selectWhereCategoriesAndLevelsAndIfApproved(questionCategories, questionLevels, approved) + .fetch(); + } + + default List findAllOrderByIfApprovedAsc() { + return selectOrderByIfApprovedAsc() + .fetch(); + } + + default JPAQuery selectOrderByIfApprovedAsc() { + return getQuestion() + .orderBy(getQuestionQClass().ifApproved.asc()); + } + + default JPAQuery selectWhereCategoriesAndLevelsAndIfApproved( + List questionCategories, + List questionLevels, + boolean approved) { + return getQuestion() + .where( + whereCategoriesAndLevels( + getQuestionQClass(), + questionCategories, + questionLevels) + .and(getQuestionQClass().ifApproved.eq(approved)) + ); + } +} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/QuestionApiTransmissionQuery.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/QuestionApiTransmissionQuery.java new file mode 100644 index 0000000..4130349 --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/QuestionApiTransmissionQuery.java @@ -0,0 +1,28 @@ +package com.comssa.persistence.question.repository.querydsl.query; + +import com.comssa.persistence.question.domain.common.Question; +import com.comssa.persistence.question.domain.common.QuestionCategory; +import com.comssa.persistence.question.repository.querydsl.query.booleanbuilder.LevelsAndCategoryBooleanBuilder; +import com.querydsl.jpa.impl.JPAQuery; + +import java.util.List; + +public interface QuestionApiTransmissionQuery + extends LevelsAndCategoryBooleanBuilder, QuestionQuerySupport { + // 구현체에서 구현해야하는 통일된 메소드 이름 + + default List findAllWhereCategories(List questionCategories) { + return selectWhereCategories(questionCategories) + .fetch(); + } + + default JPAQuery selectWhereCategories(List questionCategories) { + return getQuestion() + .where( + whereCategoriesAndLevels( + getQuestionQClass(), + questionCategories, + null) + ); + } +} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/QuestionQuerySupport.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/QuestionQuerySupport.java new file mode 100644 index 0000000..623ad6e --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/QuestionQuerySupport.java @@ -0,0 +1,14 @@ +package com.comssa.persistence.question.repository.querydsl.query; + +import com.comssa.persistence.question.domain.common.QQuestion; +import com.comssa.persistence.question.domain.common.Question; +import com.querydsl.jpa.impl.JPAQuery; + +public interface QuestionQuerySupport { + //구현체에서 Select할 테이블을 선택 + JPAQuery getQuestion(); + + + //구현체에서 QQuestion을 반환 + QQuestion getQuestionQClass(); +} diff --git a/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/booleanbuilder/LevelsAndCategoryBooleanBuilder.java b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/booleanbuilder/LevelsAndCategoryBooleanBuilder.java new file mode 100644 index 0000000..bc47836 --- /dev/null +++ b/persistence/src/main/java/com/comssa/persistence/question/repository/querydsl/query/booleanbuilder/LevelsAndCategoryBooleanBuilder.java @@ -0,0 +1,32 @@ +package com.comssa.persistence.question.repository.querydsl.query.booleanbuilder; + +import com.comssa.persistence.question.domain.common.QQuestion; +import com.comssa.persistence.question.domain.common.QuestionCategory; +import com.comssa.persistence.question.domain.common.QuestionLevel; +import com.querydsl.core.BooleanBuilder; + +import java.util.List; + + +public interface LevelsAndCategoryBooleanBuilder { + /** + * @param question 호출부에선 QQuestion 그대로 삽입하거나 + * 실제 상속받는 관계일 떄는 Q*Question._super를 인자로 넣어 호출한다 + */ + default BooleanBuilder whereCategoriesAndLevels( + QQuestion question, + List questionCategories, + List questionLevels + ) { + BooleanBuilder condition = new BooleanBuilder(); + // 카테고리 조건 + if (questionCategories != null && !questionCategories.isEmpty()) { + condition.and(question.questionCategory.in(questionCategories)); + } + // 레벨 조건 + if (questionLevels != null && !questionLevels.isEmpty()) { + condition.and(question.questionLevel.in(questionLevels)); + } + return condition; + } +}