forked from apoloz/alfa-bank-sdk
50 lines
2.2 KiB
PHP
50 lines
2.2 KiB
PHP
<?php
|
|
/*
|
|
// MODULE_CONTRACT: Represents the API call to retrieve a single deal by its ID.
|
|
// RESPONSIBILITY: To define the GET request structure for fetching a specific deal's details.
|
|
// INPUTS: Deal ID (string).
|
|
// OUTPUTS: DealData (DTO).
|
|
*/
|
|
namespace Apoloz\AlfaBank\Requests\NominalAccounts\Deals;
|
|
|
|
// <SECTION name="module_imports" intent="Import DTO and Saloon components.">
|
|
// <BELIEF_STATE "This request needs the `DealData` DTO for its response and Saloon's base Request class.">
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Deals\DealData;
|
|
use Saloon\Enums\Method;
|
|
use Saloon\Http\Request;
|
|
use Saloon\Http\Response;
|
|
// </SECTION>
|
|
|
|
// <SECTION name="class_definition" intent="Define the request to get a single deal.">
|
|
// <BELIEF_STATE "A dedicated class encapsulates the logic for this specific API endpoint, promoting reusability and separation of concerns.">
|
|
class GetDealRequest extends Request
|
|
{
|
|
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
|
// <BELIEF_STATE "Fetching a resource by its identifier is a read-only operation, making GET the correct RESTful verb.">
|
|
protected Method $method = Method::GET;
|
|
// </SECTION>
|
|
|
|
// <SECTION name="constructor" intent="Inject the deal's unique identifier.">
|
|
// <BELIEF_STATE "The `dealId` is a mandatory path parameter for this endpoint, so it must be required in the constructor.">
|
|
public function __construct(
|
|
protected string $dealId
|
|
) {}
|
|
// </SECTION>
|
|
|
|
// <SECTION name="endpoint_resolver" intent="Construct the request URI with the dynamic deal ID.">
|
|
// <BELIEF_STATE "The endpoint is dynamic. Injecting the `dealId` into the URI is handled here to keep the endpoint definition clean and centralized within the request class.">
|
|
public function resolveEndpoint(): string
|
|
{
|
|
return "/api/na/jp/v1/deals/{$this->dealId}";
|
|
}
|
|
// </SECTION>
|
|
|
|
// <SECTION name="response_caster" intent="Map the JSON response to a DealData DTO.">
|
|
// <BELIEF_STATE "Automated casting to a DTO provides type safety and a clean object-oriented interface for the API response.">
|
|
public function createDtoFromResponse(Response $response): DealData
|
|
{
|
|
return DealData::from($response->json());
|
|
}
|
|
// </SECTION>
|
|
}
|