Skip to content

Commit

Permalink
Merge branch 'main' into question-set-like
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaisqls authored Nov 2, 2023
2 parents b6246c8 + 194bc54 commit 2103e88
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object QuestionNotFoundException : CustomException(
)

object QuestionSetNotFoundException : CustomException(
DomainErrorCode.QUESTION_NOT_FOUND
DomainErrorCode.QUESTION_SET_NOT_FOUND
)

object AnswerNotFoundException : CustomException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class QuestionSets (
@Column(columnDefinition = "DATETIME(6)", nullable = false, updatable = false)
var createdAt: LocalDateTime = LocalDateTime.now(),

@Column(columnDefinition = "VARCHAR(1000)", nullable = false)
var description: String,

@Column(columnDefinition = "INT", nullable = false)
var answerCount: Int,

Expand All @@ -27,6 +30,9 @@ class QuestionSets (
@Column(columnDefinition = "INT", nullable = false)
var likeCount: Int,

@Column(columnDefinition = "INT", nullable = false)
val dislikeCount: Int,

@Column(columnDefinition = "INT", nullable = false)
var viewCount: Int,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package kr.hs.dsm.inq.domain.question.persistence.dto

import com.querydsl.core.annotations.QueryProjection
import kr.hs.dsm.inq.domain.question.persistence.Category
import org.aspectj.weaver.patterns.TypePatternQuestions.Question
import java.util.Objects

class CategoriesDto (
class CategoriesDto @QueryProjection constructor (
val category: Category,
val count: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class QuestionSetDetailDto @QueryProjection constructor(
val questionSetId: Long,
val name: String,
val createdAt: LocalDateTime,
val description: String,
val username: String,
val job: String,
val jobDuration: Int,
val category: Category,
val likeCount: Int,
val dislikeCount: Int,
val viewCount: Int,
val isLiked: Boolean,
val isDisliked: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package kr.hs.dsm.inq.domain.question.persistence.repository

import com.querydsl.core.ResultTransformer
import com.querydsl.core.group.GroupBy
import com.querydsl.core.types.Expression
import com.querydsl.core.types.Ops
import com.querydsl.core.types.dsl.Expressions
import com.querydsl.jpa.impl.JPAQuery
import com.querydsl.jpa.impl.JPAQueryFactory
import kr.hs.dsm.inq.common.util.PageResponse
import kr.hs.dsm.inq.common.util.PageUtil
import kr.hs.dsm.inq.domain.question.persistence.*
import kr.hs.dsm.inq.domain.question.persistence.QAnswers.answers
import kr.hs.dsm.inq.domain.question.persistence.QComments.comments
import kr.hs.dsm.inq.domain.question.persistence.QQuestionSets.questionSets
import kr.hs.dsm.inq.domain.question.persistence.QQuestionSolvingHistory.questionSolvingHistory
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.dto.QAnswersDto
import kr.hs.dsm.inq.domain.question.persistence.dto.QQuestionSetDetailDto
import kr.hs.dsm.inq.domain.question.persistence.dto.QQuestionSetDto
import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionSetDetailDto
import kr.hs.dsm.inq.domain.question.persistence.dto.QuestionSetDto
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 org.springframework.data.repository.CrudRepository
Expand All @@ -35,7 +35,7 @@ interface CustomQuestionSetsRepository {
page: Long
): PageResponse<QuestionSetDto>

fun queryQuestionSetDtoById(
fun queryQuestionSetDetailDtoById(
user: User,
id: Long
): QuestionSetDetailDto?
Expand Down Expand Up @@ -67,11 +67,12 @@ class CustomQuestionSetsRepositoryImpl(
}

@Transactional
override fun queryQuestionSetDtoById(
override fun queryQuestionSetDetailDtoById(
user: User,
id: Long
): QuestionSetDetailDto? {
queryFactory

queryFactory
.update(questionSets)
.set(questionSets.viewCount, questionSets.viewCount.add(1))
.where(questionSets.id.eq(id))
Expand Down Expand Up @@ -119,32 +120,34 @@ class CustomQuestionSetsRepositoryImpl(
val author = QUser("writer")
val liked = QLike("liked")
val favorite = QFavorite("favorite")

return@run leftJoin(questionTags).on(questionTags.problems.eq(questionSets.problem))
.leftJoin(tags).on(tags.id.eq(questionTags.id.tagId))
.innerJoin(author).on(author.id.eq(questionSets.author.id))
.leftJoin(liked).on(liked.id.userId.eq(user.id)).on(liked.post.eq(questionSets.post))
.leftJoin(favorite).on(favorite.id.userId.eq(user.id)).on(favorite.problemId.eq(questionSets.problem))
.rightJoin(comments).on(comments.post.eq(questionSets.post))
.leftJoin(comments).on(comments.post.eq(questionSets.post))
.transform(
GroupBy.groupBy(questionSets)
.list(
QQuestionSetDetailDto(
/* questionSetId = */ questionSets.id,
/* name = */ questionSets.name,
/* createdAt = */ questionSets.createdAt,
/* description = */ questionSets.description,
/* username = */ author.username,
/* job = */ author.job,
/* jobDuration = */ author.jobDuration,
/* category = */ questionSets.category,
/* likeCount = */ questionSets.likeCount,
/* dislikeCount = */ questionSets.dislikeCount,
/* viewCount = */ questionSets.viewCount,
/* isLiked = */ liked.isLiked.isTrue,
/* isDisliked = */ liked.isLiked.isFalse,
/* isFavorite = */ favorite.isNotNull,
/* tagList = */ GroupBy.list(tags),
/* comments = */ GroupBy.list(comments)
/* commentList = */ GroupBy.list(comments)
)
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import kr.hs.dsm.inq.domain.question.persistence.SetQuestion
import kr.hs.dsm.inq.domain.question.persistence.SetQuestionId
import org.springframework.data.repository.CrudRepository

interface SetQuestionRepository : CrudRepository<SetQuestion, SetQuestionId> {
interface SetQuestionRepository : CrudRepository<SetQuestion, SetQuestionId>, CustomQuestionRepository {
fun findAllBySetId(setId: Long): List<SetQuestion>
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class GetPopularQuestionRequest(

data class QuestionSetsRequest(
val questionSetName: String,
val description: String,
val category: Category,
val questionId: List<Long>,
val tag: List<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package kr.hs.dsm.inq.domain.question.presentation.dto

import kr.hs.dsm.inq.common.util.PageResponse
import kr.hs.dsm.inq.common.util.PageUtil
import kr.hs.dsm.inq.domain.question.persistence.Category
import kr.hs.dsm.inq.domain.question.persistence.Comments
import kr.hs.dsm.inq.domain.question.persistence.QuestionSets
import kr.hs.dsm.inq.domain.question.persistence.Tags
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
Expand Down Expand Up @@ -195,8 +192,8 @@ data class GetQuestionSetResponse(
val hasNext: Boolean,
val questionSetsList: List<QuestionSet>,
) {
companion object{
fun of(pageResponse: PageResponse<QuestionSetDto>) = pageResponse.run{
companion object {
fun of(pageResponse: PageResponse<QuestionSetDto>) = pageResponse.run {
GetQuestionSetResponse(
hasNext = hasNext,
questionSetsList = list.map { QuestionSet.of(it) }
Expand All @@ -205,21 +202,21 @@ data class GetQuestionSetResponse(
}
}

data class QuestionSet (
val questionSetId : Long?,
val questionSetName : String?,
data class QuestionSet(
val questionSetId: Long?,
val questionSetName: String?,
val createdAt: LocalDateTime,
val category: Category?,
val username : String?,
val job : String?,
val jobDuration : Int?,
val tags : List<String>?,
val isAnswered : Boolean?,
val likeCount : Int?,
val viewCount : Int?,
val username: String?,
val job: String?,
val jobDuration: Int?,
val tags: List<String>?,
val isAnswered: Boolean?,
val likeCount: Int?,
val viewCount: Int?,
) {
companion object {
fun of (dto: QuestionSetDto) = dto.run {
fun of(dto: QuestionSetDto) = dto.run {
QuestionSet(
questionSetId = questionSetId,
questionSetName = questionSetName,
Expand All @@ -241,11 +238,13 @@ data class GetQuestionSetDetailResponse(
val questionSetId: Long,
val name: String,
val createdAt: LocalDateTime,
val description: String,
val username: String,
val job: String,
val jobDuration: Int,
val category: Category,
val category: List<CategoriesDto?>?,
val likeCount: Int,
val dislikeCount: Int,
val viewCount: Int,
val isLiked: Boolean,
val isDisliked: Boolean,
Expand All @@ -254,16 +253,26 @@ data class GetQuestionSetDetailResponse(
val comments: List<CommentResponse>
) {
companion object {
fun of(questionSetDetail: QuestionSetDetailDto) = questionSetDetail.run {
fun of(questionSetDetail: QuestionSetDetailDto, questionList: List<Questions>) = questionSetDetail.run {
GetQuestionSetDetailResponse(
questionSetId = questionSetId,
name = name,
createdAt = createdAt,
description = description,
username = username,
job = job,
jobDuration = jobDuration,
category = category,
category = questionList
.groupingBy { it.category }
.eachCount()
.map {
CategoriesDto(
category = it.key,
count = it.value
)
},
likeCount = likeCount,
dislikeCount = dislikeCount,
viewCount = viewCount,
isLiked = isLiked,
isDisliked = isDisliked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kr.hs.dsm.inq.domain.question.exception.AlreadyLikedPostException
import kr.hs.dsm.inq.domain.question.exception.AnswerNotFoundException
import kr.hs.dsm.inq.domain.question.exception.QuestionNotFoundException
import kr.hs.dsm.inq.domain.question.exception.QuestionSetNotFoundException
import kr.hs.dsm.inq.domain.question.exception.*
import kr.hs.dsm.inq.domain.question.persistence.*
import kr.hs.dsm.inq.domain.question.persistence.dto.AnswersDto
import kr.hs.dsm.inq.domain.question.persistence.dto.CategoriesDto
Expand Down Expand Up @@ -319,8 +320,10 @@ class QuestionService(
QuestionSets(
name = request.questionSetName,
answerCount = 0,
description = request.description,
category = request.category,
likeCount = 0,
dislikeCount = 0,
viewCount = 0,
post = post,
problem = problem,
Expand Down Expand Up @@ -395,11 +398,14 @@ class QuestionService(
val user = SecurityUtil.getCurrentUser()

val questionSetDetail = questionSetId.run {
questionSetsRepository.queryQuestionSetDtoById(user, questionSetId)
questionSetsRepository.queryQuestionSetDetailDtoById(user, questionSetId)
?: throw QuestionSetNotFoundException
}

return GetQuestionSetDetailResponse.of(questionSetDetail)
val setQuestionList = setQuestionRepository.findAllBySetId(questionSetDetail.questionSetId)
val questionList = questionsRepository.findByIdIn(setQuestionList.map { it.question.id })

return GetQuestionSetDetailResponse.of(questionSetDetail, questionList)
}

fun answerQuestionSet(questionSetId: Long){
Expand Down

0 comments on commit 2103e88

Please sign in to comment.