diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/question/presentation/dto/Responses.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/question/presentation/dto/Responses.kt index 58ed39b..d13466b 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/question/presentation/dto/Responses.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/question/presentation/dto/Responses.kt @@ -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 @@ -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, +) { + companion object { + fun of(pageResponse: PageResponse) = pageResponse.run { + UserQuestionListResponse( + hasNext = hasNext, + questionList = list.map { UserQuestionResponse.of(it) } + ) + } } } 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 a446409..3b86434 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 @@ -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 @@ -45,7 +46,7 @@ class UserController( @GetMapping("/question") - fun getMyQuestion(@Valid @ModelAttribute request: GetMyQuestionRequest): List { + fun getMyQuestion(@Valid @ModelAttribute request: GetMyQuestionRequest): UserQuestionListResponse { return userService.getMyQuestion(request) } 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 53cc0d1..aa967fe 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 @@ -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 @@ -117,28 +118,12 @@ class UserService( return QuestionUserAnsweredResponse.of(questionList, questionSetList, questionSetDetailsList) } - fun getMyQuestion(request: GetMyQuestionRequest): List { + 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 {