Skip to content

Commit

Permalink
fix: 페이징 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
12xii committed Nov 28, 2023
1 parent 9f8ec68 commit f4fa5dc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kr.hs.dsm.inq.domain.question.persistence.dto.*
import java.time.LocalDateTime
import java.util.UUID
import kr.hs.dsm.inq.domain.user.persistence.User
import kr.hs.dsm.inq.domain.user.persistence.dto.UserQuestionDto

data class CreateQuestionResponses(
val questionId: Long
Expand Down Expand Up @@ -150,6 +151,36 @@ data class UserQuestionResponse(
createdAt = createdAt
)
}

fun of(questionDetail: UserQuestionDto) = questionDetail.run {
UserQuestionResponse(
questionId = questionId,
authorId = authorId,
username = username,
job = job,
jobDuration = jobDuration,
question = question,
category = category,
tags = tagList.map { it.tag },
isFavorite = isFavorite,
exemplaryAnswer = exemplaryAnswer,
createdAt = createdAt
)
}
}
}

data class UserQuestionListResponse(
val hasNext: Boolean,
val questionList: List<UserQuestionResponse>,
) {
companion object {
fun of(pageResponse: PageResponse<UserQuestionDto>) = pageResponse.run {
UserQuestionListResponse(
hasNext = hasNext,
questionList = list.map { UserQuestionResponse.of(it) }
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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.UserQuestionListResponse
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 @@ -45,7 +46,7 @@ class UserController(


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

Expand Down
21 changes: 3 additions & 18 deletions src/main/kotlin/kr/hs/dsm/inq/domain/user/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionDetailDto
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.UserQuestionListResponse
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 Down Expand Up @@ -117,28 +118,12 @@ class UserService(
return QuestionUserAnsweredResponse.of(questionList, questionSetList, questionSetDetailsList)
}

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

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

return usersQuestions.list.map {
UserQuestionResponse.of(
questionDetail = QuestionDetailDto(
questionId = it.questionId,
authorId = it.authorId,
username = it.username,
job = it.job,
jobDuration = it.jobDuration,
question = it.question,
category = it.category,
tagList = it.tagList,
isFavorite = it.isFavorite,
createdAt = it.createdAt
),
exemplaryAnswer = it.exemplaryAnswer
)
}
return UserQuestionListResponse.of(usersQuestions)
}

fun getMyQuestionSet(request: GetMyQuestionRequest): QuestionSetListResponse {
Expand Down

0 comments on commit f4fa5dc

Please sign in to comment.