-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ry-생성 #12 [FEED] 기본 entity 및 repository 생성
- Loading branch information
Showing
15 changed files
with
259 additions
and
68 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
sns_service/src/main/kotlin/joryu/sns_service/comment/entity/Comment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package joryu.sns_service.comment.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.Table | ||
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 = "post_id", nullable = false) | ||
val post: Post, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "parent_id") | ||
val parent: Comment?, | ||
|
||
content: String, | ||
) : BaseEntity() { | ||
constructor() : this(Post(), null, "") | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0 | ||
|
||
@Column(name = "content", nullable = false, length = 1000) | ||
var content: String = content | ||
private set | ||
} |
30 changes: 30 additions & 0 deletions
30
sns_service/src/main/kotlin/joryu/sns_service/comment/entity/CommentLike.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package joryu.sns_service.comment.entity | ||
|
||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.Table | ||
import joryu.sns_service.common.entity.BaseEntity | ||
import joryu.sns_service.profile.entity.Profile | ||
|
||
@Table(name = "comment_like") | ||
@Entity | ||
class CommentLike( | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "profile_id", nullable = false) | ||
val likeMember: Profile, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "comment_id", nullable = false) | ||
val comment: Comment, | ||
) : BaseEntity() { | ||
constructor() : this(Profile(), Comment()) | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0 | ||
} |
6 changes: 6 additions & 0 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/comment/repository/CommentLikeRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package joryu.sns_service.comment.repository | ||
|
||
import joryu.sns_service.comment.entity.CommentLike | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface CommentLikeRepository : JpaRepository<CommentLike, Long> |
6 changes: 6 additions & 0 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/comment/repository/CommentRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package joryu.sns_service.comment.repository | ||
|
||
import joryu.sns_service.comment.entity.Comment | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface CommentRepository : JpaRepository<Comment, Long> |
2 changes: 1 addition & 1 deletion
2
.../sns_service/profile/entity/BaseEntity.kt → ...u/sns_service/common/entity/BaseEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedRepository.kt
This file was deleted.
Oops, something went wrong.
19 changes: 9 additions & 10 deletions
19
...lin/joryu/sns_service/feed/entity/Feed.kt → ...lin/joryu/sns_service/post/entity/Post.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostLike.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package joryu.sns_service.post.entity | ||
|
||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.Table | ||
import joryu.sns_service.common.entity.BaseEntity | ||
import joryu.sns_service.profile.entity.Profile | ||
|
||
@Table(name = "post_like") | ||
@Entity | ||
class PostLike( | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "profile_id", nullable = false) | ||
val likeMember: Profile, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "post_id", nullable = false) | ||
val post: Post, | ||
) : BaseEntity() { | ||
constructor() : this(Profile(), Post()) | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0 | ||
} |
25 changes: 25 additions & 0 deletions
25
sns_service/src/main/kotlin/joryu/sns_service/post/entity/Share.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package joryu.sns_service.post.entity | ||
|
||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.Table | ||
import joryu.sns_service.common.entity.BaseEntity | ||
|
||
@Table(name = "share") | ||
@Entity | ||
class Share( | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "post_id", nullable = false) | ||
val post: Post, | ||
) : BaseEntity() { | ||
constructor() : this(Post()) | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0 | ||
} |
6 changes: 6 additions & 0 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostLikeRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PostLike, Long> |
6 changes: 6 additions & 0 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Post, Long> |
6 changes: 6 additions & 0 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/post/repository/ShareRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package joryu.sns_service.post.repository | ||
|
||
import joryu.sns_service.post.entity.Share | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface ShareRepository : JpaRepository<Share, Long> |
51 changes: 0 additions & 51 deletions
51
sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedEntityTest.kt
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostEntityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
sns_service/src/test/kotlin/joryu/sns_service/post/entity/PostLikeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package joryu.sns_service.post.entity | ||
|
||
import jakarta.persistence.EntityManager | ||
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 | ||
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 | ||
|
||
@Transactional | ||
@SpringBootTest | ||
// @Disabled | ||
class PostLikeTest { | ||
|
||
@Autowired | ||
lateinit var em: EntityManager | ||
|
||
@Autowired | ||
lateinit var profileRepository: ProfileRepository | ||
|
||
@Autowired | ||
lateinit var postRepository: PostRepository | ||
|
||
@Autowired | ||
lateinit var postLikeRepository: PostLikeRepository | ||
|
||
@Test | ||
fun `연관관계가 잘 적용되어야 한다`() { | ||
val profile = profileRepository.save(Profile("현모")) | ||
val post = postRepository.save(Post("피드내용")) | ||
val postLike = postLikeRepository.save(PostLike(profile, post)) | ||
|
||
em.flush() | ||
em.clear() | ||
|
||
val findPostLikeEntity = postLikeRepository.getReferenceById(postLike.id) | ||
|
||
assertThat(findPostLikeEntity).isNotNull() | ||
assertThat(findPostLikeEntity.likeMember.name).isEqualTo(profile.name) | ||
assertThat(findPostLikeEntity.post.content).isEqualTo(post.content) | ||
} | ||
} |