Skip to content

Instantly share code, notes, and snippets.

@xetra11
Last active September 10, 2020 15:52
Show Gist options
  • Save xetra11/27430c8f9da923614531c4443ee08091 to your computer and use it in GitHub Desktop.
Save xetra11/27430c8f9da923614531c4443ee08091 to your computer and use it in GitHub Desktop.
Kotlin Property Override Extension
fun addBloodlineToCharacter(characterId: String, bloodlineId: String): CharacterOutput? {
val character: CharacterDocument = characterRepository.findById(characterId)
updatedCharacter = characterRepository.save(character.override(_bloodlineId = bloodlineId))
updatedCharacter.asOutput()
}
fun CharacterDocument.override(
_name: String = this.name,
_age: Short = this.age,
_bloodlineId: String? = this.bloodlineId,
_villageId: String? = this.villageId,
_timestamp: Long? = this.timestamp,
): CharacterDocument {
return CharacterDocument(
id = this.id,
name = _name,
age = _age,
bloodlineId = _bloodlineId,
villageId = _villageId,
timestamp = _timestamp
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment