Skip to content

Commit b760d57

Browse files
committed
WIP
1 parent bb0a995 commit b760d57

File tree

98 files changed

+1806
-52
lines changed

Some content is hidden

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

98 files changed

+1806
-52
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ $ticket = $ticketResponse->dto();
158158
#### List all tickets
159159

160160
```php
161-
use CodebarAg\Bexio\Requests\Contacts\FetchAListOfContacts;
161+
use CodebarAg\Bexio\Requests\Contacts\FetchAListOfContactsRequest;
162162
...
163163

164-
$listTicketResponse = $connector->send(new FetchAListOfContacts());
164+
$listTicketResponse = $connector->send(new FetchAListOfContactsRequest());
165165
$listTicketResponse->dto();
166166
````
167167

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\ContactAdditionalAddresses;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class ContactAdditionalAddressDTO extends Data
11+
{
12+
public function __construct(
13+
public int $id,
14+
public string $name,
15+
public string $subject,
16+
public string $description,
17+
public string $address,
18+
public string $postcode,
19+
public string $city,
20+
public ?int $country_id = null,
21+
) {
22+
}
23+
24+
public static function fromResponse(Response $response): self
25+
{
26+
if ($response->failed()) {
27+
throw new \Exception('Failed to get all tickets', $response->status());
28+
}
29+
30+
$data = $response->json();
31+
32+
return self::fromArray($data);
33+
}
34+
35+
public static function fromArray(array $data): self
36+
{
37+
if (! $data) {
38+
throw new Exception('Unable to create DTO. Data missing from response.');
39+
}
40+
41+
return new self(
42+
id: Arr::get($data, 'id'),
43+
name: Arr::get($data, 'name'),
44+
subject: Arr::get($data, 'subject'),
45+
description: Arr::get($data, 'description'),
46+
address: Arr::get($data, 'address'),
47+
postcode: Arr::get($data, 'postcode'),
48+
city: Arr::get($data, 'city'),
49+
country_id: Arr::get($data, 'country_id')
50+
);
51+
}
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\ContactAdditionalAddresses;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class CreateEditContactAdditionalAddressDTO extends Data
11+
{
12+
public function __construct(
13+
public string $name,
14+
public string $subject,
15+
public string $description,
16+
public string $address,
17+
public string $postcode,
18+
public string $city,
19+
public ?int $country_id = null,
20+
) {
21+
}
22+
23+
public static function fromResponse(Response $response): self
24+
{
25+
if ($response->failed()) {
26+
throw new \Exception('Failed to get all tickets', $response->status());
27+
}
28+
29+
$data = $response->json();
30+
31+
return self::fromArray($data);
32+
}
33+
34+
public static function fromArray(array $data): self
35+
{
36+
if (! $data) {
37+
throw new Exception('Unable to create DTO. Data missing from response.');
38+
}
39+
40+
return new self(
41+
name: Arr::get($data, 'name'),
42+
subject: Arr::get($data, 'subject'),
43+
description: Arr::get($data, 'description'),
44+
address: Arr::get($data, 'address'),
45+
postcode: Arr::get($data, 'postcode'),
46+
city: Arr::get($data, 'city'),
47+
country_id: Arr::get($data, 'country_id')
48+
);
49+
}
50+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\ContactGroups;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class ContactGroupDTO extends Data
11+
{
12+
public function __construct(
13+
public int $id,
14+
public string $name,
15+
) {
16+
}
17+
18+
public static function fromResponse(Response $response): self
19+
{
20+
if ($response->failed()) {
21+
throw new \Exception('Failed to get all tickets', $response->status());
22+
}
23+
24+
$data = $response->json();
25+
26+
return self::fromArray($data);
27+
}
28+
29+
public static function fromArray(array $data): self
30+
{
31+
if (! $data) {
32+
throw new Exception('Unable to create DTO. Data missing from response.');
33+
}
34+
35+
return new self(
36+
id: Arr::get($data, 'id'),
37+
name: Arr::get($data, 'name'),
38+
);
39+
}
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\ContactGroups;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class CreateEditContactGroupDTO extends Data
11+
{
12+
public function __construct(
13+
public string $name,
14+
) {
15+
}
16+
17+
public static function fromResponse(Response $response): self
18+
{
19+
if ($response->failed()) {
20+
throw new \Exception('Failed to get all tickets', $response->status());
21+
}
22+
23+
$data = $response->json();
24+
25+
return self::fromArray($data);
26+
}
27+
28+
public static function fromArray(array $data): self
29+
{
30+
if (! $data) {
31+
throw new Exception('Unable to create DTO. Data missing from response.');
32+
}
33+
34+
return new self(
35+
name: Arr::get($data, 'name'),
36+
);
37+
}
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\ContactRelations;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class ContactRelationDTO extends Data
11+
{
12+
public function __construct(
13+
public int $id,
14+
public int $contact_id,
15+
public int $contact_sub_id,
16+
public ?string $description,
17+
public ?string $updated_at,
18+
) {
19+
}
20+
21+
public static function fromResponse(Response $response): self
22+
{
23+
if ($response->failed()) {
24+
throw new \Exception('Failed to get all tickets', $response->status());
25+
}
26+
27+
$data = $response->json();
28+
29+
return self::fromArray($data);
30+
}
31+
32+
public static function fromArray(array $data): self
33+
{
34+
if (! $data) {
35+
throw new Exception('Unable to create DTO. Data missing from response.');
36+
}
37+
38+
return new self(
39+
id: Arr::get($data, 'id'),
40+
contact_id: Arr::get($data, 'contact_id'),
41+
contact_sub_id: Arr::get($data, 'contact_sub_id'),
42+
description: Arr::get($data, 'description'),
43+
updated_at: Arr::get($data, 'updated_at'),
44+
);
45+
}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\ContactRelations;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class CreateEditContactRelationDTO extends Data
11+
{
12+
public function __construct(
13+
public int $contact_id,
14+
public int $contact_sub_id,
15+
public ?string $description,
16+
) {
17+
}
18+
19+
public static function fromResponse(Response $response): self
20+
{
21+
if ($response->failed()) {
22+
throw new \Exception('Failed to get all tickets', $response->status());
23+
}
24+
25+
$data = $response->json();
26+
27+
return self::fromArray($data);
28+
}
29+
30+
public static function fromArray(array $data): self
31+
{
32+
if (! $data) {
33+
throw new Exception('Unable to create DTO. Data missing from response.');
34+
}
35+
36+
return new self(
37+
contact_id: Arr::get($data, 'contact_id'),
38+
contact_sub_id: Arr::get($data, 'contact_sub_id'),
39+
description: Arr::get($data, 'description'),
40+
);
41+
}
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto\ContactSectors;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class ContactSectorDTO extends Data
11+
{
12+
public function __construct(
13+
public int $id,
14+
public string $name,
15+
) {
16+
}
17+
18+
public static function fromResponse(Response $response): self
19+
{
20+
if ($response->failed()) {
21+
throw new \Exception('Failed to get all tickets', $response->status());
22+
}
23+
24+
$data = $response->json();
25+
26+
return self::fromArray($data);
27+
}
28+
29+
public static function fromArray(array $data): self
30+
{
31+
if (! $data) {
32+
throw new Exception('Unable to create DTO. Data missing from response.');
33+
}
34+
35+
return new self(
36+
id: Arr::get($data, 'id'),
37+
name: Arr::get($data, 'name'),
38+
);
39+
}
40+
}

src/Dto/ContactDTO.php renamed to src/Dto/Contacts/ContactDTO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace CodebarAg\Bexio\Dto;
3+
namespace CodebarAg\Bexio\Dto\Contacts;
44

55
use Exception;
66
use Illuminate\Support\Arr;

src/Dto/CreateEditContactDTO.php renamed to src/Dto/Contacts/CreateEditContactDTO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace CodebarAg\Bexio\Dto;
3+
namespace CodebarAg\Bexio\Dto\Contacts;
44

55
use Carbon\Carbon;
66
use Exception;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Requests\ContactAdditionalAddresses;
4+
5+
use CodebarAg\Bexio\Dto\ContactAdditionalAddresses\ContactAdditionalAddressDTO;
6+
use CodebarAg\Bexio\Dto\ContactAdditionalAddresses\CreateEditContactAdditionalAddressDTO;
7+
use Exception;
8+
use Saloon\Contracts\Body\HasBody;
9+
use Saloon\Enums\Method;
10+
use Saloon\Http\Request;
11+
use Saloon\Http\Response;
12+
use Saloon\Traits\Body\HasJsonBody;
13+
14+
class CreateContactAdditionalAddressRequest extends Request implements HasBody
15+
{
16+
use HasJsonBody;
17+
18+
protected Method $method = Method::POST;
19+
20+
public function __construct(
21+
readonly int $contactId,
22+
readonly protected array|CreateEditContactAdditionalAddressDTO $data,
23+
) {
24+
}
25+
26+
public function resolveEndpoint(): string
27+
{
28+
return '/contact/'.$this->contactId.'/additional_address';
29+
}
30+
31+
protected function defaultBody(): array
32+
{
33+
$body = $this->data;
34+
35+
if (! $body instanceof CreateEditContactAdditionalAddressDTO) {
36+
$body = CreateEditContactAdditionalAddressDTO::fromArray($body);
37+
}
38+
39+
return $body->toArray();
40+
}
41+
42+
public function createDtoFromResponse(Response $response): mixed
43+
{
44+
if (! $response->successful()) {
45+
throw new Exception('Request was not successful. Unable to create DTO.');
46+
}
47+
48+
return ContactAdditionalAddressDTO::fromArray($response->json());
49+
}
50+
}

0 commit comments

Comments
 (0)