-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: 회원 도메인 전반적인 리팩터링 #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
base: main
Are you sure you want to change the base?
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,45 @@ | ||
| package com.codezerotoone.mvp.domain.common; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import static com.codezerotoone.mvp.domain.common.EntityConstant.BOOLEAN_DEFAULT_FALSE; | ||
| import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
|
||
| // 추가 사유: 일반적으로 공통되는 컬럼들은 엔티티가 추가될 때마다 일일이 설정하기보다는 공용 멤버로 묶는 게 나아 보입니다. | ||
| @MappedSuperclass | ||
| @EntityListeners(AuditingEntityListener.class) | ||
| public abstract class BaseGeneralEntity extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false, columnDefinition = BOOLEAN_DEFAULT_FALSE) | ||
| private boolean deleteYn; | ||
|
|
||
| @Column(name = "deleted_at") | ||
| private LocalDateTime deletedAt; | ||
|
Comment on lines
+19
to
+23
Collaborator
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. 제 개인적 견해로는
Collaborator
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. 삭제된 엔티티를 복구할 경우, 이전에 삭제된 이력을 기록하는 것도 하나의 좋은 컨벤션이 될 수 있겠군요. 좋은 코드 제시 감사합니다!
Author
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. 좋은 의견 감사합니다. 제 개인적으로는 deletedAt에 deleteYn이 추가로 필요하다기보다, 오히려 deletedAt이 필수가 아니고 deletedYn으로 조회를 하는 게 좋다는 생각입니다. |
||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| protected boolean isDeleted() { | ||
| return deleteYn; | ||
| } | ||
|
|
||
| protected void updateId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| protected void deleteEntity() { | ||
| deleteYn = true; | ||
| deletedAt = LocalDateTime.now(); | ||
| } | ||
|
|
||
| protected void undeleteEntity() { | ||
| deleteYn = false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.codezerotoone.mvp.domain.common; | ||
|
|
||
| public class EntityConstant { | ||
| public static final String BOOLEAN_DEFAULT_FALSE = "boolean default false"; | ||
|
Collaborator
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. 오라클처럼 Boolean 타입을 제공하지 않는 DB를 상정한다면, DB에서 BOOLEAN 타입을 사용하는 건 DB 선택의 폭이 좁아지지 않을까요? 아니면 DB 선택의 폭을 좁히더라도 boolean 타입을 사용함으로써 얻는 이점이 더 클까요?
Author
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. 예를 들어 오라클을 사용하기로 하는 경우에, 상수로 선언했으므로 public static final String BOOLEAN_DEFAULT_FALSE = "number(1) default 0"; 로 한 내용물만 바꾸면 되기 때문에 거의 수정이 필요 없을 것으로 보입니다. |
||
| } | ||
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.
좋은 의견 감사합니다