diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/QuestionSets.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/QuestionSets.kt index 9f1dc34..68e1931 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/QuestionSets.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/QuestionSets.kt @@ -27,12 +27,6 @@ class QuestionSets ( @Column(columnDefinition = "VARCHAR(30)", nullable = false) var category: Category, - @Column(columnDefinition = "INT", nullable = false) - var likeCount: Int, - - @Column(columnDefinition = "INT", nullable = false) - val dislikeCount: Int, - @Column(columnDefinition = "INT", nullable = false) var viewCount: Int, diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt index 8af3e2d..fb4f422 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/question/persistence/repository/QuestionSetsRepository.kt @@ -11,6 +11,7 @@ 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.QComments.comments +import kr.hs.dsm.inq.domain.question.persistence.QPost.post 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 @@ -58,7 +59,7 @@ class CustomQuestionSetsRepositoryImpl( questionSets.name.contains(keyword ?: "") .and(category?.let { questionSets.category.eq(it)}) ) - .orderBy(questionSets.likeCount.asc()) + .orderBy(questionSets.post.likeCount.asc()) .getQuestionSetDto(user) return PageUtil.toPageResponse( @@ -94,6 +95,7 @@ class CustomQuestionSetsRepositoryImpl( .leftJoin(questionSolvingHistory) .on(questionSolvingHistory.userId.id.eq(user.id)).on(questionSolvingHistory.problem.eq(questionSets.problem)) .innerJoin(author).on(author.id.eq(questionSets.author.id)) + .innerJoin(post).on(post.id.eq(questionSets.post.id)) // .rightJoin(favorite).on(favorite.questions.id.eq(questions.id)) // .rightJoin(answers).on(answers.writer.eq(user).and(answers.questions.eq(questions))) .transform( @@ -109,7 +111,7 @@ class CustomQuestionSetsRepositoryImpl( /* jobDuration = */ author.jobDuration, /* tagList = */ GroupBy.list(tags), /* isAnswered = */ questionSolvingHistory.isNotNull, - /* likeCount = */ questionSets.likeCount, + /* likeCount = */ post.likeCount, /* viewCount = */ questionSets.viewCount, ) ) @@ -126,6 +128,7 @@ class CustomQuestionSetsRepositoryImpl( .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(post).on(post.id.eq(questionSets.post.id)) .leftJoin(favorite).on(favorite.id.userId.eq(user.id)).on(favorite.problemId.eq(questionSets.problem)) .leftJoin(comments).on(comments.post.eq(questionSets.post)) .transform( @@ -139,8 +142,8 @@ class CustomQuestionSetsRepositoryImpl( /* username = */ author.username, /* job = */ author.job, /* jobDuration = */ author.jobDuration, - /* likeCount = */ questionSets.likeCount, - /* dislikeCount = */ questionSets.dislikeCount, + /* likeCount = */ post.likeCount, + /* dislikeCount = */ post.dislikeCount, /* viewCount = */ questionSets.viewCount, /* isLiked = */ liked.isLiked.isTrue, /* isDisliked = */ liked.isLiked.isFalse, diff --git a/src/main/kotlin/kr/hs/dsm/inq/domain/question/service/QuestionService.kt b/src/main/kotlin/kr/hs/dsm/inq/domain/question/service/QuestionService.kt index 1e1c45d..91c4527 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/domain/question/service/QuestionService.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/domain/question/service/QuestionService.kt @@ -1,5 +1,11 @@ package kr.hs.dsm.inq.domain.question.service +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.ZoneOffset +import java.time.ZonedDateTime +import java.util.Date import kr.hs.dsm.inq.common.util.SecurityUtil import kr.hs.dsm.inq.common.util.defaultPage import kr.hs.dsm.inq.domain.question.exception.AlreadyDislikedPostException @@ -243,9 +249,10 @@ class QuestionService( val likeId = LikeId(post.id, user.id) val like = likeRepository.findByIdOrNull(likeId) return if (like == null) { - postRepository.save( - post.apply { addLikeCount() } - ) + post.apply { + addLikeCount() + postRepository.save(this) + } likeRepository.save( Like( id = likeId, @@ -258,9 +265,10 @@ class QuestionService( } else if (!like.isLiked) { throw AlreadyDislikedPostException } else { - postRepository.save( - post.apply { reduceLikeCount() } - ) + post.apply { + reduceLikeCount() + postRepository.save(this) + } likeRepository.deleteById(likeId) LikeResponse(isLiked = false) } @@ -285,10 +293,10 @@ class QuestionService( val likeId = LikeId(post.id, user.id) val like = likeRepository.findByIdOrNull(likeId) return if (like == null) { - // doDislike - postRepository.save( - post.apply { addDislikeCount() } - ) + post.apply { + addDislikeCount() + postRepository.save(this) + } likeRepository.save( Like( id = likeId, @@ -301,10 +309,10 @@ class QuestionService( } else if (like.isLiked) { throw AlreadyLikedPostException } else { - // cancelDislike - postRepository.save( - post.apply { reduceDislikeCount() } - ) + post.apply { + reduceDislikeCount() + postRepository.save(this) + } likeRepository.deleteById(likeId) DislikeResponse(isDisliked = false) } @@ -322,8 +330,6 @@ class QuestionService( answerCount = 0, description = request.description, category = request.category, - likeCount = 0, - dislikeCount = 0, viewCount = 0, post = post, problem = problem, diff --git a/src/main/kotlin/kr/hs/dsm/inq/global/filter/ExceptionFilter.kt b/src/main/kotlin/kr/hs/dsm/inq/global/filter/ExceptionFilter.kt index b39eb76..b3ab7b7 100644 --- a/src/main/kotlin/kr/hs/dsm/inq/global/filter/ExceptionFilter.kt +++ b/src/main/kotlin/kr/hs/dsm/inq/global/filter/ExceptionFilter.kt @@ -24,10 +24,12 @@ class ExceptionFilter( try { filterChain.doFilter(request, response) } catch (e: CustomException) { + e.printStackTrace() errorToJson(e.errorProperty, response) } catch (e: Exception) { when (e.cause) { is CustomException -> { + e.printStackTrace() errorToJson((e.cause as CustomException).errorProperty, response) } else -> {