Skip to content

Instantly share code, notes, and snippets.

@manuelernesto
Created July 5, 2022 20:04
Show Gist options
  • Save manuelernesto/4c5135f254c1ba4fc56c6f1f54351d68 to your computer and use it in GitHub Desktop.
Save manuelernesto/4c5135f254c1ba4fc56c6f1f54351d68 to your computer and use it in GitHub Desktop.
@RequestMapping("api/v1/players")
@RestController
class PlayerController(val service: PlayerService) {
@GetMapping
fun getAllPlayers() = service.getAll()
@GetMapping("/{id}")
fun getPlayer(@PathVariable id: Long) = service.getById(id)
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
fun savePlayer(@RequestBody player: Player): Player = service.create(player)
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun deletePlayer(@PathVariable id: Long) = service.remove(id)
@PutMapping("/{id}")
fun updatePlayer(
@PathVariable id: Long, @RequestBody player: Player
) = service.update(id, player)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment