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

Commit

Permalink
Merge df361c4 into fd11a1f
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramakers committed Nov 25, 2019
2 parents fd11a1f + df361c4 commit 992f6e4
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 34 deletions.
4 changes: 4 additions & 0 deletions app/Controller/EventControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function (Application $app) {
'uitpas.event_card_systems_controller:get'
)->bind(self::EVENT_CARD_SYSTEMS);

$controllers->put(
'/{eventId}/cardSystems/',
'uitpas.event_card_systems_controller:set'
);
$controllers->put(
'/{eventId}/cardSystems/{cardSystemId}',
'uitpas.event_card_systems_controller:add'
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.9",
"cultuurnet/culturefeed-php": "~1.10",
"cultuurnet/deserializer": "~0.1",
"cultuurnet/silex-amqp": "~0.1",
"cultuurnet/silex-service-provider-jwt": "~0.1",
Expand Down
48 changes: 16 additions & 32 deletions composer.lock

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

12 changes: 12 additions & 0 deletions src/Controller/EventCardSystemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

class EventCardSystemsController
Expand All @@ -24,6 +25,17 @@ public function get(string $eventId): CardSystemsJsonResponse
return new CardSystemsJsonResponse($cardSystems->objects);
}

public function set(string $eventId, Request $request): Response
{
$cardSystemIds = json_decode($request->getContent(), true);
if (!is_array($cardSystemIds)) {
return new Response('Payload should be an array of card system ids', 400);
}

$this->uitpas->setCardSystemsForEvent($eventId, $cardSystemIds);
return new Response('OK', 200);
}

public function add(string $eventId, string $cardSystemId, string $distributionKeyId = null): Response
{
$this->uitpas->addCardSystemToEvent($eventId, $cardSystemId, $distributionKeyId);
Expand Down
40 changes: 40 additions & 0 deletions tests/Controller/EventCardSystemsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use CultureFeed_Uitpas_DistributionKey;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_TestCase;
use Symfony\Component\HttpFoundation\Request;

class EventCardSystemsControllerTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -119,6 +120,45 @@ public function it_can_get_card_systems_of_an_event()
$this->assertEquals($expectedResponseContent, $actualResponseContent);
}

/**
* @test
*/
public function it_can_set_a_list_of_card_systems_to_an_event()
{
$eventId = '52943e99-51c8-4ba9-95ef-ec7d93f16ed9';
$cardSystemIds = ['3', '15'];

$request = new Request([], [], [], [], [], [], json_encode($cardSystemIds));

$this->uitpas->expects($this->once())
->method('setCardSystemsForEvent')
->with($eventId, $cardSystemIds)
->willReturn(null);

$response = $this->controller->set($eventId, $request);

$this->assertEquals(200, $response->getStatusCode());
}

/**
* @test
*/
public function it_returns_an_error_response_if_the_list_of_card_system_ids_is_not_an_array()
{
$eventId = '52943e99-51c8-4ba9-95ef-ec7d93f16ed9';
$cardSystemIds = 3;

$request = new Request([], [], [], [], [], [], json_encode($cardSystemIds));

$this->uitpas->expects($this->never())
->method('setCardSystemsForEvent')
->willReturn(null);

$response = $this->controller->set($eventId, $request);

$this->assertEquals(400, $response->getStatusCode());
}

/**
* @test
*/
Expand Down
36 changes: 35 additions & 1 deletion web/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}
}
},
"/events/{cdbid}/cardSystems": {
"/events/{cdbid}/cardSystems/": {
"get": {
"summary": "View the card systems coupled to the cultural event.",
"operationId": "getEventCardSystems",
Expand All @@ -91,6 +91,40 @@
"$ref": "#/responses/APIProblem"
}
}
},
"put": {
"summary": "Set the card systems coupled to the cultural event. If the event is not known by UiTPAS, it will still be saved and applied when it becomes known.",
"operationId": "setEventCardSystems",
"produces": [
"text/plain",
"application/json"
],
"parameters": [
{
"$ref": "#/parameters/cdbid"
},
{
"name": "body",
"in": "body",
"description": "An array containing card system ids to set on the event.",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "string",
"example": "51423b80-01f5-43a0-8a2e-6c47c92e0efe"
}
}
}
],
"responses": {
"200": {
"description": "The event's card systems have been updated."
},
"400": {
"$ref": "#/responses/APIProblem"
}
}
}
},
"/events/{cdbid}/cardSystems/{cardSystemId}": {
Expand Down

0 comments on commit 992f6e4

Please sign in to comment.