-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] 좋아요 반 정규화로 인한 템플릿 좋아요 시 해당 템플릿의 ModifiedAt 변경 문제 (#927)
- Loading branch information
Showing
8 changed files
with
135 additions
and
52 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
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/codezap/global/auditing/SkipModifiedAtBaseTimeEntity.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,40 @@ | ||
package codezap.global.auditing; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import jakarta.persistence.MappedSuperclass; | ||
import jakarta.persistence.PostLoad; | ||
import jakarta.persistence.PostPersist; | ||
import jakarta.persistence.PostUpdate; | ||
import jakarta.persistence.PreUpdate; | ||
import jakarta.persistence.Transient; | ||
|
||
@MappedSuperclass | ||
public abstract class SkipModifiedAtBaseTimeEntity extends BaseTimeEntity { | ||
|
||
@Transient | ||
private LocalDateTime lastModifiedAt; | ||
|
||
@Transient | ||
private boolean isModified = true; | ||
|
||
@PreUpdate | ||
private void preUpdate() { | ||
if (!isModified && lastModifiedAt != null) { | ||
modifiedAt = lastModifiedAt; | ||
return; | ||
} | ||
isModified = true; | ||
} | ||
|
||
@PostLoad | ||
@PostPersist | ||
@PostUpdate | ||
private void postLoad() { | ||
lastModifiedAt = modifiedAt; | ||
} | ||
|
||
public void skipModifiedAtUpdate() { | ||
isModified = false; | ||
} | ||
} |
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
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