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 107e43c5..6ddd930c 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 @@ -6,6 +6,7 @@ import java.time.LocalDateTime data class CommentResponse( val commentId: Long, val userId: Long, + val nickname: String? = null, val content: String, val originalCommentId: Long? = null, val createdAt: LocalDateTime, @@ -16,6 +17,7 @@ data class CommentResponse( CommentResponse( commentId = id, userId = writer.id, + nickname = writer.nickname, content = content, originalCommentId = originalId, createdAt = createdAt, diff --git a/src/main/kotlin/com/example/daitssuapi/domain/article/service/ArticleService.kt b/src/main/kotlin/com/example/daitssuapi/domain/article/service/ArticleService.kt index b34fe5e9..77792be3 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/article/service/ArticleService.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/article/service/ArticleService.kt @@ -217,14 +217,7 @@ class ArticleService( ) ) - return CommentResponse( - commentId = comment.id, - userId = comment.writer.id, - content = comment.content, - originalCommentId = comment.originalId, - createdAt = comment.createdAt, - updatedAt = comment.updatedAt - ) + return CommentResponse.of(comment = comment) } @Transactional @@ -287,16 +280,7 @@ class ArticleService( articleRepository.findByIdOrNull(articleId) ?: throw DefaultException(errorCode = ErrorCode.ARTICLE_NOT_FOUND) - return commentRepository.findByArticleId(articleId = articleId).map { - CommentResponse( - commentId = it.id, - userId = it.writer.id, - content = it.content, - originalCommentId = it.originalId, - createdAt = it.createdAt, - updatedAt = it.updatedAt - ) - } + return commentRepository.findByArticleId(articleId = articleId).map(CommentResponse::of) } @Transactional diff --git a/src/main/kotlin/com/example/daitssuapi/domain/notice/service/FunSystemService.kt b/src/main/kotlin/com/example/daitssuapi/domain/notice/service/FunSystemService.kt index 2d38602c..2ea7c5a9 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/notice/service/FunSystemService.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/notice/service/FunSystemService.kt @@ -95,14 +95,7 @@ class FunSystemService( originalId = request.originalCommentId )) - return CommentResponse( - commentId = comment.id, - userId = comment.writer.id, - content = comment.content, - originalCommentId = comment.originalId, - createdAt = comment.createdAt, - updatedAt = comment.updatedAt - ) + return CommentResponse.of(comment = comment) } private fun validateComment(funSystem: FunSystem, content: String, originalCommentId: Long?) { @@ -124,15 +117,6 @@ class FunSystemService( funSystemRepository.findByIdOrNull(funSystemId) ?: throw DefaultException(errorCode = ErrorCode.FUNSYSTEM_NOT_FOUND) - return commentRepository.findByFunSystemId(funSystemId = funSystemId).map { - CommentResponse( - commentId = it.id, - userId = it.writer.id, - content = it.content, - originalCommentId = it.originalId, - createdAt = it.createdAt, - updatedAt = it.updatedAt - ) - } + return commentRepository.findByFunSystemId(funSystemId = funSystemId).map(CommentResponse::of) } } diff --git a/src/main/kotlin/com/example/daitssuapi/domain/notice/service/NoticeService.kt b/src/main/kotlin/com/example/daitssuapi/domain/notice/service/NoticeService.kt index d8d3c212..79fdb540 100644 --- a/src/main/kotlin/com/example/daitssuapi/domain/notice/service/NoticeService.kt +++ b/src/main/kotlin/com/example/daitssuapi/domain/notice/service/NoticeService.kt @@ -96,14 +96,7 @@ class NoticeService( ) ) - return CommentResponse( - commentId = comment.id, - userId = comment.writer.id, - content = comment.content, - originalCommentId = comment.originalId, - createdAt = comment.createdAt, - updatedAt = comment.updatedAt - ) + return CommentResponse.of(comment = comment) } private fun validateComment(notice: Notice, content: String, originalCommentId: Long?) { @@ -125,16 +118,7 @@ class NoticeService( noticeRepository.findByIdOrNull(noticeId) ?: throw DefaultException(errorCode = ErrorCode.ARTICLE_NOT_FOUND) - return commentRepository.findByNoticeId(noticeId = noticeId).map { - CommentResponse( - commentId = it.id, - userId = it.writer.id, - content = it.content, - originalCommentId = it.originalId, - createdAt = it.createdAt, - updatedAt = it.updatedAt - ) - } + return commentRepository.findByNoticeId(noticeId = noticeId).map(CommentResponse::of) } } diff --git a/src/test/resources/h2-data.sql b/src/test/resources/h2-data.sql index 841d2edb..b569822f 100644 --- a/src/test/resources/h2-data.sql +++ b/src/test/resources/h2-data.sql @@ -88,6 +88,7 @@ INSERT INTO notice_fs(id, title, content, category,url, image_url, created_at, u (5,'공지사항5','5번 공지 내용입니다!!','EXPERIENTIAL_ACTIVITIES','http://google.com', '{"url": []}', '1000-01-01 00:00:00','1000-01-01 00:00:00',0); INSERT INTO course_notice(id, course_id, is_active, name, registered_at, views, content, file_url) VALUES - (1, 1, true, '강의의 공지1', '2024-01-01 04:16:12', 3, '공지 상세 내용', '{"url": []}') + (1, 1, true, '강의의 공지1', '2024-01-01 04:16:12', 3, '공지 상세 내용', '{"url": []}'); + INSERT INTO service_notice(id, title, content, created_at, updated_at ) VALUES - (1, '6/23 (금) 시스템 점검 및 업데이트 안내', '안녕하세요 다잇슈입니다. 더욱 쾌적하고 안정적인 서비스 지원을 위해 아래와 같이 점검이 진행됩니다.', '2023-12-06 06:44:07', '2023-12-06 06:44:07'); \ No newline at end of file + (1, '6/23 (금) 시스템 점검 및 업데이트 안내', '안녕하세요 다잇슈입니다. 더욱 쾌적하고 안정적인 서비스 지원을 위해 아래와 같이 점검이 진행됩니다.', '2023-12-06 06:44:07', '2023-12-06 06:44:07');