Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OING-58] feat: MemberPost 도메인 entity & repository 구성 #28

Merged
merged 12 commits into from
Dec 9, 2023
17 changes: 14 additions & 3 deletions member/src/test/java/com/oing/domain/model/MemberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.*;

/**
Expand All @@ -17,9 +20,12 @@ public class MemberTest {
void testMemberConstructorAndGetters() {
// Given
String memberId = "sampleId";
String familyId = "sampleFamilyId";
LocalDate dayofBirth = LocalDate.of(2023, 7, 8);
String name = "sampleName";

// When
Member member = new Member(memberId);
Member member = new Member(memberId, familyId, dayofBirth, name, null);

// Then
assertNotNull(member);
Expand All @@ -31,8 +37,13 @@ void testMemberConstructorAndGetters() {
void testMemberEqualsAndHashCode() {
// Given
String memberId = "sampleId";
Member member1 = new Member(memberId);
Member member2 = new Member(memberId);
String familyId = "sampleFamilyId";
LocalDate dayofBirth = LocalDate.of(2023, 7, 8);
String name = "sampleName";

// When
Member member1 = new Member(memberId, familyId, dayofBirth, name, null);
Member member2 = new Member(memberId, familyId, dayofBirth, name, null);

// Then
assertEquals(member1, member2);
Expand Down
12 changes: 10 additions & 2 deletions member/src/test/java/com/oing/domain/model/SocialMemberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.oing.domain.SocialLoginProvider;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.*;

/**
Expand All @@ -19,7 +22,10 @@ void testSocialMemberConstructorAndGetters() {
// Given
SocialLoginProvider provider = SocialLoginProvider.APPLE;
String identifier = "user123";
Member member = new Member("sampleId");

// When
Member member = new Member("sampleId", "sampleFamilyId",
LocalDate.of(2023, 7, 8), "sampleName", null);

// When
SocialMember socialMember = new SocialMember(provider, identifier, member);
Expand All @@ -37,8 +43,10 @@ void testSocialMemberEqualsAndHashCode() {
// Given
SocialLoginProvider provider = SocialLoginProvider.APPLE;
String identifier = "user123";
Member member = new Member("sampleId");
Member member = new Member("sampleId", "sampleFamilyId",
LocalDate.of(2023, 7, 8), "sampleName", null);

// When
SocialMember socialMember1 = new SocialMember(provider, identifier, member);
SocialMember socialMember2 = new SocialMember(provider, identifier, member);

Expand Down
43 changes: 43 additions & 0 deletions post/src/main/java/com/oing/domain/model/MemberPost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.oing.domain.model;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;
import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@Getter
@Builder
@Table(indexes = {
@Index(name = "member_post_idx1", columnList = "member_id")
})
@Entity(name = "member_post")
public class MemberPost extends BaseAuditEntity {
@Id
@Column(name = "post_id", length = 26, columnDefinition = "CHAR(26)")
Kwon770 marked this conversation as resolved.
Show resolved Hide resolved
private String id;

@Column(name = "member_id", length = 26, columnDefinition = "CHAR(26)")
Kwon770 marked this conversation as resolved.
Show resolved Hide resolved
private String memberId;

@Column(name = "post_date", nullable = false)
private LocalDate postDate;

@Column(name = "image_url")
private String imageUrl;

@Column(name = "comment_cnt", nullable = false, columnDefinition = "INTEGER DEFAULT 0")
private int commentCnt;

@Column(name = "reaction_cnt", nullable = false, columnDefinition = "INTEGER DEFAULT 0")
private int reactionCnt;

@OneToMany(mappedBy = "post")
private List<MemberPostComment> comments;
Kwon770 marked this conversation as resolved.
Show resolved Hide resolved

@OneToMany(mappedBy = "post")
private List<MemberPostReaction> reactions;
}
30 changes: 30 additions & 0 deletions post/src/main/java/com/oing/domain/model/MemberPostComment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.oing.domain.model;

import jakarta.persistence.*;
import lombok.*;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@Getter
@Builder
@Table(indexes = {
@Index(name = "member_post_comment_idx1", columnList = "post_id"),
@Index(name = "member_post_comment_idx2", columnList = "member_id")
})
@Entity(name = "member_post_comment")
public class MemberPostComment extends BaseAuditEntity {
@Id
@Column(name = "comment_id", length = 26, columnDefinition = "CHAR(26)")
Kwon770 marked this conversation as resolved.
Show resolved Hide resolved
private String id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private MemberPost post;

@Column(name = "member_id", length = 26, columnDefinition = "CHAR(26)")
private String memberId;

@Column(name = "comment", nullable = false)
private String comment;
}
30 changes: 30 additions & 0 deletions post/src/main/java/com/oing/domain/model/MemberPostReaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.oing.domain.model;

import jakarta.persistence.*;
import lombok.*;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@Getter
@Builder
@Table(indexes = {
@Index(name = "member_post_reaction_idx1", columnList = "post_id"),
@Index(name = "member_post_reaction_idx2", columnList = "member_id")
})
@Entity(name = "member_post_reaction")
public class MemberPostReaction extends BaseEntity {
@Id
@Column(name = "reaction_id", length = 26, columnDefinition = "CHAR(26)")
private String id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private MemberPost post;

@Column(name = "member_id", length = 26, columnDefinition = "CHAR(26)")
private String memberId;

@Column(name = "ascii", length = 16, nullable = false)
private String ascii;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.oing.repository;

import com.oing.domain.model.MemberPostComment;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberPostCommentRepository extends JpaRepository<MemberPostComment, String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@repository 안넣어도 될까요?

Copy link
Member Author

@Ji-soo708 Ji-soo708 Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 안넣어도 동작되고 Member쪽도 @Repository는 빼고 구현해되어 있어서 저도 저렇게 했습니다! 이건 회의때 얘기해도 좋을 거 같네요

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.oing.repository;

import com.oing.domain.model.MemberPostReaction;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberPostReactionRepository extends JpaRepository<MemberPostReaction, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.oing.repository;

import com.oing.domain.model.MemberPost;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberPostRepository extends JpaRepository<MemberPost, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.oing.domain.model;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class MemberPostCommentTest {

@DisplayName("MemberPostComment 생성자 및 getter 테스트")
@Test
void testMemberPostCommentConstructorAndGetters() {
// Given
String postId = "samplePostId";
String memberId = "sampleMemberId";
String commentId = "sampleCommentId";
String commentContents = "sampleCommentContents";
LocalDate postDate = LocalDate.of(2023, 7, 8);
MemberPost post = new MemberPost(postId, memberId, postDate, null, 0, 0,
null, null);

// When
MemberPostComment comment = new MemberPostComment(commentId, post, memberId, commentContents);

// Then
assertNotNull(comment);
assertEquals(commentId, comment.getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.oing.domain.model;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class MemberPostReactionTest {

@DisplayName("MemberPostReaction 생성자 및 getter 테스트")
@Test
void testMemberPostReactionConstructorAndGetters() {
// Given
String postId = "samplePostId";
String memberId = "sampleMemberId";
String reactionId = "sampleCommentId";
String ascii = "sampleAscii";
LocalDate postDate = LocalDate.of(2023, 7, 8);
MemberPost post = new MemberPost(postId, memberId, postDate, null, 0, 0,
null, null);

// When
MemberPostReaction reaction = new MemberPostReaction(reactionId, post, memberId, ascii);

// Then
assertNotNull(reaction);
assertEquals(reactionId, reaction.getId());
}
}
29 changes: 29 additions & 0 deletions post/src/test/java/com/oing/domain/model/MemberPostTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.oing.domain.model;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class MemberPostTest {

@DisplayName("MemberPost 생성자 및 getter 테스트")
@Test
void testMemberPostConstructorAndGetters() {
// Given
String postId = "samplePostId";
String memberId = "sampleMemberId";
LocalDate postDate = LocalDate.of(2023, 7, 8);

// When
MemberPost post = new MemberPost(postId, memberId, postDate, null, 0, 0,
null, null);

// Then
assertNotNull(post);
assertEquals(postId, post.getId());
}
}
Loading