From d9e928b1eb7b1aba2ed12f05c14cac377b323d93 Mon Sep 17 00:00:00 2001 From: Made Mas Adi Winata Date: Thu, 12 Sep 2024 12:29:18 +0700 Subject: [PATCH 1/3] make service command add response dto --- src/Commands/ServiceMakeCommand.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Commands/ServiceMakeCommand.php b/src/Commands/ServiceMakeCommand.php index 4d91b12..cb07b19 100644 --- a/src/Commands/ServiceMakeCommand.php +++ b/src/Commands/ServiceMakeCommand.php @@ -49,6 +49,31 @@ class ServiceMakeCommand extends GeneratorCommand * @var string */ protected $type = 'Service'; + /** + * Execute the console command. + * + * @return void + */ + public function handle() + { + parent::handle(); + $this->createResponseDto(); + } + /** + * Create a unit test file. + * + * @return void + */ + protected function createResponseDto() + { + $className = class_basename($this->argument('name')); + $this->call( + 'make:response_dto', + [ + 'name' => $className + ] + ); + } /** * Get the destination class path. * From 42570885b95ee267022bfcd70fd50fbd5e30cb93 Mon Sep 17 00:00:00 2001 From: Made Mas Adi Winata Date: Thu, 12 Sep 2024 12:47:11 +0700 Subject: [PATCH 2/3] enhance make service stub --- src/Commands/stubs/service.plain.stub | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Commands/stubs/service.plain.stub b/src/Commands/stubs/service.plain.stub index 8d55654..70ec462 100644 --- a/src/Commands/stubs/service.plain.stub +++ b/src/Commands/stubs/service.plain.stub @@ -37,4 +37,27 @@ class DummyClassService { $this->rest_client = $restClient; } + + public function dummyUrlCall(array $requestDto): DummyClassResponse + { + $clientResponse = $this->rest_client->call( + $requestDto, + 'http://dummy-microservice.com', + '/v1/dummyEndpoint' + ); + if (!isset($clientResponse->responseCode) || $clientResponse->responseCode <> '00') { + throw StdException::create( + $clientResponse->responseCode, + $clientResponse->responseDesc ?? 'Unknown response from host role' + ); + } + $dummyData = new DummyClass(isset($clientResponse->responseData) ? (array) $clientResponse->responseData : []); + $dummyResponse = new DummyClassResponse( + $clientResponse->responseCode, + $clientResponse->responseDesc, + $dummyData + ); + + return $dummyResponse; + } } From e73a62f4661c95101542fcd7cf0f9c4bca17218c Mon Sep 17 00:00:00 2001 From: Made Mas Adi Winata Date: Thu, 12 Sep 2024 12:56:09 +0700 Subject: [PATCH 3/3] fix missing import Dtos class --- src/Commands/stubs/service.plain.stub | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commands/stubs/service.plain.stub b/src/Commands/stubs/service.plain.stub index 70ec462..a265cfa 100644 --- a/src/Commands/stubs/service.plain.stub +++ b/src/Commands/stubs/service.plain.stub @@ -18,6 +18,8 @@ namespace App\Services; use App\Library\RestClient; use Spotlibs\PhpLib\Exceptions\StdException; use Spotlibs\PhpLib\Exceptions\ThirdPartyServiceException; +use App\Models\Dtos\DummyClassResponse; +use App\Models\Dtos\DummyClass; /** * DummyClassService