public function __invoke(ServerRequestInterface $request, ResponseInterface $response) { $data = $request->getParsedBody(); Assertion::keyExists($data, 'origin'); Assertion::keyExists($data, 'destination'); $trackingId = $this->bookingService->bookNewCargo($data['origin'], $data['destination']); return new JsonResponse(['trackingId' => $trackingId]); }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { if (null === ($trackingId = $request->getAttribute('trackingId'))) { return new EmptyResponse(404); } try { $cargoRoutingDto = $this->bookingService->loadCargoForRouting($trackingId); return new JsonResponse($cargoRoutingDto->getArrayCopy()); } catch (CargoNotFoundException $e) { return new EmptyResponse(404); } }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response) { if (null === ($trackingId = $request->getAttribute('trackingId'))) { return new EmptyResponse(404); } $candidateIndex = 1; return new JsonResponse(['routeCandidates' => array_map(function (RouteCandidateDto $routeCandidate) use(&$candidateIndex) { $candidateData = $routeCandidate->getArrayCopy(); $candidateData['id'] = $candidateIndex; $candidateIndex++; return $candidateData; }, $this->bookingService->requestPossibleRoutesForCargo($trackingId))]); }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { if (null === ($trackingId = $request->getAttribute('trackingId'))) { return new EmptyResponse(404); } $cargoData = $request->getParsedBody(); if (!isset($cargoData['legs']) || !is_array($cargoData['legs'])) { throw new \InvalidArgumentException("Missing legs for cargo"); } $routeCandidate = new RouteCandidateDto(); $routeCandidate->setLegs($this->toLegDtosFromData($cargoData['legs'])); try { $this->bookingService->assignCargoToRoute($trackingId, $routeCandidate); $cargoRoutingDto = $this->bookingService->loadCargoForRouting($trackingId); return new JsonResponse($cargoRoutingDto->getArrayCopy()); } catch (CargoNotFoundException $e) { return new EmptyResponse(404); } }
/** * @test */ public function it_lists_all_stored_cargos() { $trackingIdOne = $this->bookingService->bookNewCargo('USNYC', 'DEHAM'); $trackingIdTwo = $this->bookingService->bookNewCargo('NLRTM', 'USNYC'); $cargoRoutingDtos = $this->bookingService->listAllCargos(); $this->assertEquals(2, count($cargoRoutingDtos)); $generatedTrackingIds = [$trackingIdOne, $trackingIdTwo]; foreach ($cargoRoutingDtos as $cargoRoutingDto) { $this->assertTrue(in_array($cargoRoutingDto->getTrackingId(), $generatedTrackingIds)); } }
/** * @param RequestInterface $request * @param ResponseInterface $response * @return JsonResponse */ public function __invoke(RequestInterface $request, ResponseInterface $response) { return new JsonResponse(['locations' => array_map(function (LocationDto $locationDto) { return ['name' => $locationDto->getName(), 'unLocode' => $locationDto->getUnLocode()]; }, $this->bookingService->listShippingLocations())]); }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { return new JsonResponse(['cargos' => array_map(function (CargoRoutingDto $cargoRoutingDto) { return $cargoRoutingDto->getArrayCopy(); }, $this->bookingService->listAllCargos())]); }