-
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.
Merge pull request #16 from amvid/feat/phone-codes-endpoint
feat: phone codes endpoint
- Loading branch information
Showing
11 changed files
with
168 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,4 @@ | |
"symfony/stopwatch": "6.3.*", | ||
"symfony/web-profiler-bundle": "6.3.*" | ||
} | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Country\Action\GetPhoneCodes; | ||
|
||
use App\Country\Repository\CountryRepositoryInterface; | ||
use App\Currency\Exception\CurrencyNotFoundException; | ||
use App\SubRegion\Exception\SubRegionNotFoundException; | ||
|
||
readonly class GetPhoneCodesAction implements GetPhoneCodesActionInterface | ||
{ | ||
public function __construct(private CountryRepositoryInterface $countryRepository) | ||
{ | ||
} | ||
|
||
/** | ||
* @throws CurrencyNotFoundException | ||
* @throws SubRegionNotFoundException | ||
*/ | ||
public function run(GetPhoneCodesActionRequest $request): GetPhoneCodesActionResponse | ||
{ | ||
return new GetPhoneCodesActionResponse( | ||
$this->countryRepository->findPhoneCodes( | ||
$request->offset, | ||
$request->limit, | ||
$request->title, | ||
$request->phoneCode, | ||
) | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Country/Action/GetPhoneCodes/GetPhoneCodesActionInterface.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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Country\Action\GetPhoneCodes; | ||
|
||
interface GetPhoneCodesActionInterface | ||
{ | ||
public function run(GetPhoneCodesActionRequest $request): GetPhoneCodesActionResponse; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Country/Action/GetPhoneCodes/GetPhoneCodesActionRequest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Country\Action\GetPhoneCodes; | ||
|
||
use App\Application\Controller\Request\LimitOffsetInterface; | ||
use App\Application\Controller\Request\LimitOffsetParser; | ||
use App\Application\Controller\Request\LimitOffsetRequestTrait; | ||
|
||
class GetPhoneCodesActionRequest implements LimitOffsetInterface | ||
{ | ||
use LimitOffsetRequestTrait; | ||
|
||
public ?string $title = null; | ||
public ?string $phoneCode = null; | ||
|
||
public static function fromArray(array $params): self | ||
{ | ||
/** @var GetPhoneCodesActionRequest $req */ | ||
$req = LimitOffsetParser::parse($params, new self()); | ||
|
||
$req->phoneCode = $params['phoneCode'] ?? null; | ||
$req->title = $params['title'] ?? null; | ||
|
||
return $req; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Country/Action/GetPhoneCodes/GetPhoneCodesActionResponse.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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Country\Action\GetPhoneCodes; | ||
|
||
use App\Country\Controller\Response\PhoneCodeResponse; | ||
use App\Country\Entity\Country; | ||
|
||
class GetPhoneCodesActionResponse | ||
{ | ||
/** @var array<PhoneCodeResponse> $response */ | ||
public array $response = []; | ||
|
||
/** | ||
* @param array<Country> $phoneCodes | ||
*/ | ||
public function __construct(array $phoneCodes) | ||
{ | ||
foreach ($phoneCodes as $phoneCode) { | ||
$this->response[] = new PhoneCodeResponse($phoneCode); | ||
} | ||
} | ||
} |
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
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
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
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Country\Controller\Response; | ||
|
||
use App\Country\Entity\Country; | ||
|
||
class PhoneCodeResponse | ||
{ | ||
public string $title; | ||
public string $iso2; | ||
public string $iso3; | ||
public string $phoneCode; | ||
public string $flag; | ||
|
||
public function __construct(Country $country) | ||
{ | ||
$this->title = $country->getTitle(); | ||
$this->iso2 = $country->getIso2(); | ||
$this->iso3 = $country->getIso3(); | ||
$this->phoneCode = $country->getPhoneCode(); | ||
$this->flag = $country->getFlag(); | ||
} | ||
} |
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
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