Skip to content

Commit

Permalink
fix : Comment 조회 시 닉네임도 전달 (#111)
Browse files Browse the repository at this point in the history
* feat: 댓글 조회 시 작성자 닉네임도 함께 전달

* test: 테스트 sql 세미콜론 빠진 것 수정
  • Loading branch information
kkanggu authored Jan 23, 2024
1 parent acf13fd commit 8bbb1cf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,6 +17,7 @@ data class CommentResponse(
CommentResponse(
commentId = id,
userId = writer.id,
nickname = writer.nickname,
content = content,
originalCommentId = originalId,
createdAt = createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -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)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/resources/h2-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
(1, '6/23 (금) 시스템 점검 및 업데이트 안내', '안녕하세요 다잇슈입니다. 더욱 쾌적하고 안정적인 서비스 지원을 위해 아래와 같이 점검이 진행됩니다.', '2023-12-06 06:44:07', '2023-12-06 06:44:07');

0 comments on commit 8bbb1cf

Please sign in to comment.