From 934aa768b5f4705f379ce6ba26c6f0ba08a29f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=95=B8=EB=AA=A8?= Date: Sun, 27 Aug 2023 20:13:12 +0900 Subject: [PATCH] refactor: feed -> post --- .../sns_service/comment/entity/Comment.kt | 8 +-- .../feed/repository/FeedLikeRepository.kt | 6 --- .../feed/repository/FeedRepository.kt | 6 --- .../entity/Feed.kt => post/entity/Post.kt} | 6 +-- .../FeedLike.kt => post/entity/PostLike.kt} | 12 ++--- .../{feed => post}/entity/Share.kt | 8 +-- .../post/repository/PostLikeRepository.kt | 6 +++ .../post/repository/PostRepository.kt | 6 +++ .../repository/ShareRepository.kt | 4 +- .../sns_service/feed/entity/FeedEntityTest.kt | 51 ------------------- .../sns_service/post/entity/PostEntityTest.kt | 51 +++++++++++++++++++ .../entity/PostLikeTest.kt} | 24 ++++----- 12 files changed, 94 insertions(+), 94 deletions(-) delete mode 100644 sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedLikeRepository.kt delete mode 100644 sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedRepository.kt rename sns_service/src/main/kotlin/joryu/sns_service/{feed/entity/Feed.kt => post/entity/Post.kt} (90%) rename sns_service/src/main/kotlin/joryu/sns_service/{feed/entity/FeedLike.kt => post/entity/PostLike.kt} (77%) rename sns_service/src/main/kotlin/joryu/sns_service/{feed => post}/entity/Share.kt (78%) create mode 100644 sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostLikeRepository.kt create mode 100644 sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostRepository.kt rename sns_service/src/main/kotlin/joryu/sns_service/{feed => post}/repository/ShareRepository.kt (58%) delete mode 100644 sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedEntityTest.kt create mode 100644 sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostEntityTest.kt rename sns_service/src/test/kotlin/joryu/sns_service/{feed/entity/FeedLikeTest.kt => post/entity/PostLikeTest.kt} (54%) diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/Comment.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/Comment.kt index 9a1a984..5ae8ac6 100644 --- a/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/Comment.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/Comment.kt @@ -9,15 +9,15 @@ import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne import jakarta.persistence.Table -import joryu.sns_service.feed.entity.Feed import joryu.sns_service.common.entity.BaseEntity +import joryu.sns_service.post.entity.Post @Table(name = "comment") @Entity class Comment( @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "feed_id", nullable = false) - val feed: Feed, + @JoinColumn(name = "post_id", nullable = false) + val post: Post, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parent_id") @@ -25,7 +25,7 @@ class Comment( content: String, ) : BaseEntity() { - constructor() : this(Feed(), null, "") + constructor() : this(Post(), null, "") @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedLikeRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedLikeRepository.kt deleted file mode 100644 index ed121fd..0000000 --- a/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedLikeRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package joryu.sns_service.feed.repository - -import joryu.sns_service.feed.entity.FeedLike -import org.springframework.data.jpa.repository.JpaRepository - -interface FeedLikeRepository : JpaRepository diff --git a/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedRepository.kt deleted file mode 100644 index ab68ca5..0000000 --- a/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package joryu.sns_service.feed.repository - -import joryu.sns_service.feed.entity.Feed -import org.springframework.data.jpa.repository.JpaRepository - -interface FeedRepository : JpaRepository diff --git a/sns_service/src/main/kotlin/joryu/sns_service/feed/entity/Feed.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Post.kt similarity index 90% rename from sns_service/src/main/kotlin/joryu/sns_service/feed/entity/Feed.kt rename to sns_service/src/main/kotlin/joryu/sns_service/post/entity/Post.kt index 4ad4d9f..e57acab 100644 --- a/sns_service/src/main/kotlin/joryu/sns_service/feed/entity/Feed.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Post.kt @@ -1,4 +1,4 @@ -package joryu.sns_service.feed.entity +package joryu.sns_service.post.entity import jakarta.persistence.Column import jakarta.persistence.Entity @@ -8,9 +8,9 @@ import jakarta.persistence.Id import jakarta.persistence.Table import joryu.sns_service.common.entity.BaseEntity -@Table(name = "feed") +@Table(name = "post") @Entity -class Feed( +class Post( content: String, ) : BaseEntity() { constructor() : this("") diff --git a/sns_service/src/main/kotlin/joryu/sns_service/feed/entity/FeedLike.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostLike.kt similarity index 77% rename from sns_service/src/main/kotlin/joryu/sns_service/feed/entity/FeedLike.kt rename to sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostLike.kt index e107728..b29ac9e 100644 --- a/sns_service/src/main/kotlin/joryu/sns_service/feed/entity/FeedLike.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostLike.kt @@ -1,4 +1,4 @@ -package joryu.sns_service.feed.entity +package joryu.sns_service.post.entity import jakarta.persistence.Entity import jakarta.persistence.FetchType @@ -11,18 +11,18 @@ import jakarta.persistence.Table import joryu.sns_service.common.entity.BaseEntity import joryu.sns_service.profile.entity.Profile -@Table(name = "feed_like") +@Table(name = "post_like") @Entity -class FeedLike( +class PostLike( @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "profile_id", nullable = false) val likeMember: Profile, @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "feed_id", nullable = false) - val feed: Feed, + @JoinColumn(name = "post_id", nullable = false) + val post: Post, ) : BaseEntity() { - constructor() : this(Profile(), Feed()) + constructor() : this(Profile(), Post()) @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/sns_service/src/main/kotlin/joryu/sns_service/feed/entity/Share.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Share.kt similarity index 78% rename from sns_service/src/main/kotlin/joryu/sns_service/feed/entity/Share.kt rename to sns_service/src/main/kotlin/joryu/sns_service/post/entity/Share.kt index 6eb85d0..4aedb32 100644 --- a/sns_service/src/main/kotlin/joryu/sns_service/feed/entity/Share.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Share.kt @@ -1,4 +1,4 @@ -package joryu.sns_service.feed.entity +package joryu.sns_service.post.entity import jakarta.persistence.Entity import jakarta.persistence.FetchType @@ -14,10 +14,10 @@ import joryu.sns_service.common.entity.BaseEntity @Entity class Share( @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "feed_id", nullable = false) - val feed: Feed, + @JoinColumn(name = "post_id", nullable = false) + val post: Post, ) : BaseEntity() { - constructor() : this(Feed()) + constructor() : this(Post()) @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostLikeRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostLikeRepository.kt new file mode 100644 index 0000000..46f91b2 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostLikeRepository.kt @@ -0,0 +1,6 @@ +package joryu.sns_service.post.repository + +import joryu.sns_service.post.entity.PostLike +import org.springframework.data.jpa.repository.JpaRepository + +interface PostLikeRepository : JpaRepository diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostRepository.kt new file mode 100644 index 0000000..5f050ef --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostRepository.kt @@ -0,0 +1,6 @@ +package joryu.sns_service.post.repository + +import joryu.sns_service.post.entity.Post +import org.springframework.data.jpa.repository.JpaRepository + +interface PostRepository : JpaRepository diff --git a/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/ShareRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/ShareRepository.kt similarity index 58% rename from sns_service/src/main/kotlin/joryu/sns_service/feed/repository/ShareRepository.kt rename to sns_service/src/main/kotlin/joryu/sns_service/post/repository/ShareRepository.kt index a3184f3..249334e 100644 --- a/sns_service/src/main/kotlin/joryu/sns_service/feed/repository/ShareRepository.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/ShareRepository.kt @@ -1,6 +1,6 @@ -package joryu.sns_service.feed.repository +package joryu.sns_service.post.repository -import joryu.sns_service.feed.entity.Share +import joryu.sns_service.post.entity.Share import org.springframework.data.jpa.repository.JpaRepository interface ShareRepository : JpaRepository diff --git a/sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedEntityTest.kt b/sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedEntityTest.kt deleted file mode 100644 index 05b27ca..0000000 --- a/sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedEntityTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package joryu.sns_service.feed.entity - -import jakarta.persistence.EntityManager -import joryu.sns_service.feed.repository.FeedRepository -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.transaction.annotation.Transactional -import java.time.LocalDateTime - -@Transactional -@SpringBootTest -@Disabled("프로젝트 초기 kotlin entity 테스트용도. springBootTest라 속도가 느려서 disabled.") -class FeedEntityTest { - - @Autowired - lateinit var em: EntityManager - - @Autowired - lateinit var feedRepository: FeedRepository - - @Test - fun `BaseEntity에 createAt, updateAt이 잘 들어가야 한다`() { - val before = LocalDateTime.now() - val feedEntity = feedRepository.save(Feed("123")) - - em.flush() - em.clear() - - val findFeedEntity = feedRepository.getReferenceById(feedEntity.id) - - assertThat(findFeedEntity.createAt).isNotNull() - assertThat(findFeedEntity.createAt).isAfter(before) - assertThat(findFeedEntity.createAt).isBefore(LocalDateTime.now()) - assertThat(findFeedEntity.updateAt).isNotNull() - assertThat(findFeedEntity.updateAt).isAfter(before) - assertThat(findFeedEntity.updateAt).isBefore(LocalDateTime.now()) - } - - @Test - fun `BaseEntity의 Id는 auto increment 되어야 한다`() { - val feedEntity1 = feedRepository.save(Feed("123")) - val feedEntity2 = feedRepository.save(Feed("123")) - val feedEntity3 = feedRepository.save(Feed("123")) - - assertThat(feedEntity1.id).isLessThan(feedEntity2.id) - assertThat(feedEntity2.id).isLessThan(feedEntity3.id) - } -} diff --git a/sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostEntityTest.kt b/sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostEntityTest.kt new file mode 100644 index 0000000..0d7f5a8 --- /dev/null +++ b/sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostEntityTest.kt @@ -0,0 +1,51 @@ +package joryu.sns_service.post.entity + +import jakarta.persistence.EntityManager +import joryu.sns_service.post.repository.PostRepository +import joryu.sns_service.post.entity.Post +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.transaction.annotation.Transactional +import java.time.LocalDateTime + +@Transactional +@SpringBootTest +// @Disabled("프로젝트 초기 kotlin entity 테스트용도. springBootTest라 속도가 느려서 disabled.") +class PostEntityTest { + + @Autowired + lateinit var em: EntityManager + + @Autowired + lateinit var postRepository: PostRepository + + @Test + fun `BaseEntity에 createAt, updateAt이 잘 들어가야 한다`() { + val before = LocalDateTime.now() + val postEntity = postRepository.save(Post("123")) + + em.flush() + em.clear() + + val findPostEntity = postRepository.getReferenceById(postEntity.id) + + assertThat(findPostEntity.createAt).isNotNull() + assertThat(findPostEntity.createAt).isAfter(before) + assertThat(findPostEntity.createAt).isBefore(LocalDateTime.now()) + assertThat(findPostEntity.updateAt).isNotNull() + assertThat(findPostEntity.updateAt).isAfter(before) + assertThat(findPostEntity.updateAt).isBefore(LocalDateTime.now()) + } + + @Test + fun `BaseEntity의 Id는 auto increment 되어야 한다`() { + val postEntity1 = postRepository.save(Post("123")) + val postEntity2 = postRepository.save(Post("123")) + val postEntity3 = postRepository.save(Post("123")) + + assertThat(postEntity1.id).isLessThan(postEntity2.id) + assertThat(postEntity2.id).isLessThan(postEntity3.id) + } +} diff --git a/sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedLikeTest.kt b/sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostLikeTest.kt similarity index 54% rename from sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedLikeTest.kt rename to sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostLikeTest.kt index 89ae5f8..8b69714 100644 --- a/sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedLikeTest.kt +++ b/sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostLikeTest.kt @@ -1,8 +1,8 @@ -package joryu.sns_service.feed.entity +package joryu.sns_service.post.entity import jakarta.persistence.EntityManager -import joryu.sns_service.feed.repository.FeedLikeRepository -import joryu.sns_service.feed.repository.FeedRepository +import joryu.sns_service.post.repository.PostLikeRepository +import joryu.sns_service.post.repository.PostRepository import joryu.sns_service.profile.entity.Profile import joryu.sns_service.profile.repository.ProfileRepository import org.assertj.core.api.Assertions.assertThat @@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.Transactional @Transactional @SpringBootTest // @Disabled -class FeedLikeTest { +class PostLikeTest { @Autowired lateinit var em: EntityManager @@ -23,24 +23,24 @@ class FeedLikeTest { lateinit var profileRepository: ProfileRepository @Autowired - lateinit var feedRepository: FeedRepository + lateinit var postRepository: PostRepository @Autowired - lateinit var feedLikeRepository: FeedLikeRepository + lateinit var postLikeRepository: PostLikeRepository @Test fun `연관관계가 잘 적용되어야 한다`() { val profile = profileRepository.save(Profile("현모")) - val feed = feedRepository.save(Feed("피드내용")) - val feedLike = feedLikeRepository.save(FeedLike(profile, feed)) + val post = postRepository.save(Post("피드내용")) + val postLike = postLikeRepository.save(PostLike(profile, post)) em.flush() em.clear() - val findFeedLikeEntity = feedLikeRepository.getReferenceById(feedLike.id) + val findPostLikeEntity = postLikeRepository.getReferenceById(postLike.id) - assertThat(findFeedLikeEntity).isNotNull() - assertThat(findFeedLikeEntity.likeMember.name).isEqualTo(profile.name) - assertThat(findFeedLikeEntity.feed.content).isEqualTo(feed.content) + assertThat(findPostLikeEntity).isNotNull() + assertThat(findPostLikeEntity.likeMember.name).isEqualTo(profile.name) + assertThat(findPostLikeEntity.post.content).isEqualTo(post.content) } }