Last active
December 20, 2018 12:23
-
-
Save thiagomarini/229cd7d02aa50a7b269927d811f9fdcd to your computer and use it in GitHub Desktop.
Service Usage in Controller Example
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
<?php | |
/** | |
* Requests a call from the sales team | |
* | |
* @method PUT | |
* @param Request $request | |
* @param int $userId | |
* @param RequestPhoneCall\Service $requestCall | |
* | |
* @return Response | |
*/ | |
public function requestCall(Request $request, int $userId, RequestPhoneCall\Service $requestCall): Response | |
{ | |
try { | |
$payload = $request->json()->all(); | |
$responseData = $requestCall->execute( | |
new RequestPhoneCall\Request(['user_id' => $userId], $payload) | |
)->getData(); | |
Log::info('Request call successful', [ | |
'action' => __METHOD__, | |
'user_id' => $userId, | |
'phone' => $payload['phone'], | |
'description' => sprintf('Merchant: %s (%s) requested a call.', $responseData['user']['name'], $responseData['user']['id']) | |
]); | |
return $this->ok([ | |
'onboarding' => $responseData['onboarding'], | |
]); | |
} catch (ValidationException | BusinessException $e) { | |
Log::error('Request call failed', [ | |
'action' => __METHOD__, | |
'user_id' => $userId, | |
'error_message' => $e->getMessage() | |
]); | |
return $this->badRequest($e->getErrors()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment