Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
III-2331: Event & Organizer controller changes based on new UiTPAS AP…
Browse files Browse the repository at this point in the history
…I (WIP)
  • Loading branch information
bertramakers committed Oct 31, 2017
1 parent 641943d commit c2bd420
Show file tree
Hide file tree
Showing 14 changed files with 433 additions and 249 deletions.
22 changes: 18 additions & 4 deletions app/Controller/EventControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class EventControllerProvider implements ControllerProviderInterface
*/
public function connect(Application $app)
{
$app['uitpas.event_controller'] = $app->share(
$app['uitpas.event_card_system_controller'] = $app->share(
function (Application $app) {
return new EventController(
return new EventCardSystemsController(
$app['culturefeed_uitpas_client']
);
}
Expand All @@ -25,8 +25,22 @@ function (Application $app) {
$controllers = $app['controllers_factory'];

$controllers->get(
'/{eventId}/distributionKeys/',
'uitpas.event_controller' . ':get'
'/{eventId}/cardSystems/',
'uitpas.event_card_system_controller:get'
);

$controllers->put(
'/{eventId}/cardSystems/{cardSystemId}',
'uitpas.event_card_system_controller:add'
);
$controllers->put(
'/{eventId}/cardSystems/{cardSystemId}/{distributionKeyId}',
'uitpas.event_card_system_controller:add'
);

$controllers->delete(
'/{eventId}/cardSystems/{cardSystemId}',
'uitpas.event_card_system_controller:delete'
);

return $controllers;
Expand Down
6 changes: 3 additions & 3 deletions app/Controller/OrganizerControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class OrganizerControllerProvider implements ControllerProviderInterface
*/
public function connect(Application $app)
{
$app['uitpas.organizer_controller'] = $app->share(
$app['uitpas.organizer_card_system_controller'] = $app->share(
function (Application $app) {
return new OrganizerController(
return new OrganizerCardSystemsController(
$app['culturefeed_uitpas_client']
);
}
Expand All @@ -27,7 +27,7 @@ function (Application $app) {

$controllers->get(
'/{organizerId}/cardSystems/',
'uitpas.organizer_controller:getCardSystems'
'uitpas.organizer_card_system_controller:get'
);

return $controllers;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"require": {
"broadway/broadway": "~0.10.0",
"cultuurnet/broadway-amqp": "~0.1",
"cultuurnet/culturefeed-php": "~1.6",
"cultuurnet/culturefeed-php": "dev-feature/III-2331 as 1.6",
"cultuurnet/deserializer": "~0.1",
"cultuurnet/silex-amqp": "~0.1",
"cultuurnet/silex-service-provider-jwt": "~0.1",
Expand Down
25 changes: 17 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions src/Controller/EventCardSystemsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Controller;

use CultuurNet\UDB3\UiTPASService\Controller\Response\CardSystemsJsonResponse;
use Symfony\Component\HttpFoundation\Response;

class EventCardSystemsController
{
/**
* @var \CultureFeed_Uitpas
*/
private $uitpas;

/**
* @param \CultureFeed_Uitpas $uitpas
*/
public function __construct(\CultureFeed_Uitpas $uitpas)
{
$this->uitpas = $uitpas;
}

/**
* @param string $eventId
* @return CardSystemsJsonResponse
*/
public function get($eventId)
{
$cardSystems = $this->uitpas->getCardSystemsForEvent($eventId);
return new CardSystemsJsonResponse($cardSystems->objects);
}

/**
* @param string $eventId
* @param string $cardSystemId
* @param string|null $distributionKeyId
* @return Response
*/
public function add($eventId, $cardSystemId, $distributionKeyId = null)
{
$this->uitpas->addCardSystemToEvent($eventId, $cardSystemId, $distributionKeyId);
return new Response('OK', 200);
}

/**
* @param string $eventId
* @param string $cardSystemId
* @return Response
*/
public function delete($eventId, $cardSystemId)
{
$this->uitpas->deleteCardSystemFromEvent($eventId, $cardSystemId);
return new Response('OK', 200);
}
}
40 changes: 0 additions & 40 deletions src/Controller/EventController.php

This file was deleted.

31 changes: 31 additions & 0 deletions src/Controller/OrganizerCardSystemsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Controller;

use CultuurNet\UDB3\UiTPASService\Controller\Response\CardSystemsJsonResponse;

class OrganizerCardSystemsController
{
/**
* @var \CultureFeed_Uitpas
*/
private $uitpas;

/**
* @param \CultureFeed_Uitpas $uitpas
*/
public function __construct(\CultureFeed_Uitpas $uitpas)
{
$this->uitpas = $uitpas;
}

/**
* @param string $organizerId
* @return CardSystemsJsonResponse
*/
public function get($organizerId)
{
$cardSystems = $this->uitpas->getCardSystemsForOrganizer($organizerId);
return new CardSystemsJsonResponse($cardSystems->objects);
}
}
78 changes: 0 additions & 78 deletions src/Controller/OrganizerController.php

This file was deleted.

55 changes: 55 additions & 0 deletions src/Controller/Response/CardSystemsJsonResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Controller\Response;

use Symfony\Component\HttpFoundation\Response;

class CardSystemsJsonResponse extends Response
{
/**
* @param \CultureFeed_Uitpas_CardSystem[] $cardSystems
* @param int $status
* @param array $headers
*/
public function __construct(array $cardSystems, $status = 200, array $headers = array())
{
$data = [];
foreach ($cardSystems as $cardSystem) {
$data[$cardSystem->id] = $this->convertCardSystemToArray($cardSystem);
}

$content = json_encode($data);

parent::__construct($content, $status, $headers);
}

/**
* @param \CultureFeed_Uitpas_CardSystem $cardSystem
* @return array
*/
private function convertCardSystemToArray(\CultureFeed_Uitpas_CardSystem $cardSystem)
{
$distributionKeys = [];
foreach ($cardSystem->distributionKeys as $distributionKey) {
$distributionKeys[$distributionKey->id] = $this->convertDistributionKeyToArray($distributionKey);
}

return [
'id' => $cardSystem->id,
'name' => $cardSystem->name,
'distributionKeys' => $distributionKeys,
];
}

/**
* @param \CultureFeed_Uitpas_DistributionKey $distributionKey
* @return array
*/
private function convertDistributionKeyToArray(\CultureFeed_Uitpas_DistributionKey $distributionKey)
{
return [
'id' => $distributionKey->id,
'name' => $distributionKey->name,
];
}
}
Loading

0 comments on commit c2bd420

Please sign in to comment.