Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create and enhance make service command #16

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Commands/ServiceMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
25 changes: 25 additions & 0 deletions src/Commands/stubs/service.plain.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,4 +39,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;
}
}
Loading