Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.fhsh.daitda'
version = '0.1.3-SNAPSHOT'
version = '0.1.4-SNAPSHOT'

java {
toolchain {
Expand Down
38 changes: 12 additions & 26 deletions src/main/java/com/fhsh/daitda/domain/BaseUserEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,33 @@
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.UUID;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseUserEntity extends BaseEntity {

private static final int AUDITOR_MAX_LENGTH = 45;

@CreatedBy
@Column(length = AUDITOR_MAX_LENGTH, updatable = false)
protected String createdBy;
@Column(updatable = false)
protected UUID createdBy;

@LastModifiedBy
@Column(length = AUDITOR_MAX_LENGTH)
protected String updatedBy;
protected UUID updatedBy;

@Column(length = AUDITOR_MAX_LENGTH)
protected String deletedBy;
protected UUID deletedBy;
Comment thread
bomzae marked this conversation as resolved.

// Soft Delete 구현
protected void delete(String deletedBy) {
public void delete(UUID deletedBy) {
// 중복 삭제로 인해 삭제 관련 필드가 업데이트되는 상황을 방지
if (isDeleted()) {
return;
}

validateAuditorLength(deletedBy);

// 삭제자가 없으면 SYSTEM 삭제로 간주
this.updatedBy = StringUtils.hasText(deletedBy) ? deletedBy : "SYSTEM";
this.deletedBy = StringUtils.hasText(deletedBy) ? deletedBy : "SYSTEM";

this.updatedBy = deletedBy;
this.deletedBy = deletedBy;

this.updatedAt = LocalDateTime.now();
this.deletedAt = LocalDateTime.now();
Expand All @@ -50,23 +43,16 @@ public boolean isDeleted() {
return this.deletedAt != null;
}

public void restore(String restoredBy) {
// 삭제 복구
public void restore(UUID restoredBy) {
if (!isDeleted()) {
return;
}

validateAuditorLength(restoredBy);

this.updatedBy = StringUtils.hasText(restoredBy) ? restoredBy : "SYSTEM";
this.updatedBy = restoredBy;
this.deletedBy = null;

this.updatedAt = LocalDateTime.now();
this.deletedAt = null;
}
Comment thread
bomzae marked this conversation as resolved.

private void validateAuditorLength(String auditor) {
if (auditor != null && auditor.length() > AUDITOR_MAX_LENGTH) {
throw new IllegalArgumentException("auditor 정보는 %d자를 초과할 수 없습니다.".formatted(AUDITOR_MAX_LENGTH));
}
}
}