-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
20 deletions.
There are no files selected for viewing
42 changes: 41 additions & 1 deletion
42
src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/ProblemRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,48 @@ | ||
package kr.hs.dsm.inq.domain.question.persistence.repository | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import kr.hs.dsm.inq.common.util.PageResponse | ||
import kr.hs.dsm.inq.domain.question.persistence.Category | ||
import kr.hs.dsm.inq.domain.question.persistence.Problem | ||
import kr.hs.dsm.inq.domain.question.persistence.ProblemType | ||
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.QProblem | ||
import kr.hs.dsm.inq.domain.question.persistence.QProblem.problem | ||
import kr.hs.dsm.inq.domain.question.persistence.QuestionSets | ||
import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionSetDetailDto | ||
import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionSetDto | ||
import kr.hs.dsm.inq.domain.user.persistence.User | ||
import org.springframework.data.repository.CrudRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
interface ProblemRepository : CrudRepository<Problem, Long>, CustomProblemRepository { | ||
} | ||
|
||
interface CustomProblemRepository { | ||
fun queryFavoriteProblem(userId: Long): List<Problem> | ||
fun queryFavoriteProblemSet(userId: Long): List<Problem> | ||
} | ||
|
||
@Repository | ||
class CustomProblemRepositoryImpl( | ||
private val queryFactory: JPAQueryFactory | ||
): CustomProblemRepository { | ||
|
||
override fun queryFavoriteProblem(userId: Long): List<Problem> { | ||
return queryFactory | ||
.selectFrom(problem) | ||
.innerJoin(favorite).on(favorite.user.id.eq(userId)) | ||
.where(problem.type.eq(ProblemType.QUESTION)) | ||
.fetch() | ||
} | ||
|
||
override fun queryFavoriteProblemSet(userId: Long): List<Problem> { | ||
return queryFactory | ||
.selectFrom(problem) | ||
.innerJoin(favorite).on(favorite.user.id.eq(userId)) | ||
.where(problem.type.eq(ProblemType.SET)) | ||
.fetch() | ||
} | ||
|
||
interface ProblemRepository : CrudRepository<Problem, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters