Skip to content

Instantly share code, notes, and snippets.

@Tonel
Last active March 1, 2021 08:38
Show Gist options
  • Save Tonel/54baa8d0a7d5dde969b61f76c1f6f964 to your computer and use it in GitHub Desktop.
Save Tonel/54baa8d0a7d5dde969b61f76c1f6f964 to your computer and use it in GitHub Desktop.
@RestController
@RequestMapping("/authors")
class AuthorController {
@Autowired
lateinit var authorRepository: AuthorRepository
@Autowired
lateinit var authorMapper: AuthorMapper
@Autowired
lateinit var specialAuthorMapper: SpecialAuthorMapper
@GetMapping
fun getAll() : ResponseEntity<List<AuthorDto>> {
return ResponseEntity(
authorMapper.authorsToAuthorDtos(authorRepository.findAll()),
HttpStatus.OK)
}
@GetMapping("special/{id}")
fun getSpecial(@PathVariable(value = "id") id: Int) : ResponseEntity<SpecialAuthorDto> {
return ResponseEntity(
specialAuthorMapper.authorToSpecialAuthorDto(authorRepository.find(id)),
HttpStatus.OK)
}
@GetMapping("{id}")
fun get(@PathVariable(value = "id") id: Int) : ResponseEntity<AuthorDto> {
return ResponseEntity(
authorMapper.authorToAuthorDto(authorRepository.find(id)),
HttpStatus.OK)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment