Is there a way to use copy Kotlin function and use the original object value property in case of a conditional state non verified ?
Or a similar function that does that ?
Example:
data class UserEntity(
id = String,
email = String,
firstName = String,
lastName = String
)
data class UserUpdate(
firstName = String?,
lastName = String?
)
@Service
class UserService(userRepository: UserRepository) {
fun update(id: String, dto: UserUpdate) = userRepository.save(
userRepository.findById(id).copy(
// *it* is not available as the initial object the
// copy function is called from.
firstName = dto.firstName ?: it.firstName,
// I'd like something like:
lastName = dto.lastName ?: keepTheOriginalLastNameProperty
)
)
}