-
Notifications
You must be signed in to change notification settings - Fork 2
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: #4의 DataEntity 구현을 수정합니다 #6
Changes from all commits
6bb1076
7ecb8fe
71c1197
e2419c1
eab5fb4
815a07d
05a0d78
0699cf1
5807696
cbf102c
4e7b6c1
68f99fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.walking.data.entity.member; | ||
|
||
public enum CertificationSubject { | ||
KAKAO, | ||
} | ||
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. 이 코드 패치는 간단한 enum을 선언하는 것으로 보입니다. 여러 가지 사항에 대해 고려할 수 있습니다:
이외에는 이 코드 스니펫이 단순하고 문제가 없어 보입니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
import com.walking.data.entity.BaseEntity; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
@@ -20,9 +23,32 @@ | |
@SQLDelete(sql = "UPDATE member SET deleted=true where id=?") | ||
public class MemberEntity extends BaseEntity { | ||
|
||
/* 소셜 로그인을 통해 가입한 회원의 닉네임 */ | ||
@Column(nullable = false, unique = true, length = 50) | ||
private String nickName; | ||
|
||
/* 소셜 로그인을 통해 가입한 회원의 프로필 이미지 URL */ | ||
@Column(nullable = false) | ||
private String memberId; | ||
private String profile; | ||
|
||
/* 소셜 로그인을 통해 가입한 회원의 식별자 */ | ||
@Column(nullable = false, unique = true) | ||
private String certificationId; | ||
|
||
/* 소셜 로그인을 통해 가입한 회원의 인증 주체 */ | ||
@SuppressWarnings("FieldMayBeFinal") | ||
@Enumerated(EnumType.STRING) | ||
@Builder.Default | ||
@Column(nullable = false) | ||
private String password; | ||
private CertificationSubject certificationSubject = CertificationSubject.KAKAO; | ||
|
||
@SuppressWarnings("FieldMayBeFinal") | ||
@Enumerated(EnumType.STRING) | ||
@Builder.Default | ||
@Column(nullable = false) | ||
private MemberStatus status = MemberStatus.REGULAR; | ||
|
||
@Builder.Default | ||
@Column(nullable = false, columnDefinition = "json") | ||
private String resource = "{}"; | ||
} | ||
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. 이 코드 패치의 코드 리뷰:
개선 제안:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.walking.data.entity.member; | ||
|
||
import lombok.ToString; | ||
|
||
@ToString | ||
public enum MemberStatus { | ||
REGULAR("정회원"), | ||
ASSOCIATE("준회원"), | ||
SEPARATE("장기미이용 회원"), | ||
WITHDRAWN("탈퇴회원"), | ||
; | ||
|
||
private final String description; | ||
|
||
MemberStatus(String description) { | ||
this.description = description; | ||
} | ||
} | ||
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. 이 코드는 깔끔하고 간단한 열거형(MemberStatus)을 정의하고 있습니다. 개선할 점으로는 다음과 같은 사항을 고려할 수 있습니다:
위 내용은 코드 리뷰에서 고려될 수 있는 세 가지 포인트입니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,20 +21,21 @@ | |
public class PathFavoritesEntity extends BaseEntity { | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
private MemberEntity memberEntity; | ||
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT)) | ||
private MemberEntity memberFk; | ||
|
||
@Column(columnDefinition = "POINT") | ||
@Column(nullable = false, columnDefinition = "POINT SRID 4326") | ||
private Point startPoint; | ||
|
||
@Column(columnDefinition = "POINT") | ||
@Column(nullable = false, columnDefinition = "POINT SRID 4326") | ||
private Point endPoint; | ||
|
||
@Column(columnDefinition = "LINESTRING") | ||
@Column(nullable = false, columnDefinition = "LINESTRING SRID 4326") | ||
private LineString path; | ||
|
||
@Column(nullable = false) | ||
@Column(nullable = false, length = 50) | ||
private String startAlias; | ||
|
||
@Column(nullable = false) | ||
@Column(nullable = false, length = 50) | ||
private String endAlias; | ||
} | ||
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. 이 코드는 좋아보입니다. 몇 가지 제안사항은 다음과 같습니다:
위의 제안을 고려하여 코드가 확장 가능하고 유지 보수가 쉬워질 수 있도록 하는 것이 좋습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,13 @@ | |
public class TrafficFavoritesEntity extends BaseEntity { | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
private MemberEntity memberEntity; | ||
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT)) | ||
private MemberEntity memberFk; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
private TrafficEntity trafficEntity; | ||
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT)) | ||
private TrafficEntity trafficFk; | ||
|
||
@Column(nullable = false) | ||
@Column(nullable = false, length = 50) | ||
private String alias; | ||
} | ||
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. 이 코드 패치는 다음과 같은 변경을 포함합니다:
개선 제안:
버그 리스크:
이 외에도 코드 구조 및 목적에 따라 다른 개선 사항이 있을 수 있습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.walking.data.entity.support.listener; | ||
|
||
import com.walking.data.entity.traffic.TrafficEntity; | ||
import javax.persistence.PreRemove; | ||
|
||
public class TrafficEntitySoftDeleteListener { | ||
|
||
@PreRemove | ||
private void preRemove(TrafficEntity entity) { | ||
entity.delete(); | ||
} | ||
} | ||
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. 이 코드는 JPA Entity의 Soft Delete를 지원하기 위한 Listener로 보입니다. 해당 리스너는 개선 제안:
버그 리스크:
코드 리뷰 결과, 리스너 메서드 시그니처를 수정하고 접근 제어자를 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,61 @@ | ||
package com.walking.data.entity.traffic; | ||
|
||
import com.walking.data.entity.BaseEntity; | ||
import com.walking.data.entity.support.listener.TrafficEntitySoftDeleteListener; | ||
import java.time.LocalDateTime; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
import org.hibernate.annotations.SQLDelete; | ||
import org.locationtech.jts.geom.Point; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Entity | ||
@SuperBuilder(toBuilder = true) | ||
@EntityListeners({AuditingEntityListener.class, TrafficEntitySoftDeleteListener.class}) | ||
@Builder(toBuilder = true) | ||
@Table(name = "traffic") | ||
@SQLDelete(sql = "UPDATE traffic SET deleted=true where id=?") | ||
public class TrafficEntity extends BaseEntity { | ||
public class TrafficEntity { | ||
|
||
@Column(nullable = false, updatable = false) | ||
private String detail; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@Column(columnDefinition = "POINT SRID 4326", nullable = false) | ||
@Column(nullable = false, columnDefinition = "POINT SRID 4326") | ||
private Point point; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
private Long id; | ||
|
||
@Column(nullable = false, updatable = false) | ||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
@Column(nullable = false) | ||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
|
||
@Builder.Default | ||
@Column(nullable = false) | ||
private Boolean deleted = false; | ||
|
||
public void delete() { | ||
this.deleted = true; | ||
} | ||
} | ||
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. 이 코드는 대체로 잘 구성되어 있지만 몇 가지 개선 사항이 있습니다:
좀 더 명확하고 안정적인 코드를 작성하기 위해 위의 제안을 고려해보세요. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,9 @@ spring: | |
ddl-auto: validate | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
format_sql: true | ||
dialect: org.hibernate.spatial.dialect.mysql.MySQL8SpatialDialect | ||
order_inserts: true | ||
order_updates: true | ||
jdbc: | ||
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. 주요 변경 사항은 Hibernate dialect가 MySQL8SpatialDialect로 설정되었으며 insert 및 update 문장이 순서화되었습니다. jdbc의 batch_size도 설정되었습니다. 개선 제안:
이 코드는 전반적으로 안정적으로 보입니다. |
||
batch_size: ${JDBC_BATCH_SIZE:50} |
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.
코드 리뷰: