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,