-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query warehouses & storage locations
- Loading branch information
Showing
10 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Modules/Warehouse/DataTransferObjects/StorageLocationDto.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse\DataTransferObjects; | ||
|
||
use DREID\LaravelJtlApi\Services\DataTransferObjectService; | ||
|
||
readonly class StorageLocationDto | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public int $warehouseId, | ||
public string $name, | ||
public ?int $sortNumber, | ||
public ?int $priority, | ||
public bool $lockForShipment, | ||
public bool $lockForAvailability, | ||
public ?string $comment, | ||
) {} | ||
|
||
public static function fromResponse(array $data): static | ||
{ | ||
$service = app(DataTransferObjectService::class); | ||
|
||
return new self( | ||
$data['Id'], | ||
$data['WarehouseId'], | ||
$data['Name'], | ||
$service->getArrayValue($data, 'SortNumber'), | ||
$service->getArrayValue($data, 'Priority'), | ||
$service->getArrayValue($data, 'LockForShipment'), | ||
$service->getArrayValue($data, 'LockForAvailability'), | ||
$service->getArrayValue($data, 'Comment'), | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Modules/Warehouse/DataTransferObjects/WarehouseDto.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse\DataTransferObjects; | ||
|
||
readonly class WarehouseDto | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $name, | ||
public ?string $code, | ||
public ?string $description, | ||
public ?int $priority, | ||
public ?int $companyId, | ||
public bool $lockForShipment, | ||
public bool $lockForAvailability, | ||
public bool $isActive, | ||
) {} | ||
|
||
public static function fromResponse(array $data): static | ||
{ | ||
return new self( | ||
$data['Id'], | ||
$data['Name'], | ||
$data['Code'] ?? null, | ||
$data['Description'] ?? null, | ||
$data['Priority'] ?? null, | ||
$data['CompanyId'] ?? null, | ||
$data['LockForShipment'], | ||
$data['LockForAvailability'], | ||
$data['IsActive'], | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Modules/Warehouse/Requests/QueryStorageLocationsRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse\Requests; | ||
|
||
readonly class QueryStorageLocationsRequest | ||
{ | ||
public function __construct( | ||
public int $warehouseId, | ||
public ?int $pageNumber = null, | ||
public ?int $pageSize = null, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse\Requests; | ||
|
||
readonly class QueryWarehousesRequest | ||
{ | ||
public function __construct( | ||
public ?int $pageNumber = null, | ||
public ?int $pageSize = null, | ||
public ?bool $isActive = null, | ||
) {} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Modules/Warehouse/Responses/QueryStorageLocationsResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse\Responses; | ||
|
||
use DREID\LaravelJtlApi\ApiResponse; | ||
use DREID\LaravelJtlApi\Modules\Warehouse\DataTransferObjects\StorageLocationDto; | ||
use DREID\LaravelJtlApi\PaginatedResponse; | ||
|
||
readonly class QueryStorageLocationsResponse extends PaginatedResponse | ||
{ | ||
public function __construct(ApiResponse $response) | ||
{ | ||
parent::__construct($response, array_map(static function ($item) { | ||
return StorageLocationDto::fromResponse($item); | ||
}, $response->json['Items'])); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Modules/Warehouse/Responses/QueryWarehousesResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse\Responses; | ||
|
||
use DREID\LaravelJtlApi\ApiResponse; | ||
use DREID\LaravelJtlApi\Modules\Warehouse\DataTransferObjects\WarehouseDto; | ||
use DREID\LaravelJtlApi\PaginatedResponse; | ||
|
||
readonly class QueryWarehousesResponse extends PaginatedResponse | ||
{ | ||
public function __construct(ApiResponse $response) | ||
{ | ||
parent::__construct($response, array_map(static function ($item) { | ||
return WarehouseDto::fromResponse($item); | ||
}, $response->json['Items'])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse; | ||
|
||
use DREID\LaravelJtlApi\Enums\Permission; | ||
use DREID\LaravelJtlApi\Exceptions\ConnectionException; | ||
use DREID\LaravelJtlApi\Exceptions\MissingApiKeyException; | ||
use DREID\LaravelJtlApi\Exceptions\MissingLicenseException; | ||
use DREID\LaravelJtlApi\Exceptions\MissingPermissionException; | ||
use DREID\LaravelJtlApi\Exceptions\UnauthorizedException; | ||
use DREID\LaravelJtlApi\Exceptions\UnhandledResponseException; | ||
use DREID\LaravelJtlApi\Modules\Warehouse\Requests\QueryStorageLocationsRequest; | ||
use DREID\LaravelJtlApi\Modules\Warehouse\Responses\QueryStorageLocationsResponse; | ||
use DREID\LaravelJtlApi\Repository; | ||
|
||
class StorageLocationRepository extends Repository | ||
{ | ||
/** | ||
* @throws MissingApiKeyException | ||
* @throws MissingLicenseException | ||
* @throws MissingPermissionException | ||
* @throws UnauthorizedException | ||
* @throws UnhandledResponseException | ||
* @throws ConnectionException | ||
*/ | ||
public function queryStorageLocations(QueryStorageLocationsRequest $request): QueryStorageLocationsResponse | ||
{ | ||
$permissions = [Permission::AllRead, Permission::QueryStorageLocations]; | ||
|
||
if (!Permission::allowsOneOf($permissions)) { | ||
throw MissingPermissionException::oneOf($permissions); | ||
} | ||
|
||
$response = $this->get('/v1/warehouses/' . $request->warehouseId . '/storagelocations', [ | ||
'pageNumber' => $request->pageNumber, | ||
'pageSize' => $request->pageSize, | ||
]); | ||
|
||
if ($response->wasSuccessful) { | ||
return new QueryStorageLocationsResponse($response); | ||
} | ||
|
||
$this->throwExceptionsIfPossible($response); | ||
throw new UnhandledResponseException($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace DREID\LaravelJtlApi\Modules\Warehouse; | ||
|
||
use DREID\LaravelJtlApi\Enums\Permission; | ||
use DREID\LaravelJtlApi\Exceptions\ConnectionException; | ||
use DREID\LaravelJtlApi\Exceptions\MissingApiKeyException; | ||
use DREID\LaravelJtlApi\Exceptions\MissingLicenseException; | ||
use DREID\LaravelJtlApi\Exceptions\MissingPermissionException; | ||
use DREID\LaravelJtlApi\Exceptions\UnauthorizedException; | ||
use DREID\LaravelJtlApi\Exceptions\UnhandledResponseException; | ||
use DREID\LaravelJtlApi\Modules\Warehouse\Requests\QueryWarehousesRequest; | ||
use DREID\LaravelJtlApi\Modules\Warehouse\Responses\QueryWarehousesResponse; | ||
use DREID\LaravelJtlApi\Repository; | ||
|
||
class WarehouseRepository extends Repository | ||
{ | ||
/** | ||
* @throws MissingApiKeyException | ||
* @throws MissingLicenseException | ||
* @throws MissingPermissionException | ||
* @throws UnauthorizedException | ||
* @throws UnhandledResponseException | ||
* @throws ConnectionException | ||
*/ | ||
public function queryWarehouses(QueryWarehousesRequest $request): QueryWarehousesResponse | ||
{ | ||
$permissions = [Permission::AllRead, Permission::QueryWarehouses]; | ||
|
||
if (!Permission::allowsOneOf($permissions)) { | ||
throw MissingPermissionException::oneOf($permissions); | ||
} | ||
|
||
$response = $this->get('/v1/warehouses', [ | ||
'isActive' => $request->isActive, | ||
'pageNumber' => $request->pageNumber, | ||
'pageSize' => $request->pageSize, | ||
]); | ||
|
||
if ($response->wasSuccessful) { | ||
return new QueryWarehousesResponse($response); | ||
} | ||
|
||
$this->throwExceptionsIfPossible($response); | ||
throw new UnhandledResponseException($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters