Skip to content

Instantly share code, notes, and snippets.

@Tonel
Created July 26, 2020 13:55
Show Gist options
  • Select an option

  • Save Tonel/140017baa4130cf2db5e37e3857dcc96 to your computer and use it in GitHub Desktop.

Select an option

Save Tonel/140017baa4130cf2db5e37e3857dcc96 to your computer and use it in GitHub Desktop.
@RestController
@RequestMapping("/authors")
class AuthorController : CustomController() {
@Autowired
lateinit var authorMapper: AuthorMapper
@GetMapping("v1/")
fun getAll() : ResponseEntity<List<AuthorDto>> {
return ResponseEntity(
authorMapper.authorsToAuthorDtos(
authorService.getAll()
), HttpStatus.OK)
}
@GetMapping("v1/special/{id}")
fun getSpecial(@PathVariable(value = "id") id: Int) : ResponseEntity<SpecialAuthorDto> {
return ResponseEntity(
authorMapper.authorToSpecialAuthorDto(
authorService.getByKey(id)
), HttpStatus.OK)
}
@GetMapping("v1/{id}")
fun get(@PathVariable(value = "id") id: Int) : ResponseEntity<AuthorDto> {
return ResponseEntity(
authorMapper.authorToAuthorDto(
authorService.getByKey(id)
), HttpStatus.OK)
}
@GetMapping("v1/find")
fun findByName(
@RequestParam(value = "name", required = true) @NotEmpty @NotBlank name: String
) : ResponseEntity<List<AuthorDto>> {
return ResponseEntity(
authorMapper.authorsToAuthorDtos(
authorService.getByName(name)
), HttpStatus.OK)
}
}
@Validated
@Transactional(readOnly = true)
abstract class CustomController {
@Autowired
protected lateinit var authorService: AuthorService
@Autowired
protected lateinit var bookService: BookService
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment