-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BSVR-123] DB 컨벤션에 맞춰 BaseEntity 생성 (#20)
* feat: BaseEntity 생성 * feat: 모든 entity에 BaseEntity 적용
- Loading branch information
Showing
15 changed files
with
146 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/common/entity/BaseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.depromeet.spot.jpa.common.entity; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.MappedSuperclass; | ||
import jakarta.persistence.PrePersist; | ||
import jakarta.persistence.PreUpdate; | ||
|
||
import org.hibernate.annotations.Where; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Getter | ||
@SuperBuilder | ||
@MappedSuperclass | ||
@AllArgsConstructor | ||
@Where(clause = "deleted_at is null") | ||
@EntityListeners(AuditingEntityListener.class) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public abstract class BaseEntity { | ||
|
||
@Id | ||
@Column(name = "id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(updatable = false, name = "created_at") | ||
private LocalDateTime createdAt; | ||
|
||
@Column(name = "updated_at") | ||
private LocalDateTime updatedAt; | ||
|
||
@Column(name = "deleted_at") | ||
private LocalDateTime deletedAt; | ||
|
||
@PrePersist | ||
public void prePersist() { | ||
this.createdAt = LocalDateTime.now(); | ||
this.updatedAt = LocalDateTime.now(); | ||
} | ||
|
||
@PreUpdate | ||
public void preUpdate() { | ||
this.updatedAt = LocalDateTime.now(); | ||
} | ||
|
||
public boolean isDeleted() { | ||
return null != this.deletedAt; | ||
} | ||
|
||
public void delete() { | ||
this.deletedAt = LocalDateTime.now(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.