Skip to content

Commit

Permalink
release: 0.4.5 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored May 11, 2024
2 parents 3f209dc + 54ed65e commit 22e6480
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/kotlin/org/gitanimals/render/domain/AbstractTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/org/gitanimals/render/domain/Persona.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/gitanimals/render/domain/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class UserService(
fun createNewUser(name: String, contributions: Map<Int, Int>): User =
userRepository.save(User.newUser(name, contributions))

@Retryable(retryFor = [ObjectOptimisticLockingFailureException::class], maxAttempts = 100)
@Transactional
fun giveBonusPersona(id: Long, persona: String) {
requireIdempotency("$id:bonus")
Expand All @@ -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)
Expand Down

0 comments on commit 22e6480

Please sign in to comment.