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 120ba4a..5814f45 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 @@ -10,12 +10,11 @@ import kr.hs.dsm.inq.domain.question.persistence.QQuestionTags.questionTags import kr.hs.dsm.inq.domain.question.persistence.QQuestions.questions import kr.hs.dsm.inq.domain.question.persistence.QTags.tags import kr.hs.dsm.inq.domain.question.persistence.Questions -import kr.hs.dsm.inq.domain.question.persistence.dto.QQuestionDetailDto -import kr.hs.dsm.inq.domain.question.persistence.dto.QQuestionDto -import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionDetailDto -import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionDto +import kr.hs.dsm.inq.domain.question.persistence.dto.* import kr.hs.dsm.inq.domain.user.persistence.QUser import kr.hs.dsm.inq.domain.user.persistence.User +import kr.hs.dsm.inq.domain.user.presentation.dto.QUserQuestionDto +import kr.hs.dsm.inq.domain.user.presentation.dto.UserQuestionDto import org.springframework.data.repository.CrudRepository import org.springframework.stereotype.Repository @@ -35,6 +34,8 @@ interface CustomQuestionRepository { fun queryQuestionDtoOrderByAnswerCount(user: User, page: Long): PageResponse fun queryQuestionDtoById(id: Long, user: User): QuestionDto? fun queryQuestionDetailDtoById(user: User, questionId: Long): QuestionDetailDto? + + fun queryGetQuestionDtoById(user: User): List } @Repository @@ -109,16 +110,6 @@ class CustomQuestionRepositoryImpl( ) ) ) - -// val questionId: Long, -// val question: String, -// val category: Category, -// val username: String, -// val job: String, -// val jobDuration: Int, -// tagList: List?, -// val isAnswered: Boolean, -// val isFavorite: Boolean } override fun queryQuestionDetailDtoById( @@ -159,4 +150,29 @@ class CustomQuestionRepositoryImpl( ) ) } + + override fun queryGetQuestionDtoById(user: User): List { + return queryFactory + .selectFrom(questions) + .where(questions.author.eq(user)) + .getUserQuestionListDto(user) + } + + fun JPAQuery.getUserQuestionListDto(user: User): List = run { + return@run innerJoin(questionTags).on(questionTags.problems.eq(questions.problem)) + .innerJoin(tags).on(tags.id.eq(questionTags.id.tagId)) + .transform( + GroupBy.groupBy(questions) + .list( + QUserQuestionDto( + /* questionId = */ questions.id, + /* question = */ questions.question, + /* createdAt = */ questions.createdAt, + /* category = */ questions.category, + /* tagList = */ GroupBy.list(tags), + /* isAnswered = */ questions.isNull + ) + ) + ) + } } \ No newline at end of file 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 647567c..524b54c 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 @@ -5,7 +5,6 @@ import kr.hs.dsm.inq.common.util.PageUtil import kr.hs.dsm.inq.domain.question.persistence.* import kr.hs.dsm.inq.domain.question.persistence.dto.* import java.time.LocalDateTime -import java.util.Date data class CreateQuestionResponses( val questionId: Long 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 55e0aa0..d509c25 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,16 +2,11 @@ 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.user.presentation.dto.GetMyQuestionResponse import kr.hs.dsm.inq.domain.user.presentation.dto.* import kr.hs.dsm.inq.domain.user.service.UserService import org.springframework.http.HttpStatus -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.PutMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.ResponseStatus -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* @RequestMapping("/user") @RestController @@ -42,4 +37,8 @@ class UserController( fun queryUserAttendance(): UserAttendanceResponse = userService.queryUserAttendance() + @GetMapping("/question/{page}") + fun getMyQuestion(@PathVariable("page") page: Int): GetMyQuestionResponse { + return userService.getMyQuestion(page) + } } \ No newline at end of file diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Responses.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Responses.kt index 172d6ab..07128b5 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Responses.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/Responses.kt @@ -24,4 +24,16 @@ data class UserAttendanceResponse( val saturday: Boolean, val sunday: Boolean, -) \ No newline at end of file +) + +data class GetMyQuestionResponse( + val questionList: List +) { + companion object { + fun of(questionList: List) = questionList.run{ + GetMyQuestionResponse( + questionList = questionList.map { it } + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/UserQuestionDto.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/UserQuestionDto.kt new file mode 100644 index 0000000..a68bd28 --- /dev/null +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/user/presentation/dto/UserQuestionDto.kt @@ -0,0 +1,17 @@ +package kr.hs.dsm.inq.domain.user.presentation.dto + +import com.querydsl.core.annotations.QueryProjection +import kr.hs.dsm.inq.domain.question.persistence.Category +import kr.hs.dsm.inq.domain.question.persistence.Tags +import java.time.LocalDateTime + +class UserQuestionDto @QueryProjection constructor ( + val questionId: Long, + val question: String, + val createdAt: LocalDateTime, + val category: Category, + tagList: List?, + val isAnswered: Boolean +) { + val tagList = tagList ?: listOf() +} \ 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 214e74d..33f0424 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 @@ -2,6 +2,8 @@ package kr.hs.dsm.inq.domain.user.service import kr.hs.dsm.inq.common.dto.TokenResponse import kr.hs.dsm.inq.common.util.SecurityUtil +import kr.hs.dsm.inq.domain.question.persistence.repository.QuestionsRepository +import kr.hs.dsm.inq.domain.user.presentation.dto.GetMyQuestionResponse import kr.hs.dsm.inq.domain.user.exception.AttendanceNotFound import kr.hs.dsm.inq.domain.user.exception.PasswordMismatchException import kr.hs.dsm.inq.domain.user.exception.UserAlreadyExist @@ -12,7 +14,6 @@ import kr.hs.dsm.inq.domain.user.presentation.dto.* import kr.hs.dsm.inq.global.security.token.JwtGenerator import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service -import java.time.LocalDate import java.time.LocalDateTime import javax.transaction.Transactional import kr.hs.dsm.inq.domain.user.persistence.repository.UserRepository @@ -22,7 +23,8 @@ class UserService( private val userRepository: UserRepository, private val passwordEncoder: PasswordEncoder, private val jwtGenerator: JwtGenerator, - private val attendanceRepository: AttendanceRepository + private val attendanceRepository: AttendanceRepository, + private val questionsRepository: QuestionsRepository ) { fun signIn(request: UserSignInRequest): TokenResponse { @@ -90,4 +92,12 @@ class UserService( sunday = attendance.sunday ) } + + fun getMyQuestion(page: Int): GetMyQuestionResponse { + val user = SecurityUtil.getCurrentUser() + + val usersQuestions = questionsRepository.queryGetQuestionDtoById(user) + + return GetMyQuestionResponse.of(usersQuestions) + } } \ No newline at end of file