I need to pass dateTs
from rest controller class-method into getCars()
method in the service class which will retrieve cars that were registered on the given timestamp date and if the timestamp dateTs
(its Optional) is null then it will retrieve all cars.
I think current implementation will not work since if dateTs
is null then it can't be passed into getCars()
which expects value of type Long
. Where and how should I check if the dateTs
is not null and how to pass corresponding value into getCars()
and invoke appropriate method?
@GetMapping(value = "/get/cars")
public CarList CarController(@Param("dateTs") Optional<Long> dateTs) {
return ResponseEntity.ok(carService.getCars((Long) dateSt.get());
}
Service class method:
public List<Car> getCars(Long dateSt) {
List<Car> carList;
if(dateSt != null){
carList = carReposistory.retrieveRegisteredCars(dateSt);}
else{
carList = carReposistory.retrieveAllCars();}
return carList;
}