Skip to content

Commit be50888

Browse files
author
Codeliner
committed
Add API layer to CargoBackend
1 parent 8e57aa8 commit be50888

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1503
-452
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ before_script:
2424

2525
script:
2626
- php ./bin/phpunit -c ./module/CargoBackend/tests
27+
- php ./bin/phpunit -c ./module/GraphTraversalService/tests
2728
- bin/behat --verbose
2829

config/application.config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'DoctrineORMModule',
77
'ZfcTwitterBootstrap',
88
'CargoBackend',
9-
'RoutingService',
9+
'GraphTraversalService',
1010
'Application',
1111
),
1212

module/Application/src/Application/Controller/CargoController.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
namespace Application\Controller;
1010

11-
use CargoBackend\API\CargoService;
11+
use CargoBackend\API\BookingService;
1212
use CargoBackend\API\Dto\TrackingIdDto;
1313
use CargoBackend\API\Exception\CargoNotFoundException;
1414
use RoutingService\RoutingService;
@@ -25,9 +25,9 @@
2525
class CargoController extends AbstractActionController
2626
{
2727
/**
28-
* @var CargoService
28+
* @var BookingService
2929
*/
30-
protected $cargoService;
30+
protected $bookingService;
3131

3232
/**
3333
*
@@ -50,7 +50,7 @@ class CargoController extends AbstractActionController
5050

5151
public function indexAction()
5252
{
53-
$trackingIds = $this->cargoService->listAllCargoTrackingIds();
53+
$trackingIds = $this->bookingService->listAllCargoTrackingIds();
5454

5555
return new ViewModel(array('trackingIds' => $trackingIds->getTrackingIds()));
5656
}
@@ -68,7 +68,7 @@ public function showAction()
6868
$trackingIdDto->setTrackingId($trackingId);
6969

7070
try {
71-
$cargoData = $this->cargoService->getCargoDataByTrackingId($trackingIdDto);
71+
$cargoData = $this->bookingService->getCargoDataByTrackingId($trackingIdDto);
7272
} catch (CargoNotFoundException $ex) {
7373
throw new \RuntimeException('Cargo can not be found. Please check the trackingId!', 404, $ex);
7474
}
@@ -205,11 +205,11 @@ public function assignItineraryAction()
205205
}
206206

207207
/**
208-
* @param CargoService $aCargoService
208+
* @param BookingService $aBookingService
209209
*/
210-
public function setCargoService(CargoService $aCargoService)
210+
public function setBookingService(BookingService $aBookingService)
211211
{
212-
$this->cargoService = $aCargoService;
212+
$this->bookingService = $aBookingService;
213213
}
214214

215215
/**

module/CargoBackend/Module.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@
1414

1515
class Module
1616
{
17-
public function onBootstrap(MvcEvent $e)
18-
{
19-
$eventManager = $e->getApplication()->getEventManager();
20-
$moduleRouteListener = new ModuleRouteListener();
21-
$moduleRouteListener->attach($eventManager);
22-
}
23-
2417
public function getConfig()
2518
{
2619
$config = include __DIR__ . '/config/module.config.php';
20+
$config['locations'] = include __DIR__ . '/config/locations.php';
2721
return $config;
2822
}
2923

File renamed without changes.

module/CargoBackend/config/module.config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
return array(
1010
'service_manager' => array(
1111
'factories' => array(
12-
'cargo_service' => 'CargoBackend\API\Service\CargoServiceFactory',
12+
'booking_service' => 'CargoBackend\API\Service\BookingServiceFactory',
1313
'cargo_repository' => 'CargoBackend\Infrastructure\Persistence\Service\CargoRepositoryFactory',
1414
),
1515
),
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/*
3+
* This file is part of the codeliner/php-ddd-cargo-sample.
4+
* (c) Alexander Miertsch <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 29.03.14 - 18:21
10+
*/
11+
12+
namespace CargoBackend\API\Booking\Assembler;
13+
use CargoBackend\API\Booking\Dto\CargoRoutingDto;
14+
use CargoBackend\API\Booking\Dto\LegDto;
15+
use CargoBackend\Model\Cargo\Cargo;
16+
17+
/**
18+
* Class CargoRoutingDtoAssembler
19+
*
20+
* @package CargoBackend\API\Booking\Assembler
21+
* @author Alexander Miertsch <[email protected]>
22+
*/
23+
class CargoRoutingDtoAssembler
24+
{
25+
/**
26+
* @param Cargo $aCargo
27+
* @return CargoRoutingDto
28+
*/
29+
public function toDto(Cargo $aCargo)
30+
{
31+
$cargoRoutingDto = new CargoRoutingDto();
32+
33+
$cargoRoutingDto->setTrackingId($aCargo->trackingId()->toString());
34+
$cargoRoutingDto->setOrigin($aCargo->origin());
35+
$cargoRoutingDto->setFinalDestination($aCargo->routeSpecification()->destination());
36+
37+
foreach ($aCargo->itinerary()->legs() as $leg) {
38+
$legDto = new LegDto();
39+
40+
$legDto->setLoadLocation($leg->loadLocation());
41+
$legDto->setUnloadLocation($leg->unloadLocation());
42+
$legDto->setLoadTime($leg->loadTime()->format(\DateTime::ISO8601));
43+
$legDto->setUnloadTime($leg->unloadTime()->format(\DateTime::ISO8601));
44+
45+
$cargoRoutingDto->addLeg($legDto);
46+
}
47+
48+
return $cargoRoutingDto;
49+
}
50+
}
51+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/*
3+
* This file is part of the codeliner/php-ddd-cargo-sample.
4+
* (c) Alexander Miertsch <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 29.03.14 - 21:06
10+
*/
11+
12+
namespace CargoBackend\API\Booking\Assembler;
13+
14+
use CargoBackend\API\Booking\Dto\LegDto;
15+
use CargoBackend\API\Booking\Dto\RouteCandidateDto;
16+
use CargoBackend\Model\Cargo\Itinerary;
17+
use CargoBackend\Model\Cargo\Leg;
18+
19+
/**
20+
* Class RouteCandidateDtoAssembler
21+
*
22+
* @package CargoBackend\API\Booking\Assembler
23+
* @author Alexander Miertsch <[email protected]>
24+
*/
25+
class RouteCandidateDtoAssembler
26+
{
27+
/**
28+
* @param Itinerary $anItinerary
29+
* @return RouteCandidateDto
30+
*/
31+
public function toDto(Itinerary $anItinerary)
32+
{
33+
$legs = array();
34+
35+
foreach ($anItinerary->legs() as $leg) {
36+
$legDto = new LegDto();
37+
38+
$legDto->setLoadLocation($leg->loadLocation());
39+
$legDto->setUnloadLocation($leg->unloadLocation());
40+
$legDto->setLoadTime($leg->loadTime()->format(\DateTime::ISO8601));
41+
$legDto->setUnloadTime($leg->loadTime()->format(\DateTime::ISO8601));
42+
43+
$legs[] = $legDto;
44+
}
45+
46+
$routeCandidate = new RouteCandidateDto();
47+
48+
$routeCandidate->setLegs($legs);
49+
50+
return $routeCandidate;
51+
}
52+
53+
/**
54+
* @param RouteCandidateDto $aRouteCandidate
55+
* @return Itinerary
56+
*/
57+
public function toItinerary(RouteCandidateDto $aRouteCandidate)
58+
{
59+
$legs = array();
60+
61+
foreach ($aRouteCandidate->getLegs() as $legDto) {
62+
$legs[] = new Leg(
63+
$legDto->getLoadLocation(),
64+
$legDto->getUnloadLocation(),
65+
new \DateTime($legDto->getLoadTime()),
66+
new \DateTime($legDto->getUnloadTime())
67+
);
68+
}
69+
70+
return new Itinerary($legs);
71+
}
72+
}
73+

0 commit comments

Comments
 (0)