Skip to content

Commit

Permalink
Merge pull request #19 from DSM-InQ/get-user-question-set
Browse files Browse the repository at this point in the history
feat: 내가 등록한 질문 세트 api
  • Loading branch information
12xii authored Nov 7, 2023
2 parents d33aa18 + 428f453 commit d782e21
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ interface CustomQuestionSetsRepository {
): QuestionSetDetailDto?

fun queryQuestionSetDtoByProblemIdIn(user: User, problemIds: List<Long>): PageResponse<QuestionSetDto>

fun queryQuestionSetDtoByWriter(page: Int, user: User): PageResponse<QuestionSetDto>
}

@Repository
Expand Down Expand Up @@ -100,7 +102,7 @@ class CustomQuestionSetsRepositoryImpl(
)
}

private fun <T> JPAQuery<T>.getQuestionSetDto(user: User): MutableList<QuestionSetDto> {
private fun <T> JPAQuery<T>.getQuestionSetDto(user: User): List<QuestionSetDto> {
val author = QUser("writer")
return leftJoin(questionTags).on(questionTags.problems.eq(questionSets.problem))
.leftJoin(tags).on(tags.id.eq(questionTags.id.tagId))
Expand Down Expand Up @@ -166,4 +168,16 @@ class CustomQuestionSetsRepositoryImpl(
)
)
}

override fun queryQuestionSetDtoByWriter(page: Int, user: User): PageResponse<QuestionSetDto> {
val questionSets = queryFactory
.selectFrom(questionSets)
.where(questionSets.author.eq(user))
.getQuestionSetDto(user)

return PageUtil.toPageResponse(
page = page.toLong(),
list = questionSets
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Questions, Long>, CustomQuestionRepository {
fun findByIdIn(questionIds: List<Long>): List<Questions>
}
Expand All @@ -36,7 +35,7 @@ interface CustomQuestionRepository {
fun queryQuestionDtoOrderByAnswerCount(user: User, page: Long): PageResponse<QuestionDto>
fun queryQuestionDtoById(id: Long, user: User): QuestionDto?
fun queryQuestionDetailDtoById(user: User, questionId: Long): QuestionDetailDto?
fun queryQuestionDtoByWriterId(page: Long, user: User): PageResponse<UserQuestionDto>
fun queryQuestionDtoByWriterId(page: Int, user: User): PageResponse<UserQuestionDto>
fun queryQuestionDto(user: User): List<QuestionDto>
fun queryQuestionDtoByProblemIdIn(user: User, problemIds: List<Long>): PageResponse<QuestionDto>
}
Expand Down Expand Up @@ -177,14 +176,14 @@ class CustomQuestionRepositoryImpl(
)
}

override fun queryQuestionDtoByWriterId(page: Long, user: User): PageResponse<UserQuestionDto> {
override fun queryQuestionDtoByWriterId(page: Int, user: User): PageResponse<UserQuestionDto> {
val questions = queryFactory
.selectFrom(questions)
.where(questions.author.eq(user))
.getUserQuestionListDto(user)

return PageUtil.toPageResponse(
page = page,
page = page.toLong(),
list = questions
)
}
Expand All @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,8 +38,14 @@ class UserController(
fun queryUserAttendance(): UserAttendanceResponse =
userService.queryUserAttendance()

@GetMapping("/question/{page}")
fun getMyQuestion(@PathVariable("page") page: Long): List<UserQuestionResponse> {
return userService.getMyQuestion(page)
@GetMapping("/question")
fun getMyQuestion(@Valid @ModelAttribute request: GetMyQuestionRequest): List<UserQuestionResponse> {
return userService.getMyQuestion(request)
}

@GetMapping("/set")
fun getMyQuestionSet(@Valid @ModelAttribute request: GetMyQuestionRequest): QuestionSetListResponse {

return userService.getMyQuestionSet(request)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ data class UpdateUserInfoRequest(
val job: String,

val jobDuration: Int
)

data class GetMyQuestionRequest(
val page: Int
)
18 changes: 15 additions & 3 deletions src/main/kotlin/kr/hs/dsm/inq/domain/user/service/UserService.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -94,10 +99,10 @@ class UserService(
)
}

fun getMyQuestion(page: Long): List<UserQuestionResponse> {
fun getMyQuestion(request: GetMyQuestionRequest): List<UserQuestionResponse> {
val user = SecurityUtil.getCurrentUser()

val usersQuestions = questionsRepository.queryQuestionDtoByWriterId(page, user)
val usersQuestions = questionsRepository.queryQuestionDtoByWriterId(request.page, user)

return usersQuestions.list.map {
UserQuestionResponse.of(
Expand All @@ -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)
}
}

0 comments on commit d782e21

Please sign in to comment.