Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/Requests/Company/EventAttendingRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace TruckersMP\APIClient\Requests\Company;

use Illuminate\Support\Collection;
use Psr\Http\Client\ClientExceptionInterface;
use TruckersMP\APIClient\Client;
use TruckersMP\APIClient\Exceptions\ApiErrorException;
use TruckersMP\APIClient\Models\Event;
use TruckersMP\APIClient\Requests\Request;

class EventAttendingRequest extends Request
{
/**
* The ID of the requested company.
*
* @var int
*/
protected int $companyId;

/**
* Create a new EventAttendingRequest instance.
*
* @param Client $client
* @param int $id
* @return void
*/
public function __construct(Client $client, int $id)
{
parent::__construct($client);

$this->companyId = $id;
}

/**
* Get the endpoint of the request.
*
* @return string
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->companyId . '/events/attending';
}

/**
* Get the data for the request.
*
* @return Collection|Event[]
*
* @throws ApiErrorException
* @throws ClientExceptionInterface
*/
public function get(): Collection
{
return (new Collection($this->send()['response']))
->map(fn (array $event) => new Event($this->client, $event));
}
}
13 changes: 13 additions & 0 deletions src/Requests/Company/EventIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ public function get(): CompanyEventIndex
$this->send()['response']
);
}

/**
* Get all events that the company is attending.
*
* @return EventAttendingRequest
*/
public function attending(): EventAttendingRequest
{
return new EventAttendingRequest(
$this->client,
$this->companyId,
);
}
}
4 changes: 2 additions & 2 deletions src/Requests/CompanyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function member(int $id): MemberRequest
}

/**
* Get the events for the company.
* Get the events created by the company.
*
* @return EventIndexRequest
*/
Expand All @@ -162,7 +162,7 @@ public function events(): EventIndexRequest
}

/**
* Get the event for the company with the specified ID.
* Get the event created by the company with the specified ID.
*
* @param int $id
* @return EventRequest
Expand Down
20 changes: 16 additions & 4 deletions tests/Unit/Requests/CompanyEventRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class CompanyEventRequestTest extends TestCase

public function testItCanGetAllCompanyEvents()
{
$this->mockRequest('company.event.index.json', 'vtc/258/events');
$this->mockRequest('company.event.index.json', 'vtc/22/events');

$index = $this->client->company(258)->events()->get();
$index = $this->client->company(22)->events()->get();

$this->assertInstanceOf(CompanyEventIndex::class, $index);

Expand All @@ -30,10 +30,22 @@ public function testItCanGetAllCompanyEvents()

public function testItCanGetASpecificCompanyEvent()
{
$this->mockRequest('event.json', 'vtc/258/events/45');
$this->mockRequest('event.json', 'vtc/22/events/45');

$event = $this->client->company(258)->event(45)->get();
$event = $this->client->company(22)->event(45)->get();

$this->assertInstanceOf(Event::class, $event);
}

public function testItCanGetEventsThatACompanyIsAttending()
{
$this->mockRequest('company.event.attending.json', 'vtc/22/events/attending');

$events = $this->client->company(22)->events()->attending()->get();

$this->assertInstanceOf(Collection::class, $events);
$this->assertCount(1, $events);

$this->assertInstanceOf(Event::class, $events->first());
}
}
56 changes: 56 additions & 0 deletions tests/Unit/Requests/fixtures/company.event.attending.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"error": false,
"response": [
{
"id": 2,
"event_type": {
"key": "convoy",
"name": "Convoy"
},
"name": "Today's Convoy",
"slug": "2-todays-convoy",
"game": "ETS2",
"server": {
"id": 4,
"name": "Server"
},
"language": "English",
"departure": {
"location": "Hotel",
"city": "Prague"
},
"arrive": {
"location": "Quarry",
"city": "Stuttgart"
},
"start_at": "2023-01-04 17:00:00",
"meetup_at": "2023-01-04 16:00:00",
"banner": "https://static.truckersmp.com/images/event/cover/cover.png",
"map": "https://static.truckersmp.com/images/event/map/map.jpeg",
"description": "",
"rule": null,
"voice_link": null,
"external_link": null,
"featured": "",
"vtc": {
"id": 789,
"name": "Example Logistics"
},
"user": {
"id": 33,
"username": "Organizer"
},
"attendances": {
"confirmed": 11,
"unsure": 5,
"vtcs": 4
},
"dlcs": {
"304212": "Scandinavia"
},
"url": "/events/2-todays-convoy",
"created_at": "2022-01-04 17:04:58",
"updated_at": "2022-01-04 17:13:15"
}
]
}
1 change: 1 addition & 0 deletions tests/Unit/Requests/fixtures/company.event.index.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"city": "Stuttgart"
},
"start_at": "2023-01-04 14:32:28",
"meetup_at": "2023-01-04 14:02:28",
"banner": "https://static.truckersmp.com/images/event/cover/cover.png",
"map": "https://static.truckersmp.com/images/event/map/map.png",
"description": "Description",
Expand Down
Loading