0

Is it possible, to somehow alter the code below, so in case of no status value provided to return all the PaymentLog objects stored in the database instead of only the ones with status equal with 404? Basically, I would like if the status variable has not been provided to call another method in the service layer logService.getAllPaymentLogs()

@GetMapping(Endpoints.LOGS.PAYMENT_LOGS)
public Page<PaymentLog> getPaymentLog(@RequestParam Optional<Integer> status) {
    return logService.getPaymentLogStatus(status.orElse(404), PageRequest.of(0, 10));
}

These are the getPaymentLogStatus() and getAllPaymentLogs

@Override
public Page<PaymentLog> getPaymentLog(Pageable pageable) {
    return paymentLogRepository.getAllBy(pageable);
}

And

@Override
public Page<PaymentLog> getPaymentLog(int status, Pageable pageable) {
    return paymentLogRepository.getAllByStatus(status, pageable);
}
Matt Ellen
  • 11,268
  • 4
  • 68
  • 90

1 Answers1

1

@123 answered the question in the commenting session:

status.map(s -> getPaymentLog(s, page)).orElseGet(() -> getPaymentLog(page))