I am pretty new to java and spring.
What I want to implement is api endpoint /tickets
with pagination and sorting. I made it and it works. But also what I would like to do is to return plain list of all tickets if size
and page
are not specified in the query params, so in FE I can use that list in selectbox.
What I have tried to do is to implement getTickets
on service facade and return list of all tickets. But I didn't find a way how to check if Pageable is set as it always returns default values (size=20, page=0)
//Controller
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Page<TicketListItemResponseModel>> getTickets(Pageable pageable) {
logger.info("> getTickets");
Page<TicketListItemResponseModel> tickets = ticketServiceFacade.getTickets(pageable);
logger.info("< getTickets");
return new ResponseEntity<>(tickets, HttpStatus.OK);
}
//TicketServiceFacade
public Page<TicketListItemResponseModel> getTickets(Pageable pageable) {
Page<Ticket> tickets = ticketService.findAll(pageable);
return tickets.map(new ConverterFromPagesToListItem());
}
public List<TicketListItemResponseModel> getTickets() {
List<Ticket> tickets = ticketService.findAll();
return tickets.stream()
.map(t -> modelMapper.map(t, TicketListItemResponseModel.class))
.collect(Collectors.toList());
}
Perhaps I do it totally wrong?