Я создаю API rest, и он мне нужен, когда я "найду ALL" вместо того, чтобы получить все данные, я просто выбираю несколько. С Java я сделал это так:
@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);
}
С Kotlin я пытаюсь так:
@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)
}
Но возврат всегда пуст. Может ли кто-нибудь помочь? Пожалуйста.
UPDATE:
Мой класс LegalPerson
data class LegalPerson(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
override var id: Long,
@Column(nullable = false)
val companyId: Long,
@Column(nullable = false)
var active: Boolean,
@Column(nullable = false, length = 100)
val tradeName: String,
@Column(nullable = false, length = 100)
val companyName: String,
@Column(nullable = false, length = 100)
val email: String,
@Column(nullable = false, length = 18)
val cnpj: String,
@Column(length = 15)
val stateRegistration: String,
@Column(length = 15)
val municipalRegistration: String,
@Column(nullable = false)
val openingDate: LocalDate,
@Column(nullable = false)
val address: Long,
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "phone", schema = "legal_person")
val phones: List<Long>
)
Мой класс LegalPersonMPage
data class LegalPersonMPage(
val id: Long,
val tradeName: String,
val companyName: String,
val cnpj: String
) {
}