Skip to content

Commit

Permalink
fix : 내가 쓴 댓글에 공지와 펀시스템도 추가 (#113)
Browse files Browse the repository at this point in the history
* fix : 내가 쓴 댓글에 공지와 펀시스템도 추가

* fix : user isDeleted 필터링 추가
  • Loading branch information
swdevsw98 committed Feb 27, 2024
1 parent 0824334 commit 68ebfa0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ data class CommentResponse(
val updatedAt: LocalDateTime,
val title: String? = null,
val topic: Topic? = null,
val articleId: Long? = null
val articleId: Long? = null,
val noticeId: Long? = null,
val funSystemId: Long? = null
) {
companion object {
fun of(comment: Comment): CommentResponse = with(comment) {
Expand All @@ -26,9 +28,16 @@ data class CommentResponse(
originalCommentId = originalId,
createdAt = createdAt,
updatedAt = updatedAt,
title = article?.title,
title = when{
article != null -> article?.title
notice != null -> notice?.title
funSystem != null -> funSystem?.title
else -> null
},
topic = article?.topic,
articleId = article?.id
articleId = article?.id,
noticeId = notice?.id,
funSystemId = funSystem?.id
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import org.hibernate.annotations.Where

@Entity
@Where(clause = "is_deleted = 0")
class Comment(
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface CommentRepository : JpaRepository<Comment, Long> {

fun findByFunSystemId(funSystemId: Long): List<Comment>

fun findByWriterIdAndIsDeletedFalseOrderByIdDesc(userId: Long): List<Comment>
fun findByWriterIdOrderByIdDesc(userId: Long): List<Comment>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MyPageService(
fun getComments(userId: Long): List<CommentResponse> {
userRepository.findByIdOrNull(id = userId) ?: throw DefaultException(errorCode = ErrorCode.USER_NOT_FOUND)

return commentRepository.findByWriterIdAndIsDeletedFalseOrderByIdDesc(userId = userId).map {
return commentRepository.findByWriterIdOrderByIdDesc(userId = userId).map {
CommentResponse.of(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Where

@Entity
@Table(name = "users")
@Where(clause = "is_deleted = 0")
class User(
val studentId: String,

Expand Down

0 comments on commit 68ebfa0

Please sign in to comment.