From 68ebfa0ab886760fb7fba07420409c882902fede Mon Sep 17 00:00:00 2001 From: swdevsw98 <102571918+swdevsw98@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:50:52 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EB=82=B4=EA=B0=80=20=EC=93=B4=20?= =?UTF-8?q?=EB=8C=93=EA=B8=80=EC=97=90=20=EA=B3=B5=EC=A7=80=EC=99=80=20?= =?UTF-8?q?=ED=8E=80=EC=8B=9C=EC=8A=A4=ED=85=9C=EB=8F=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix : 내가 쓴 댓글에 공지와 펀시스템도 추가 * fix : user isDeleted 필터링 추가 --- .../article/dto/response/CommentResponse.kt | 15 ++++++++++++--- .../domain/article/model/entity/Comment.kt | 2 ++ .../article/model/repository/CommentRepository.kt | 2 +- .../domain/myPage/service/MyPageService.kt | 2 +- .../daitssuapi/domain/user/model/entity/User.kt | 2 ++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/example/daitssuapi/domain/article/dto/response/CommentResponse.kt b/src/main/kotlin/com/example/daitssuapi/domain/article/dto/response/CommentResponse.kt index 9948ce51..91531329 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/article/dto/response/CommentResponse.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/article/dto/response/CommentResponse.kt @@ -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) { @@ -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 ) } } diff --git a/src/main/kotlin/com/example/daitssuapi/domain/article/model/entity/Comment.kt b/src/main/kotlin/com/example/daitssuapi/domain/article/model/entity/Comment.kt index f5436a4f..15ab4eff 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/article/model/entity/Comment.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/article/model/entity/Comment.kt @@ -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") diff --git a/src/main/kotlin/com/example/daitssuapi/domain/article/model/repository/CommentRepository.kt b/src/main/kotlin/com/example/daitssuapi/domain/article/model/repository/CommentRepository.kt index 9ddeef6b..38c66faa 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/article/model/repository/CommentRepository.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/article/model/repository/CommentRepository.kt @@ -10,5 +10,5 @@ interface CommentRepository : JpaRepository { fun findByFunSystemId(funSystemId: Long): List - fun findByWriterIdAndIsDeletedFalseOrderByIdDesc(userId: Long): List + fun findByWriterIdOrderByIdDesc(userId: Long): List } diff --git a/src/main/kotlin/com/example/daitssuapi/domain/myPage/service/MyPageService.kt b/src/main/kotlin/com/example/daitssuapi/domain/myPage/service/MyPageService.kt index 8d44b8c4..3b5a236f 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/myPage/service/MyPageService.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/myPage/service/MyPageService.kt @@ -29,7 +29,7 @@ class MyPageService( fun getComments(userId: Long): List { 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) } } diff --git a/src/main/kotlin/com/example/daitssuapi/domain/user/model/entity/User.kt b/src/main/kotlin/com/example/daitssuapi/domain/user/model/entity/User.kt index a8f556c8..2c3d7f5f 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/user/model/entity/User.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/user/model/entity/User.kt @@ -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,