I'm creating an API rest and I need it when I do "find ALL" instead of fetching all the data, I just fetch a few. With Java I did it this way:
@GetMapping(value = "/pagina")
public ResponseEntity<Page<PersonFindDTO>> findAll(
@RequestParam(value = "page", defaultValue = "0") Integer page,
@RequestParam(value = "linesPerPage", defaultValue = "24") Integer linesPerPage,
@RequestParam(value = "order", defaultValue = "ASC") String order,
@RequestParam(value = "orderBy", defaultValue = "name") String orderBy) {
var person = personService.findAll(page, linesPerPage, order, orderBy);
var personFindDto = person.map(PersonFindDTO::new);
return ResponseEntity.ok().body(personFindDTO);
}
With Kotlin, I'm trying this way:
@GetMapping(value = ["/{companyId}/{active}"])
override fun findAll(
@RequestParam(value = "page", defaultValue = "0") page: Int,
@RequestParam(value = "linesPerPage", defaultValue = "24") linesPerPage: Int,
@RequestParam(value = "order", defaultValue = "ASC") order: String,
@RequestParam(value = "orderBy", defaultValue = "tradeName") orderBy: String,
@PathVariable companyId: Long, @PathVariable active: Boolean): ResponseEntity<Page<Any>> {
val lp = service.findAll(page, linesPerPage, order, orderBy, companyId, active)?.let {
it.map {
fun LegalPerson.toLegalPersonMPage() = LegalPersonMPage(id = it.id,
tradeName = it.tradeName, companyName = it.companyName, cnpj = it.cnpj)
}
}
return ResponseEntity.ok().body(lp)
}
But the return is always empty. Could anyone help? Please.
Aucun commentaire:
Enregistrer un commentaire