diff --git a/.DS_Store b/.DS_Store index fea2e6c..550fc93 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt index 35905df..2972fef 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt @@ -37,6 +37,8 @@ interface CustomQuestionSetsRepository { ): QuestionSetDetailDto? fun queryQuestionSetDtoByProblemIdIn(user: User, problemIds: List): PageResponse + + fun queryQuestionSetDtoByWriter(page: Int, user: User): PageResponse } @Repository @@ -100,7 +102,7 @@ class CustomQuestionSetsRepositoryImpl( ) } - private fun JPAQuery.getQuestionSetDto(user: User): MutableList { + private fun JPAQuery.getQuestionSetDto(user: User): List { val author = QUser("writer") return leftJoin(questionTags).on(questionTags.problems.eq(questionSets.problem)) .leftJoin(tags).on(tags.id.eq(questionTags.id.tagId)) @@ -166,4 +168,16 @@ class CustomQuestionSetsRepositoryImpl( ) ) } + + override fun queryQuestionSetDtoByWriter(page: Int, user: User): PageResponse { + val questionSets = queryFactory + .selectFrom(questionSets) + .where(questionSets.author.eq(user)) + .getQuestionSetDto(user) + + return PageUtil.toPageResponse( + page = page.toLong(), + list = questionSets + ) + } } diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionsRepository.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionsRepository.kt index 030e9ab..118feed 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionsRepository.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionsRepository.kt @@ -19,7 +19,6 @@ import kr.hs.dsm.inq.domain.user.persistence.dto.QUserQuestionDto import kr.hs.dsm.inq.domain.user.persistence.dto.UserQuestionDto import org.springframework.data.repository.CrudRepository import org.springframework.stereotype.Repository - interface QuestionsRepository: CrudRepository, CustomQuestionRepository { fun findByIdIn(questionIds: List): List } @@ -36,7 +35,7 @@ interface CustomQuestionRepository { fun queryQuestionDtoOrderByAnswerCount(user: User, page: Long): PageResponse fun queryQuestionDtoById(id: Long, user: User): QuestionDto? fun queryQuestionDetailDtoById(user: User, questionId: Long): QuestionDetailDto? - fun queryQuestionDtoByWriterId(page: Long, user: User): PageResponse + fun queryQuestionDtoByWriterId(page: Int, user: User): PageResponse fun queryQuestionDto(user: User): List fun queryQuestionDtoByProblemIdIn(user: User, problemIds: List): PageResponse } @@ -177,14 +176,14 @@ class CustomQuestionRepositoryImpl( ) } - override fun queryQuestionDtoByWriterId(page: Long, user: User): PageResponse { + override fun queryQuestionDtoByWriterId(page: Int, user: User): PageResponse { val questions = queryFactory .selectFrom(questions) .where(questions.author.eq(user)) .getUserQuestionListDto(user) return PageUtil.toPageResponse( - page = page, + page = page.toLong(), list = questions ) } @@ -208,7 +207,7 @@ class CustomQuestionRepositoryImpl( /* question = */ questions.question, /* category = */ questions.category, /* tagList = */ GroupBy.list(tags), - /* isFavorite = */ questions.isNull, // favorite.isNotNull + /* isFavorite = */ questions.isNull, /* exemplaryAnswer = */ answers.answer, /* createdAt = */ questions.createdAt, ) diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/UserController.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/UserController.kt index 5404808..e985185 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/UserController.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/UserController.kt @@ -2,6 +2,7 @@ package kr.hs.dsm.inq.domain.user.presentation import javax.validation.Valid import kr.hs.dsm.inq.common.dto.TokenResponse +import kr.hs.dsm.inq.domain.question.presentation.dto.QuestionSetListResponse import kr.hs.dsm.inq.domain.question.presentation.dto.UserQuestionResponse import kr.hs.dsm.inq.domain.user.presentation.dto.* import kr.hs.dsm.inq.domain.user.service.UserService @@ -37,8 +38,14 @@ class UserController( fun queryUserAttendance(): UserAttendanceResponse = userService.queryUserAttendance() - @GetMapping("/question/{page}") - fun getMyQuestion(@PathVariable("page") page: Long): List { - return userService.getMyQuestion(page) + @GetMapping("/question") + fun getMyQuestion(@Valid @ModelAttribute request: GetMyQuestionRequest): List { + return userService.getMyQuestion(request) + } + + @GetMapping("/set") + fun getMyQuestionSet(@Valid @ModelAttribute request: GetMyQuestionRequest): QuestionSetListResponse { + + return userService.getMyQuestionSet(request) } } \ No newline at end of file diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Requests.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Requests.kt index a00a52e..1c29703 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Requests.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Requests.kt @@ -37,4 +37,8 @@ data class UpdateUserInfoRequest( val job: String, val jobDuration: Int +) + +data class GetMyQuestionRequest( + val page: Int ) \ No newline at end of file diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/user/service/UserService.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/user/service/UserService.kt index d58e81d..df2219f 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/user/service/UserService.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/user/service/UserService.kt @@ -1,9 +1,13 @@ package kr.hs.dsm.inq.domain.user.service import kr.hs.dsm.inq.common.dto.TokenResponse +import kr.hs.dsm.inq.common.util.PageResponse import kr.hs.dsm.inq.common.util.SecurityUtil import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionDetailDto +import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionSetDto +import kr.hs.dsm.inq.domain.question.persistence.repository.QuestionSetsRepository import kr.hs.dsm.inq.domain.question.persistence.repository.QuestionsRepository +import kr.hs.dsm.inq.domain.question.presentation.dto.QuestionSetListResponse import kr.hs.dsm.inq.domain.question.presentation.dto.UserQuestionResponse import kr.hs.dsm.inq.domain.user.exception.AttendanceNotFound import kr.hs.dsm.inq.domain.user.exception.PasswordMismatchException @@ -25,7 +29,8 @@ class UserService( private val passwordEncoder: PasswordEncoder, private val jwtGenerator: JwtGenerator, private val attendanceRepository: AttendanceRepository, - private val questionsRepository: QuestionsRepository + private val questionsRepository: QuestionsRepository, + private val questionSetsRepository: QuestionSetsRepository ) { fun signIn(request: UserSignInRequest): TokenResponse { @@ -94,10 +99,10 @@ class UserService( ) } - fun getMyQuestion(page: Long): List { + fun getMyQuestion(request: GetMyQuestionRequest): List { val user = SecurityUtil.getCurrentUser() - val usersQuestions = questionsRepository.queryQuestionDtoByWriterId(page, user) + val usersQuestions = questionsRepository.queryQuestionDtoByWriterId(request.page, user) return usersQuestions.list.map { UserQuestionResponse.of( @@ -116,6 +121,13 @@ class UserService( exemplaryAnswer = it.exemplaryAnswer ) } + } + + fun getMyQuestionSet(request: GetMyQuestionRequest): QuestionSetListResponse { + val user = SecurityUtil.getCurrentUser() + + val userQuestionSets = questionSetsRepository.queryQuestionSetDtoByWriter(request.page, user) + return QuestionSetListResponse.of(userQuestionSets) } } \ No newline at end of file