refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
<?php
|
||||
/*
|
||||
// MODULE_CONTRACT: Represents the API call to retrieve a list of universal recipients.
|
||||
// RESPONSIBILITY: To define the GET request for fetching a filtered, paginated list of universal recipients.
|
||||
// INPUTS: Account number, type, and various optional filters.
|
||||
// OUTPUTS: A collection of UniversalRecipientData DTOs.
|
||||
*/
|
||||
|
||||
namespace Apoloz\AlfaBank\Requests\NominalAccounts\UniversalRecipients;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import DTOs and Saloon components.">
|
||||
// <BELIEF_STATE "This request returns a collection of `UniversalRecipientData` DTOs.">
|
||||
use Apoloz\AlfaBank\Data\NominalAccounts\UniversalRecipients\UniversalRecipientData;
|
||||
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 a list of universal recipients.">
|
||||
// <BELIEF_STATE "This class encapsulates a complex query with multiple optional filters, simplifying its use.">
|
||||
class GetUniversalRecipientsRequest extends Request
|
||||
{
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "GET is the correct verb for retrieving a collection of resources.">
|
||||
protected Method $method = Method::GET;
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="constructor" intent="Inject required filters and optional pagination parameters.">
|
||||
// <BELIEF_STATE "The `accountNumber` and `type` are mandatory filters. Other fields are optional filters or pagination parameters, allowing for flexible querying.">
|
||||
public function __construct(
|
||||
protected string $accountNumber,
|
||||
protected string $type,
|
||||
@@ -20,12 +36,18 @@ class GetUniversalRecipientsRequest extends Request
|
||||
protected ?bool $isActive = null,
|
||||
protected ?string $date = null,
|
||||
) {}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="endpoint_resolver" intent="Define the URI for the universal recipients collection.">
|
||||
// <BELIEF_STATE "The endpoint is the static collection URI; all filters are applied via query parameters.">
|
||||
public function resolveEndpoint(): string
|
||||
{
|
||||
return '/api/na/jp/v1/universal-recipients';
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="query_builder" intent="Construct the query string from the provided filters.">
|
||||
// <BELIEF_STATE "Using `array_filter` is a robust way to build the query array, as it automatically omits any optional parameters that were not provided (i.e., are `null`), resulting in a clean URL.">
|
||||
protected function defaultQuery(): array
|
||||
{
|
||||
return array_filter([
|
||||
@@ -37,9 +59,13 @@ class GetUniversalRecipientsRequest extends Request
|
||||
'date' => $this->date,
|
||||
], fn($val) => $val !== null);
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_caster" intent="Map the JSON response to a collection DTO.">
|
||||
// <BELIEF_STATE "Casting the response to a `DataCollection` of `UniversalRecipientData` provides a type-safe, iterable object. The specific API response structure requires extracting from the `universalRecipients` key.">
|
||||
public function createDtoFromResponse(Response $response): DataCollection
|
||||
{
|
||||
return UniversalRecipientData::collect($response->json('universalRecipients'), DataCollection::class);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user