-
-
Save manuelernesto/d25a0a36e3e1e7d60f93813a094cb860 to your computer and use it in GitHub Desktop.
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
@Service | |
class PlayerService(val repository: PlayerRepository) { | |
fun getAll(): List<Player> = repository.findAll() | |
fun getById(id: Long): Player = repository.findByIdOrNull(id) ?: | |
throw ResponseStatusException(HttpStatus.NOT_FOUND) | |
fun create(player: Player): Player = repository.save(player) | |
fun remove(id: Long) { | |
if (repository.existsById(id)) repository.deleteById(id) | |
else throw ResponseStatusException(HttpStatus.NOT_FOUND) | |
} | |
fun update(id: Long, player: Player): Player { | |
return if (repository.existsById(id)) { | |
player.id = id | |
repository.save(player) | |
} else throw ResponseStatusException(HttpStatus.NOT_FOUND) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment