-
Notifications
You must be signed in to change notification settings - Fork 1
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
refactor : Entity 구조 재설정 #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.hearts; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.posts.ClinicPost; | ||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class ClinicHeart { | ||
// 공감한 유저, 공감한 클리닉 글 | ||
@Id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GeneratedValue를 사용하지 않으신 이유가 있으실까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 죄송합니다. 잠시 착오가 있었던 것 같습니다 |
||
private Long id; | ||
|
||
// ClinicHeart : User = 1 : n 매핑 | ||
@OneToMany | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 유저가 여러 개의 공감한 감정글을 가질 수 있으므로 User : ClinicHeart = 1 : n이 맞습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 이해했습니다..! 꼼꼼하게 봐주셔서 감사합니다ㅠ 저희가 이해하고 적용하는데 조금 시간이 걸렸네요,,! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그러면 여러 개를 작성할 수 있는 영역이 n이 되는 건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아닙니다 이제 처음 하시는데요 그럴 수 있습니다 |
||
@JoinColumn(name = "CLINIC_HEART_USER") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위에서 말씀드린 것처럼 OneToMany가 아니어서 상관없겠지만 OneToMany로 할때 @joincolumn이 아닌 것으로 알고 있습니다. 연관관계의 주인이 왠만하면 N에 있어서요. 또 안에 들어가는 name이 왜 저거인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 책을 보며 OneToMany일 때, mappedBy를 통해 묶는 걸 확인했습니다. 아직 연관관계에 대해서 명확하게 알지 못해 자주 보이는 방식으로 작성하다보니 JoinColumn을 사용하게 되었습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mappedBy나 name은 단순히 아무 값이나 넣을 수 없습니다. 어떤 값이 들어가야 하는지 확인 부탁드립니다 |
||
private List<User> users = new ArrayList<User>(); | ||
|
||
// ClinicHeart : ClinicPost = 1 : n 매핑 | ||
@OneToMany | ||
@JoinColumn(name = "CLINIC_HEART_POST") | ||
private List<ClinicPost> ClinicPosts = new ArrayList<ClinicPost>(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.hearts; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.posts.FeelingPost; | ||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class PostHeart { | ||
// 공감한 유저, 공감한 감정글 | ||
@Id | ||
private Long id; | ||
|
||
// PostHeart : User = 1 : n 매핑 | ||
@OneToMany | ||
@JoinColumn(name = "FEELING_HEART_USER") | ||
private List<User> users = new ArrayList<User>(); | ||
|
||
// PostHeart : FeelingPost = 1 : n 매핑 | ||
@OneToMany | ||
@JoinColumn(name = "FEELING_HEART_POST") | ||
private List<FeelingPost> feelingPosts = new ArrayList<FeelingPost>(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.posts; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class ClinicPost { | ||
// 제목, 글, 글 쓴 사람 | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(length = 500, nullable = false) | ||
private String title; | ||
|
||
// 글 작성은 필수 | ||
@Column(columnDefinition = "TEXT", nullable = false) | ||
private String content; | ||
|
||
// User 와 ClinicPost 1:1 매핑 | ||
@OneToOne | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 유저는 여러개의 클리닉 글을 작성할 수 있으므로 1 : 1 매핑이 아닙니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 넵 헷갈렸던 부분이 많았습니다.. 수정하겠습니다 |
||
@JoinColumn(name = "USER_ID") | ||
private User user; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.posts; | ||
|
||
|
||
public enum Feeling { | ||
POSITIVE, | ||
NEGATIVE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.gdschanyang.todayfeelingbackend2.domain.posts; | ||
|
||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
|
@@ -9,22 +10,26 @@ | |
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class Posts { | ||
|
||
public class FeelingPost { | ||
// 감정, 글, 글 쓴 사람, 삭제 여부 | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Feelings feelings; | ||
|
||
@Column(length = 500, nullable = false) | ||
private String title; | ||
private Feeling feeling; | ||
|
||
// 글 작성은 선택적 | ||
@Column(columnDefinition = "TEXT") | ||
private String content; | ||
|
||
// User 와 FeelingPost 1:1 매핑 | ||
@OneToOne | ||
@JoinColumn(name = "USER_ID") | ||
private User user; | ||
|
||
// 삭제 여부 1:삭제 0:삭제X | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1과 0으로 구분할 수도 있겠지만 DB에서 1과 0으로 필드가 되어있으면 정확히 어떤 값인지 판단하기 어려울 수 있습니다 |
||
@Column(nullable = false) | ||
private String author; | ||
private boolean delFlag; | ||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,15 @@ public class User { | |
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "USER_ID") | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
// 본명 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 본명은 왜 추가되었나요? 어디서 가져올 수 있는 값인가? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 홈화면에 본명을 작성해야 한다고 생각하여 만들었습니다. 다시 닉네임만 있게 하겠습니다. |
||
@Column(name = "USER_REALNAME", nullable = false) | ||
private String realName; | ||
|
||
// 닉네임으로 대나무숲과 클릭닉 센터에서 활동 | ||
@Column(name = "USER_NICKNAME", nullable = false) | ||
private String nickName; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
package com.gdschanyang.todayfeelingbackend2.repository; | ||
|
||
import com.gdschanyang.todayfeelingbackend2.domain.posts.Posts; | ||
import com.gdschanyang.todayfeelingbackend2.domain.user.User; | ||
import com.gdschanyang.todayfeelingbackend2.domain.posts.FeelingPost; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface PostsRepository extends JpaRepository<Posts, Long> { | ||
public interface PostsRepository extends JpaRepository<FeelingPost, Long> { | ||
|
||
Posts save(Posts posts); | ||
FeelingPost save(FeelingPost posts); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save는 값을 return하지 않으며 Spring Data JPA를 사용하셨으므로 해당 함수는 이미 구현되어 있습니다 |
||
|
||
Optional<Posts> findById(Long id); | ||
Optional<Posts> findByAuthor(String name); | ||
Optional<FeelingPost> findById(Long id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Data JPA를 사용하셨으므로 해당 함수는 이미 구현되어 있습니다 |
||
|
||
List<Posts> findAll(); | ||
List<FeelingPost> findAll(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Data JPA를 사용하셨으므로 해당 함수는 이미 구현되어 있습니다 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ public interface UserRepository extends JpaRepository<User, Long> { | |
User save(User user); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save는 값을 return하지 않으며 Spring Data JPA를 사용하셨으므로 해당 함수는 이미 구현되어 있습니다 |
||
|
||
Optional<User> findById(Long id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Data JPA를 사용하셨으므로 해당 함수는 이미 구현되어 있습니다 |
||
Optional<User> findByName(String name); | ||
|
||
List<User> findAll(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Data JPA를 사용하셨으므로 해당 함수는 이미 구현되어 있습니다 |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주석은 특별한 사항이 없으면 안하시는게 좋을 것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 알겠습니다 !