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

[FEAT] ERD에 따른 Entity 구현 #20

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package ddangkong.controller.exception;

import static com.fasterxml.jackson.annotation.JsonInclude.Include;

import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Path;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.BindingResult;

import java.util.List;
import java.util.Set;

import static com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.springframework.validation.BindingResult;

public record ErrorResponse(
String message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.validation.ConstraintViolationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down
34 changes: 34 additions & 0 deletions backend/src/main/java/ddangkong/domain/member/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ddangkong.domain.member;

import ddangkong.domain.room.Room;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode
@ToString
public class Member {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String nickname;

@ManyToOne(optional = false)
Copy link
Member

Choose a reason for hiding this comment

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

의견) N+1 쿼리 발생으로 인한 성능 저하를 최대한 방지하기 위해 LAZY_LOADING 설정이 필요할 것 같습니다~
FetchType을 LAZY로 설정해도 N+1이 발생하지만 쿼리 발생 시점에 모든 데이터에 대해 N+1이 발생하는 EAGER 로딩보다는 나을 것 같아요!

이후에 JOIN이 필요한 부분에 대해서도 fetch join 로 처리하면 될 것 같구요 ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이와 관련해서 LazyInitializationException을 방지하기 위해,
Service Layer에서는 다른 엔티티를 불러올 때 @Transactional을 사용하도록 하겠습니다~

@JoinColumn(name = "room_id", nullable = false)
private Room room;
}
34 changes: 34 additions & 0 deletions backend/src/main/java/ddangkong/domain/option/BalanceOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ddangkong.domain.option;

import ddangkong.domain.question.BalanceQuestion;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode
@ToString
public class BalanceOption {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String content;

@ManyToOne(optional = false)
Copy link
Member

Choose a reason for hiding this comment

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

여기두요!

@JoinColumn(name = "balance_question_id", nullable = false)
private BalanceQuestion balanceQuestion;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ddangkong.domain.question;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode
@ToString
public class BalanceQuestion {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Category category;

@Column(nullable = false)
private String content;
}
6 changes: 6 additions & 0 deletions backend/src/main/java/ddangkong/domain/question/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ddangkong.domain.question;

public enum Category {
EXAMPLE,
;
Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

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

EXAMPLE 대신 실제로 사용할 연애 같은 카테고리를 넣어둬도 좋을 것 같아요~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

실제 카테고리가 정해지고 나서 해도 될것 같아서 일단 보류했습니다~
다음에 정해지고 API 구현하면서 추가하도록 할께요!

}
23 changes: 23 additions & 0 deletions backend/src/main/java/ddangkong/domain/room/Room.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ddangkong.domain.room;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode
@ToString
public class Room {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
34 changes: 34 additions & 0 deletions backend/src/main/java/ddangkong/domain/room/RoomQuestion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ddangkong.domain.room;

import ddangkong.domain.question.BalanceQuestion;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode
@ToString
public class RoomQuestion {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(optional = false)
@JoinColumn(name = "room_id")
private Room room;

@ManyToOne(optional = false)
Copy link
Member

Choose a reason for hiding this comment

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

여기두요~

@JoinColumn(name = "balance_question_id")
private BalanceQuestion balanceQuestion;
}
36 changes: 36 additions & 0 deletions backend/src/main/java/ddangkong/domain/vote/BalanceVote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ddangkong.domain.vote;

import ddangkong.domain.member.Member;
import ddangkong.domain.option.BalanceOption;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode
@ToString
public class BalanceVote {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(optional = false)
@JoinColumn(name = "balance_option_id", nullable = false)
private BalanceOption balanceOption;

@ManyToOne(optional = false)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

}