From 1e552a1dafc893ce77b2c1ace9b4a0f73f8d0f48 Mon Sep 17 00:00:00 2001 From: devxb Date: Sat, 11 May 2024 14:36:24 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EB=82=99=EA=B4=80=EC=A0=81?= =?UTF-8?q?=EB=9D=BD=20retry=20=EB=A1=9C=EC=A7=81=EC=9D=B4=20=EB=B9=A0?= =?UTF-8?q?=EC=A7=84=EB=B6=80=EB=B6=84=EC=97=90=20retry=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/org/gitanimals/render/domain/UserService.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/org/gitanimals/render/domain/UserService.kt b/src/main/kotlin/org/gitanimals/render/domain/UserService.kt index f55ee71..0264459 100644 --- a/src/main/kotlin/org/gitanimals/render/domain/UserService.kt +++ b/src/main/kotlin/org/gitanimals/render/domain/UserService.kt @@ -49,6 +49,7 @@ class UserService( fun createNewUser(name: String, contributions: Map): User = userRepository.save(User.newUser(name, contributions)) + @Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 100) @Transactional fun giveBonusPersona(id: Long, persona: String) { requireIdempotency("$id:bonus") @@ -58,6 +59,7 @@ class UserService( user.giveBonusPersona(persona) } + @Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 100) @Transactional fun changePersona(id: Long, personChangeRequest: PersonaChangeRequest) { val user = getUserById(id) From c5037c293975ce03dc7c086a1bde6e0d7e6c9de0 Mon Sep 17 00:00:00 2001 From: devxb Date: Sat, 11 May 2024 15:03:57 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20modifiedAt=EC=9D=B4=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=EB=B2=84=EA=B7=B8=EB=A5=BC=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gitanimals/render/domain/AbstractTime.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt b/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt index 0b86180..85f6ec8 100644 --- a/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt +++ b/src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt @@ -2,6 +2,7 @@ package org.gitanimals.render.domain import jakarta.persistence.Column import jakarta.persistence.MappedSuperclass +import jakarta.persistence.PrePersist import org.springframework.data.annotation.CreatedDate import org.springframework.data.annotation.LastModifiedDate import java.time.Instant @@ -14,5 +15,14 @@ abstract class AbstractTime( @LastModifiedDate @Column(name = "modified_at") - val modifiedAt: Instant = createdAt, -) + var modifiedAt: Instant? = null, +) { + + @PrePersist + fun prePersist() { + modifiedAt = when (modifiedAt == null) { + true -> createdAt + false -> return + } + } +} From 54ed65ed30d3969ecc766da74961000097b904c6 Mon Sep 17 00:00:00 2001 From: devxb Date: Sat, 11 May 2024 15:05:48 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20persona=EC=97=90=20version=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=82=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/org/gitanimals/render/domain/Persona.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/org/gitanimals/render/domain/Persona.kt b/src/main/kotlin/org/gitanimals/render/domain/Persona.kt index e22ccb3..da8f6a1 100644 --- a/src/main/kotlin/org/gitanimals/render/domain/Persona.kt +++ b/src/main/kotlin/org/gitanimals/render/domain/Persona.kt @@ -26,6 +26,10 @@ class Persona( @JoinColumn(name = "user_id") @ManyToOne(fetch = FetchType.LAZY, optional = false) var user: User? = null, + + @Version + @Column(name = "version", nullable = false) + var version: Long? = null, ) : AbstractTime() { constructor(