forked from apoloz/alfa-bank-sdk
refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -1,28 +1,50 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the API call to retrieve a list of steps for a specific deal.
|
||||
// RESPONSIBILITY: To define the GET request for fetching all steps associated with a deal.
|
||||
// INPUTS: Deal ID, and optional pagination parameters.
|
||||
// OUTPUTS: A collection of StepData DTOs.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Requests\NominalAccounts\Deals\Steps;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import DTOs and Saloon components.">
|
||||
// <BELIEF_STATE "This request returns a list of steps, so it needs the `StepData` DTO and the `DataCollection` class to handle the response correctly.">
|
||||
use Apoloz\AlfaBank\Data\NominalAccounts\Deals\Steps\StepData;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the request to get all steps for a deal.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for fetching all steps related to a specific deal, supporting pagination.">
|
||||
class GetStepsRequest extends Request
|
||||
{
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "GET is the correct verb for retrieving a list of resources.">
|
||||
protected Method $method = Method::GET;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="constructor" intent="Inject the deal ID and optional pagination parameters.">
|
||||
// <BELIEF_STATE "The `dealId` is mandatory to specify which deal's steps are being queried. `limit` and `offset` provide pagination capabilities.">
|
||||
public function __construct(
|
||||
protected string $dealId,
|
||||
protected ?int $limit = 50,
|
||||
protected ?int $offset = 0
|
||||
) {}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Construct the request URI for the steps collection of a deal.">
|
||||
// <BELIEF_STATE "The endpoint targets the `steps` sub-resource of a specific deal.">
|
||||
public function resolveEndpoint(): string
|
||||
{
|
||||
return "/api/na/jp/v1/deals/{$this->dealId}/steps";
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="query_builder" intent="Construct the query string for pagination.">
|
||||
// <BELIEF_STATE "The `defaultQuery` method properly assigns the pagination parameters to the query string.">
|
||||
protected function defaultQuery(): array
|
||||
{
|
||||
return [
|
||||
@@ -30,9 +52,13 @@ class GetStepsRequest extends Request
|
||||
'offset' => $this->offset,
|
||||
];
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_caster" intent="Map the JSON array response to a collection of DTOs.">
|
||||
// <BELIEF_STATE "The API returns a JSON array. Using `StepData::collect` automatically converts this array into a type-safe, iterable `DataCollection` of `StepData` objects.">
|
||||
public function createDtoFromResponse(Response $response): DataCollection
|
||||
{
|
||||
return StepData::collect($response->json(), DataCollection::class);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user