Skip to content

Commit

Permalink
fix: 기업의 질문 조회 안 되던 수정했습니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
fakerdeft committed May 11, 2024
1 parent b5e2e24 commit 947e382
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.coverflow.question.application;

import com.coverflow.company.infrastructure.CompanyRepository;
import com.coverflow.member.application.MemberServiceImpl;
import com.coverflow.question.domain.Question;
import com.coverflow.question.dto.AnswerListDTO;
Expand Down Expand Up @@ -36,7 +35,6 @@ public class QuestionServiceImpl implements QuestionService {

private final MemberServiceImpl memberService;
private final AnswerServiceImpl answerService;
private final CompanyRepository companyRepository;
private final QuestionRepository questionRepository;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static com.coverflow.question.domain.QQuestion.question;

Expand Down Expand Up @@ -58,91 +56,40 @@ public Optional<Page<Question>> findRegisteredQuestionsById(
final long companyId,
final String questionTag
) {
List<Question> questions;
long total;

CompletableFuture<List<Question>> questionsFuture = CompletableFuture.supplyAsync(() ->
jpaQueryFactory
.selectFrom(question)
.leftJoin(question.answers).fetchJoin()
.where(
question.company.id.eq(companyId),
question.questionStatus.eq(true),
toContainsQuestionTag(questionTag)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(makeOrderSpecifiers(question, pageable))
.distinct()
.fetch()
);

CompletableFuture<Long> countFuture = CompletableFuture.supplyAsync(() ->
jpaQueryFactory
.select(question.count())
.from(question)
.where(
question.company.id.eq(companyId),
question.questionStatus.eq(true),
toContainsQuestionTag(questionTag)
)
.fetchOne()
);

CompletableFuture.allOf(questionsFuture, countFuture).join();

try {
questions = questionsFuture.get();
total = countFuture.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}

return Optional.of(new PageImpl<>(questions, pageable, total));
List<Question> questions = jpaQueryFactory
.selectFrom(question)
.leftJoin(question.answers).fetchJoin()
.where(
question.company.id.eq(companyId),
question.questionStatus.eq(true),
toContainsQuestionTag(questionTag)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(makeOrderSpecifiers(question, pageable))
.distinct()
.fetch();

return Optional.of(new PageImpl<>(questions, pageable, questions.size()));
}

@Override
public Optional<Page<Question>> findWithFilters(
final Pageable pageable,
final FindQuestionAdminRequest request
) {
List<Question> questions;
long total;

CompletableFuture<List<Question>> questionsFuture = CompletableFuture.supplyAsync(() ->
jpaQueryFactory
.selectFrom(question)
.where(
toCreatedDateBetween(request.createdStartDate(), request.createdEndDate()),
eqStatus(request.status())
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(makeOrderSpecifiers(question, pageable))
.fetch()
);

CompletableFuture<Long> countFuture = CompletableFuture.supplyAsync(() ->
jpaQueryFactory
.select(question.count())
.from(question)
.where(
toCreatedDateBetween(request.createdStartDate(), request.createdEndDate()),
eqStatus(request.status())
)
.fetchOne()
);

CompletableFuture.allOf(questionsFuture, countFuture).join();

try {
questions = questionsFuture.get();
total = countFuture.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}

return Optional.of(new PageImpl<>(questions, pageable, total));
List<Question> questions = jpaQueryFactory
.selectFrom(question)
.where(
toCreatedDateBetween(request.createdStartDate(), request.createdEndDate()),
eqStatus(request.status())
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(makeOrderSpecifiers(question, pageable))
.fetch();

return Optional.of(new PageImpl<>(questions, pageable, questions.size()));
}

private BooleanExpression toContainsQuestionTag(final String questionTag) {
Expand Down

0 comments on commit 947e382

Please sign in to comment.