Skip to content

Commit

Permalink
fix: join 방식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaisqls committed Nov 15, 2023
1 parent 4f4b076 commit 0ab9abe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class CustomAnswerRepositoryImpl(
private fun <T> JPAQuery<T>.getAnswerDetailDto(): MutableList<AnswersDto> {
val like = QLike("likes")
val dislike = QLike("dislikes")
return rightJoin(user).on(user.id.eq(answers.writer.id))
.rightJoin(post).on(post.id.eq(answers.post.id))
return innerJoin(user).on(user.id.eq(answers.writer.id))
.innerJoin(post).on(post.id.eq(answers.post.id))
.leftJoin(like).on(like.post.id.eq(post.id).and(like.isLiked.isTrue))
.leftJoin(dislike).on(dislike.post.id.eq(post.id).and(dislike.isLiked.isFalse))
.leftJoin(comments).on(comments.post.eq(answers.post))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory
import kr.hs.dsm.inq.common.util.PageResponse
import kr.hs.dsm.inq.common.util.PageUtil
import kr.hs.dsm.inq.domain.question.persistence.*
import kr.hs.dsm.inq.domain.question.persistence.QAnswers.answers
import kr.hs.dsm.inq.domain.question.persistence.QComments.comments
import kr.hs.dsm.inq.domain.question.persistence.QFavorite.favorite
import kr.hs.dsm.inq.domain.question.persistence.QPost.post
Expand Down Expand Up @@ -112,8 +113,7 @@ class CustomQuestionSetsRepositoryImpl(
.on(questionSolvingHistory.user.id.eq(user.id)).on(questionSolvingHistory.problem.eq(questionSets.problem))
.innerJoin(author).on(author.id.eq(questionSets.author.id))
.innerJoin(post).on(post.id.eq(questionSets.post.id))
.rightJoin(favorite).on(favorite.problem.eq(questions.problem))
// .rightJoin(answers).on(answers.writer.eq(user).and(answers.questions.eq(questions)))
.leftJoin(favorite).on(favorite.problem.id.eq(questionSets.problem.id).and(favorite.user.id.eq(user.id)))
.transform(
GroupBy.groupBy(questionSets.id)
.list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kr.hs.dsm.inq.common.util.PageResponse
import kr.hs.dsm.inq.common.util.PageUtil
import kr.hs.dsm.inq.domain.question.persistence.Category
import kr.hs.dsm.inq.domain.question.persistence.QAnswers.answers
import kr.hs.dsm.inq.domain.question.persistence.QFavorite
import kr.hs.dsm.inq.domain.question.persistence.QFavorite.favorite
import kr.hs.dsm.inq.domain.question.persistence.QQuestionSets
import kr.hs.dsm.inq.domain.question.persistence.QQuestionSets.questionSets
Expand Down Expand Up @@ -115,11 +116,11 @@ class CustomQuestionRepositoryImpl(

private fun <T> JPAQuery<T>.getQuestionDto(user: User): MutableList<QuestionDto> {
val writer = QUser("writer")
return innerJoin(questionTags).on(questionTags.problems.eq(questions.problem))
.innerJoin(tags).on(tags.id.eq(questionTags.id.tagId))
return leftJoin(questionTags).on(questionTags.problems.eq(questions.problem))
.leftJoin(tags).on(tags.id.eq(questionTags.id.tagId))
.innerJoin(writer).on(writer.id.eq(questions.author.id))
.rightJoin(favorite).on(favorite.problem.id.eq(questions.problem.id))
// .rightJoin(answers).on(answers.writer.eq(user).and(answers.questions.eq(questions)))
.leftJoin(favorite).on(favorite.problem.id.eq(questions.problem.id).and(favorite.user.id.eq(user.id)))
.leftJoin(answers).on(answers.writer.id.eq(user.id).and(answers.questions.id.eq(questions.id)))
.transform(
GroupBy.groupBy(questions)
.list(
Expand All @@ -131,7 +132,7 @@ class CustomQuestionRepositoryImpl(
/* job = */ writer.job,
/* jobDuration = */ writer.jobDuration,
/* tagList = */ GroupBy.list(tags),
/* isAnswered = */ questions.isNull, // answers.isNotNull,
/* isAnswered = */ answers.isNotNull,
/* isFavorite = */ favorite.isNotNull,
/* createdAt = */ questions.createdAt
)
Expand All @@ -154,11 +155,11 @@ class CustomQuestionRepositoryImpl(

val author = QUser("writer")

return@run rightJoin(questionTags).on(questionTags.problems.eq(questions.problem))
.rightJoin(tags).on(tags.id.eq(questionTags.id.tagId))
.rightJoin(favorite).on(favorite.id.problemId.eq(questions.problem.id))
// .rightJoin(answers).on(answers.writer.eq(user).and(answers.questions.eq(questions)))
.rightJoin(author).on(author.eq(questions.author))
return@run leftJoin(questionTags).on(questionTags.problems.eq(questions.problem))
.leftJoin(tags).on(tags.id.eq(questionTags.id.tagId))
.leftJoin(favorite).on(favorite.problem.id.eq(questions.problem.id))
.leftJoin(answers).on(answers.writer.eq(user).and(answers.questions.eq(questions)))
.innerJoin(author).on(author.eq(questions.author))
.transform(
GroupBy.groupBy(questions)
.list(
Expand Down Expand Up @@ -193,11 +194,10 @@ class CustomQuestionRepositoryImpl(
fun <T> JPAQuery<T>.getUserQuestionListDto(user: User): List<UserQuestionDto> = run {
val writer = QUser("writer")

return@run innerJoin(questionTags).on(questionTags.problems.eq(questions.problem))
.innerJoin(tags).on(tags.id.eq(questionTags.id.tagId))
.rightJoin(favorite).on(favorite.id.problemId.eq(questions.problem.id))
.innerJoin(answers).on(answers.questions.id.eq(questions.id))
.rightJoin(writer).on(writer.id.eq(user.id))
return@run leftJoin(questionTags).on(questionTags.problems.eq(questions.problem))
.leftJoin(tags).on(tags.id.eq(questionTags.id.tagId))
.leftJoin(answers).on(answers.questions.id.eq(questions.id))
.innerJoin(writer).on(writer.id.eq(user.id))
.transform(
GroupBy.groupBy(questions)
.list(
Expand Down

0 comments on commit 0ab9abe

Please sign in to comment.