@RequestMapping(value = "/updatePosition", method = RequestMethod.POST) public @ResponseBody RouteExecutionPoint updatePosition( @RequestBody RouteExecutionPoint routeExecutionPoint) { String token = request.getHeader("authToken"); Truck truck = truckRepository.getTruckByToken(token); RouteExecutionPeriod routeExecutionPeriod = repository.getCurrentRouteExecutionPeriod(truck); repository.addPointToRouteExecutionPeriod(routeExecutionPeriod, routeExecutionPoint); return routeExecutionPoint; }
@RequestMapping(value = "/stop", method = RequestMethod.POST) public @ResponseBody RouteExecutionPeriod stop(@RequestBody Date executionDate) { String token = request.getHeader("authToken"); Truck truck = truckRepository.getTruckByToken(token); RouteExecutionPeriod routeExecutionPeriod = repository.getCurrentRouteExecutionPeriod(truck); routeExecutionPeriod.setEndDate(executionDate); repository.update(routeExecutionPeriod); return routeExecutionPeriod; }
@RequestMapping(value = "/start", method = RequestMethod.POST) public @ResponseBody RouteExecutionPeriod start(@RequestBody Date executionDate) { String token = request.getHeader("authToken"); Truck truck = truckRepository.getTruckByToken(token); RouteExecution routeExecution = repository.getCurrentRouteExecution(truck); RouteExecutionPeriod routeExecutionPeriod = new RouteExecutionPeriod(); routeExecutionPeriod.setStartDate(executionDate); repository.addPeriodToRouteExecution(routeExecution, routeExecutionPeriod); return routeExecutionPeriod; }
@RequestMapping(value = "/me", method = RequestMethod.GET) public @ResponseBody RouteExecution getMy() { String token = request.getHeader("authToken"); Truck truck = truckRepository.getTruckByToken(token); return repository.getCurrentRouteExecution(truck); }
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) public @ResponseBody RouteExecution update( @PathVariable long id, @RequestBody RouteExecution routeExecution) { routeExecution.setId(id); return repository.update(routeExecution); }
@RequestMapping(method = RequestMethod.POST) public @ResponseBody RouteExecution create(@RequestBody RouteExecution routeExecution) throws Exception { return repository.save(routeExecution); }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public @ResponseBody RouteExecution getById(@PathVariable long id) { return repository.getById(id); }
@RequestMapping(method = RequestMethod.GET) public @ResponseBody List<RouteExecution> getAll() { List<RouteExecution> list = repository.getAll(); return list; }