Skip to content

Commit

Permalink
Channels can be passed in when creating events (#92)
Browse files Browse the repository at this point in the history
* Channels can be passed in when creating events

* Refactoring
  • Loading branch information
mroloux authored Aug 25, 2023
1 parent c6b886c commit dff5c37
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 57 deletions.
14 changes: 14 additions & 0 deletions src/Events/CreateEventParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@

class CreateEventParams extends EventParams
{
/**
* @var \Seatsio\Events\Channel[]
*/
public $channels;

static function create(): CreateEventParams
{
return new CreateEventParams();
}

/**
* @param \Seatsio\Events\Channel[] $channels
*/
public function setChannels(array $channels): self
{
$this->channels = $channels;
return $this;
}
}
5 changes: 4 additions & 1 deletion src/Events/EventParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public function setObjectCategories($objectCategories): self
return $this;
}

public function setCategories($categories): self
/**
* @param \Seatsio\Charts\Category[] $categories
*/
public function setCategories(array $categories): self
{
$this->categories = $categories;
return $this;
Expand Down
8 changes: 8 additions & 0 deletions src/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function create(string $chartKey, CreateEventParams $params = null): Even
if ($params->categories !== null) {
$request->categories = $params->categories;
}

if ($params->channels !== null) {
$request->channels = $params->channels;
}
}

$res = $this->client->post('/events', ['json' => $request]);
Expand Down Expand Up @@ -104,6 +108,10 @@ public function createMultiple(string $chartKey, array $createEventParams): arra
$eventToCreate->categories = $param->categories;
}

if ($param->channels !== null) {
$eventToCreate->channels = $param->channels;
}

$request->events[] = $eventToCreate;
}

Expand Down
14 changes: 14 additions & 0 deletions src/Seasons/SeasonCreationParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class SeasonCreationParams
*/
public $tableBookingConfig;

/**
* @var \Seatsio\Events\Channel[]
*/
public $channels;

public function __construct(string $key = null)
{
$this->key = $key;
Expand Down Expand Up @@ -54,4 +59,13 @@ public function setTableBookingConfig(TableBookingConfig $tableBookingConfig): s
$this->tableBookingConfig = $tableBookingConfig;
return $this;
}

/**
* @param \Seatsio\Events\Channel[] $channels
*/
public function setChannels(array $channels): self
{
$this->channels = $channels;
return $this;
}
}
4 changes: 4 additions & 0 deletions src/Seasons/Seasons.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function create(string $chartKey, SeasonCreationParams $seasonCreationPar
if ($seasonCreationParams->tableBookingConfig !== null) {
$request->tableBookingConfig = $this->serializeTableBookingConfig($seasonCreationParams->tableBookingConfig);
}

if ($seasonCreationParams->channels !== null) {
$request->channels = $seasonCreationParams->channels;
}
}

$res = $this->client->post('/seasons', ['json' => $request]);
Expand Down
10 changes: 4 additions & 6 deletions tests/Events/BookObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ public function testKeepExtraData()
public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));

$this->seatsioClient->events->book($event->key, "A-1", null, null, null, null, ["channelKey1"]);

Expand All @@ -93,10 +92,9 @@ public function testChannelKeys()
public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));

$this->seatsioClient->events->book($event->key, "A-1", null, null, null, true);

Expand Down
10 changes: 4 additions & 6 deletions tests/Events/ChangeBestAvailableObjectStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ public function testKeepExtraData()
public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["B-6"])
]);
]));

$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 1, "lolzor", null, null, null, null, null, null, null, ["channelKey1"]);

Expand All @@ -173,10 +172,9 @@ public function testChannelKeys()
public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-5"])
]);
]));

$bestAvailableObjects = $this->seatsioClient->events->changeBestAvailableObjectStatus($event->key, 1, "lolzor", null, null, null, null, null, null, true);

Expand Down
10 changes: 4 additions & 6 deletions tests/Events/ChangeObjectStatusInBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public function test()
public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1"])
]);
]));

$response = $this->seatsioClient->events->changeObjectStatusInBatch([
new StatusChangeRequest($event->key, "A-1", "lolzor", null, null, null, null, ["channelKey1"])
Expand All @@ -47,10 +46,9 @@ public function testChannelKeys()
public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1"])
]);
]));

$response = $this->seatsioClient->events->changeObjectStatusInBatch([
new StatusChangeRequest($event->key, "A-1", "lolzor", null, null, null, true)
Expand Down
10 changes: 4 additions & 6 deletions tests/Events/ChangeObjectStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ public function testKeepExtraData()
public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));

$this->seatsioClient->events->changeObjectStatus($event->key, "A-1", "someStatus", null, null, null, null, ["channelKey1"]);

Expand All @@ -139,10 +138,9 @@ public function testChannelKeys()
public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));

$this->seatsioClient->events->changeObjectStatus($event->key, "A-1", "someStatus", null, null, null, true);

Expand Down
7 changes: 3 additions & 4 deletions tests/Events/Channels/RemoveChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Seatsio\Events\Channels;

use Seatsio\Events\Channel;
use Seatsio\Events\CreateEventParams;
use Seatsio\SeatsioClientTest;

class RemoveChannelTest extends SeatsioClientTest
Expand All @@ -12,12 +13,10 @@ public function test()
{

$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);

$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]),
new Channel("channelKey2", "channel 2", "#FF0000", 2, [])
]);
]));

$this->seatsioClient->events->channels->remove($event->key, "channelKey2");

Expand Down
13 changes: 13 additions & 0 deletions tests/Events/CreateEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,17 @@ public function testDateCanBePassedIn()

self::assertEquals(LocalDate::create(2022, 1, 5), $event->date);
}

public function testChannelsCanBePassedIn()
{
$chartKey = $this->createTestChart();
$channels = [
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]),
new Channel("channelKey2", "channel 2", "#00FFFF", 2, [])
];

$event = $this->seatsioClient->events->create($chartKey, CreateEventParams::create()->setChannels($channels));

self::assertEquals($channels, $event->channels);
}
}
14 changes: 14 additions & 0 deletions tests/Events/CreateEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,18 @@ public function test_dateCanBePassedIn()
self::assertEquals(LocalDate::create(2022, 1, 10), $events[0]->date);
}

public function test_channelsCanBePassedIn()
{
$chartKey = $this->createTestChart();
$channels = [
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"]),
new Channel("channelKey2", "channel 2", "#00FFFF", 2, [])
];

$params = [CreateEventParams::create()->setChannels($channels)];
$events = $this->seatsioClient->events->createMultiple($chartKey, $params);

self::assertEquals($channels, $events[0]->channels);
}

}
14 changes: 6 additions & 8 deletions tests/Events/HoldObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ public function testKeepExtraData()
public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$holdToken = $this->seatsioClient->holdTokens->create();
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));
$holdToken = $this->seatsioClient->holdTokens->create();

$this->seatsioClient->events->hold($event->key, "A-1", $holdToken->holdToken, null, null, null, ["channelKey1"]);

Expand All @@ -70,11 +69,10 @@ public function testChannelKeys()
public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$holdToken = $this->seatsioClient->holdTokens->create();
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));
$holdToken = $this->seatsioClient->holdTokens->create();

$this->seatsioClient->events->hold($event->key, "A-1", $holdToken->holdToken, null, null, true);

Expand Down
10 changes: 4 additions & 6 deletions tests/Events/ReleaseObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ public function testKeepExtraData()
public function testChannelKeys()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));
$this->seatsioClient->events->book($event->key, "A-1", null, null, null, null, ["channelKey1"]);

$this->seatsioClient->events->release($event->key, "A-1", null, null, null, null, ["channelKey1"]);
Expand All @@ -78,10 +77,9 @@ public function testChannelKeys()
public function testIgnoreChannels()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channelKey1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));
$this->seatsioClient->events->book($event->key, "A-1", null, null, null, null, ["channelKey1"]);

$this->seatsioClient->events->release($event->key, "A-1", null, null, null, true);
Expand Down
6 changes: 3 additions & 3 deletions tests/Reports/EventReportsSummaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Seatsio\Reports;

use Seatsio\Events\Channel;
use Seatsio\Events\CreateEventParams;
use Seatsio\Events\ObjectProperties;
use Seatsio\SeatsioClientTest;

Expand Down Expand Up @@ -336,10 +337,9 @@ public function testSummaryByAvailabilityReason()
public function testSummaryByChannel()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));

$report = $this->seatsioClient->eventReports->summaryByChannel($event->key);

Expand Down
19 changes: 8 additions & 11 deletions tests/Reports/EventReportsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ class EventReportsTest extends SeatsioClientTest
public function testReportItemProperties()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]));
$extraData = ["foo" => "bar"];
$this->seatsioClient->events->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1")->setExtraData($extraData), null, "order1");
$this->seatsioClient->events->channels->replace($event->key, [
new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1"])
]);
$this->seatsioClient->events->book($event->key, (new ObjectProperties("A-1"))->setTicketType("ticketType1")->setExtraData($extraData), null, "order1", null, true);

$report = $this->seatsioClient->eventReports->byLabel($event->key);

Expand Down Expand Up @@ -315,10 +314,9 @@ public function testBySpecificAvailabilityReason()
public function testByChannel()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));

$report = $this->seatsioClient->eventReports->byChannel($event->key);

Expand All @@ -329,10 +327,9 @@ public function testByChannel()
public function testBySpecificChannel()
{
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);
$this->seatsioClient->events->channels->replace($event->key, [
$event = $this->seatsioClient->events->create($chartKey, (new CreateEventParams())->setChannels([
new Channel("channel1", "channel 1", "#FF0000", 1, ["A-1", "A-2"])
]);
]));

$report = $this->seatsioClient->eventReports->byChannel($event->key, 'channel1');

Expand Down
Loading

0 comments on commit dff5c37

Please sign in to comment.