-
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.
- Loading branch information
Showing
11 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
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.feed.entity.Feed | ||
import joryu.sns_service.common.entity.BaseEntity | ||
|
||
@Table(name = "comment") | ||
@Entity | ||
class Comment( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "feed_id", nullable = false) | ||
val feed: Feed, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "parent_id") | ||
val parent: Comment?, | ||
|
||
content: String, | ||
) : BaseEntity() { | ||
constructor() : this(0, Feed(), null, "") | ||
constructor(feed: Feed, parent: Comment) : this(0, feed, parent, "") | ||
|
||
@Column(name = "content", nullable = false, length = 1000) | ||
var content: String = content | ||
private set | ||
} |
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
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( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long, | ||
|
||
@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(0, Profile(), Comment()) | ||
constructor(likeMember: Profile, comment: Comment) : this(0, likeMember, comment) | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
sns_service/src/main/kotlin/joryu/sns_service/feed/entity/FeedLike.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,31 @@ | ||
package joryu.sns_service.feed.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 = "feed_like") | ||
@Entity | ||
class FeedLike( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long, | ||
|
||
@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, | ||
) : BaseEntity() { | ||
constructor() : this(0, Profile(), Feed()) | ||
constructor(likeMember: Profile, feed: Feed) : this(0, likeMember, feed) | ||
} |
26 changes: 26 additions & 0 deletions
26
sns_service/src/main/kotlin/joryu/sns_service/feed/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,26 @@ | ||
package joryu.sns_service.feed.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( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "feed_id", nullable = false) | ||
val feed: Feed, | ||
) : BaseEntity() { | ||
constructor() : this(0, Feed()) | ||
constructor(feed: Feed) : this(0, feed) | ||
} |
6 changes: 6 additions & 0 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/feed/repository/FeedLikeRepository.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.feed.repository | ||
|
||
import joryu.sns_service.feed.entity.FeedLike | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface FeedLikeRepository : JpaRepository<FeedLike, Long> |
6 changes: 6 additions & 0 deletions
6
sns_service/src/main/kotlin/joryu/sns_service/feed/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.feed.repository | ||
|
||
import joryu.sns_service.feed.entity.Share | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface ShareRepository : JpaRepository<Share, Long> |
46 changes: 46 additions & 0 deletions
46
sns_service/src/test/kotlin/joryu/sns_service/feed/entity/FeedLikeTest.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.feed.entity | ||
|
||
import jakarta.persistence.EntityManager | ||
import joryu.sns_service.feed.repository.FeedLikeRepository | ||
import joryu.sns_service.feed.repository.FeedRepository | ||
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 FeedLikeTest { | ||
|
||
@Autowired | ||
lateinit var em: EntityManager | ||
|
||
@Autowired | ||
lateinit var profileRepository: ProfileRepository | ||
|
||
@Autowired | ||
lateinit var feedRepository: FeedRepository | ||
|
||
@Autowired | ||
lateinit var feedLikeRepository: FeedLikeRepository | ||
|
||
@Test | ||
fun `연관관계가 잘 적용되어야 한다`() { | ||
val profile = profileRepository.save(Profile("현모")) | ||
val feed = feedRepository.save(Feed("피드내용")) | ||
val feedLike = feedLikeRepository.save(FeedLike(profile, feed)) | ||
|
||
em.flush() | ||
em.clear() | ||
|
||
val findFeedLikeEntity = feedLikeRepository.getReferenceById(feedLike.id) | ||
|
||
assertThat(findFeedLikeEntity).isNotNull() | ||
assertThat(findFeedLikeEntity.likeMember.name).isEqualTo(profile.name) | ||
assertThat(findFeedLikeEntity.feed.content).isEqualTo(feed.content) | ||
} | ||
} |