Skip to content

Commit

Permalink
feat: like 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaisqls committed Nov 3, 2023
1 parent 7d0c077 commit b9024a4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
)
)
Expand All @@ -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(
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand All @@ -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,
Expand All @@ -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)
}
Expand All @@ -322,8 +330,6 @@ class QuestionService(
answerCount = 0,
description = request.description,
category = request.category,
likeCount = 0,
dislikeCount = 0,
viewCount = 0,
post = post,
problem = problem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down

0 comments on commit b9024a4

Please sign in to comment.