Skip to content

Commit

Permalink
fix: 비밀댓글
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaisqls committed Nov 15, 2023
1 parent 3871640 commit fcf59fe
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Comments(
@JoinColumn(name = "post_id", columnDefinition = "BIGINT", nullable = false)
var post: Post,

@Column(columnDefinition = "BIT(1)", nullable = false)
val isPrivate: Boolean,

@Column(nullable = false, updatable = false, columnDefinition = "DATETIME(6)")
val createdAt: LocalDateTime = LocalDateTime.now()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class QuestionSetDetailDto @QueryProjection constructor(
val name: String,
val createdAt: LocalDateTime,
val description: String,
val writerId: Long,
val username: String,
val job: String,
val jobDuration: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ import org.springframework.stereotype.Repository

interface AnswersRepository : CrudRepository<Answers, Long>, CustomAnswerRepository {
fun findByQuestionsIdAndIsExamplaryIsTrue(questionId: Long): Answers
fun findByQuestionsIdAndIsExamplaryIsFalse(questionId: Long): List<Answers>
}

interface CustomAnswerRepository {
fun queryAnswerByQuestionId(questionId: Long): List<AnswersDto>
fun queryExemplaryAnswerDto(questionId: Long, authorId: Long): AnswersDto?
fun querySolvedQuestionDtoByUserId(userId: Long, page: Long): PageResponse<QuestionUserSolvedDto>
fun querySolvedQuestionSetDtoByUserId(userId: Long, page: Long): PageResponse<QuestionSetUserSolvedDto>
fun queryQuestionDtoByQuestionSetId(userId: Long, questionSetId: Long): List<QuestionSetDetailsUserSolved>
Expand All @@ -42,30 +39,14 @@ class CustomAnswerRepositoryImpl(
private val queryFactory: JPAQueryFactory
) : CustomAnswerRepository {

override fun queryAnswerByQuestionId(questionId: Long): List<AnswersDto> {
return queryFactory
.selectFrom(answers)
.where(answers.questions.id.eq(questionId))
.innerJoin(questions).on(questions.id.eq(questionId))
.getAnswerDetailDto()
}

override fun queryExemplaryAnswerDto(questionId: Long, authorId: Long): AnswersDto? {
val answerResult = queryFactory
.selectFrom(answers)
.innerJoin(questions).on(questions.id.eq(questionId))
.getAnswerDetailDto()
return if (answerResult.isEmpty()) null else answerResult[0]
}

private fun <T> JPAQuery<T>.getAnswerDetailDto(): MutableList<AnswersDto> {
val like = QLike("likes")
val dislike = QLike("dislikes")
return innerJoin(user).on(user.id.eq(answers.writer.id))
.innerJoin(post).on(post.id.eq(answers.post.id))
.leftJoin(like).on(like.post.id.eq(post.id).and(like.isLiked.isTrue))
.leftJoin(dislike).on(dislike.post.id.eq(post.id).and(dislike.isLiked.isFalse))
.leftJoin(comments).on(comments.post.eq(answers.post))
.leftJoin(comments).on(comments.post.id.eq(answers.post.id))
.transform(
GroupBy.groupBy(answers.id)
.list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class CustomQuestionSetsRepositoryImpl(
/* name = */ questionSets.name,
/* createdAt = */ questionSets.createdAt,
/* description = */ questionSets.description,
/* writerId = */ author.id,
/* username = */ author.username,
/* job = */ author.job,
/* jobDuration = */ author.jobDuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ data class GetQuestionSetsRequest(
data class CreateCommentRequest(
@field:NotBlank
@field:Size(max = 1000)
val comment: String
val comment: String,

val isPrivate: Boolean
)

data class GetQuestionSetRankRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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.UUID
import kr.hs.dsm.inq.domain.user.persistence.User

data class CreateQuestionResponses(
val questionId: Long
Expand Down Expand Up @@ -101,7 +103,7 @@ data class QuestionDetailResponse(
val createdAt: LocalDateTime
) {
companion object {
fun of(questionDetail: QuestionDetailDto, answer: AnswersDto) = questionDetail.run {
fun of(questionDetail: QuestionDetailDto, answer: AnswersDto, user: User) = questionDetail.run {
QuestionDetailResponse(
questionId = questionId,
authorId = authorId,
Expand All @@ -112,7 +114,7 @@ data class QuestionDetailResponse(
category = category,
tags = tagList.map { it.tag },
isFavorite = isFavorite,
exemplaryAnswer = AnswerResponse.of(answer),
exemplaryAnswer = AnswerResponse.of(answer, user),
createdAt = createdAt
)
}
Expand Down Expand Up @@ -166,7 +168,7 @@ data class AnswerResponse(
val comments: List<CommentResponse>
) {
companion object {
fun of(answers: AnswersDto) = answers.run {
fun of(answers: AnswersDto, user: User) = answers.run {
AnswerResponse(
id = answers.id,
username = username,
Expand All @@ -177,7 +179,10 @@ data class AnswerResponse(
isLiked = isLiked,
dislikeCount = dislikeCount,
isDisliked = isDisliked,
comments = commentList.map { CommentResponse.of(it) }
comments = commentList.distinct().map { CommentResponse.of(
comments = it,
isOwner = answers.writerId == user.id || it.writer.id == user.id
) }
)
}
}
Expand All @@ -187,15 +192,19 @@ data class CommentResponse(
val username: String,
val job: String,
val jobDuration: Int,
val comment: String
val comment: String,
val isPrivate: Boolean,
val isAccessible: Boolean
) {
companion object {
fun of(comments: Comments) = comments.run {
fun of(comments: Comments, isOwner: Boolean) = comments.run {
CommentResponse(
username = writer.username,
job = writer.job,
jobDuration = writer.jobDuration,
comment = comment
comment = comment,
isPrivate = isPrivate,
isAccessible = !isPrivate || isOwner
)
}
}
Expand Down Expand Up @@ -322,7 +331,7 @@ data class GetQuestionSetDetailResponse(
val comments: List<CommentResponse>
) {
companion object {
fun of(questionSetDetail: QuestionSetDetailDto, questionList: List<Questions>) = questionSetDetail.run {
fun of(questionSetDetail: QuestionSetDetailDto, questionList: List<Questions>, user: User) = questionSetDetail.run {
GetQuestionSetDetailResponse(
questionSetId = questionSetId,
name = name,
Expand All @@ -347,7 +356,10 @@ data class GetQuestionSetDetailResponse(
isDisliked = isDisliked,
isFavorite = isFavorite,
tags = tagList.map { it.tag },
comments = commentList.map { CommentResponse.of(it) }
comments = commentList.distinct().map { CommentResponse.of(
comments = it,
isOwner = writerId == user.id || it.writer.id == user.id
) }
)
}
}
Expand All @@ -370,10 +382,10 @@ data class OthersAnswerResponse(
val answerList: List<AnswerResponse>
) {
companion object {
fun of(pageResponse: PageResponse<AnswersDto>) = pageResponse.run {
fun of(pageResponse: PageResponse<AnswersDto>, user: User) = pageResponse.run {
OthersAnswerResponse(
hasNext = hasNext,
answerList = list.map { AnswerResponse.of(it) }
answerList = list.map { AnswerResponse.of(answers = it, user = user) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class CommentService(
Comments(
comment = request.comment,
writer = user,
post = questionSets.post
post = questionSets.post,
isPrivate = request.isPrivate
)
)
}
Expand All @@ -41,7 +42,8 @@ class CommentService(
Comments(
comment = request.comment,
writer = user,
post = answer.post
post = answer.post,
isPrivate = request.isPrivate
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ class QuestionService(
dislikeCount = post.dislikeCount,
isDisliked = like?.isLiked == false,
commentList = comments
)
),
user = user
)
}

Expand Down Expand Up @@ -439,7 +440,11 @@ class QuestionService(
val setQuestionList = setQuestionRepository.findAllBySetId(questionSetDetail.questionSetId)
val questionList = questionsRepository.findByIdIn(setQuestionList.map { it.question.id })

return GetQuestionSetDetailResponse.of(questionSetDetail, questionList)
return GetQuestionSetDetailResponse.of(
questionSetDetail = questionSetDetail,
questionList = questionList,
user = user
)
}

fun answerQuestionSet(questionSetId: Long){
Expand Down Expand Up @@ -551,11 +556,12 @@ class QuestionService(
}

fun othersAnswer(questionId: Long, request: GetOthersAnswerRequest): OthersAnswerResponse {
SecurityUtil.getCurrentUser()

val user = SecurityUtil.getCurrentUser()
val answerList = answersRepository
.queryAnswerByQuestionIdOrderByLikeCount(request.page, questionId)

return OthersAnswerResponse.of(answerList)
return OthersAnswerResponse.of(
pageResponse = answerList,
user = user
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class UserService(
val questionSetList = answersRepository.querySolvedQuestionSetDtoByUserId(user.id, request.page)
val questionSetDetailsList = questionSetList.list.flatMap {
answersRepository.queryQuestionDtoByQuestionSetId(
user.id,
it.questionSetId
userId = user.id,
questionSetId = it.questionSetId
)
}

Expand Down Expand Up @@ -152,7 +152,6 @@ class UserService(
@Transactional
fun userAttendanceCheck() {
val user = SecurityUtil.getCurrentUser()

val today = LocalDate.now().dayOfWeek

val attendance = attendanceRepository.findByUserId(user.id)
Expand Down

0 comments on commit fcf59fe

Please sign in to comment.