AddCustomerController.php
1 month ago
GetCustomerController.php
1 month ago
GetCustomersController.php
1 month ago
ReauthorizeController.php
1 month ago
UpdateCustomerController.php
1 month ago
UpdateCustomerNoteController.php
1 month ago
UpdateCustomerStatusController.php
1 month ago
UpdateCustomerNoteController.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Controller\User\Customer; |
| 4 | |
| 5 | use AmeliaBooking\Application\Commands\User\Customer\UpdateCustomerNoteCommand; |
| 6 | use AmeliaBooking\Application\Commands\CommandResult; |
| 7 | use AmeliaBooking\Application\Controller\Controller; |
| 8 | use AmeliaBooking\Domain\Events\DomainEventBus; |
| 9 | use AmeliaVendor\Psr\Http\Message\ServerRequestInterface as Request; |
| 10 | |
| 11 | /** |
| 12 | * Class UpdateCustomerNoteController |
| 13 | * |
| 14 | * @package AmeliaBooking\Application\Controller\User\Customer |
| 15 | */ |
| 16 | class UpdateCustomerNoteController extends Controller |
| 17 | { |
| 18 | /** |
| 19 | * Fields allowed from the front-end for this endpoint |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | protected $allowedFields = [ |
| 24 | 'note', |
| 25 | ]; |
| 26 | |
| 27 | /** |
| 28 | * @param Request $request |
| 29 | * @param $args |
| 30 | * |
| 31 | * @return UpdateCustomerNoteCommand |
| 32 | * @throws \RuntimeException |
| 33 | */ |
| 34 | protected function instantiateCommand(Request $request, $args) |
| 35 | { |
| 36 | $command = new UpdateCustomerNoteCommand($args); |
| 37 | |
| 38 | $requestBody = $request->getParsedBody(); |
| 39 | $this->setCommandFields($command, $requestBody); |
| 40 | $command->setField('id', $args['id']); |
| 41 | $command->setToken($request); |
| 42 | |
| 43 | $params = (array)$request->getQueryParams(); |
| 44 | |
| 45 | if (isset($params['source'])) { |
| 46 | $command->setPage($params['source']); |
| 47 | } |
| 48 | |
| 49 | return $command; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param DomainEventBus $eventBus |
| 54 | * @param CommandResult $result |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | protected function emitSuccessEvent(DomainEventBus $eventBus, CommandResult $result) |
| 59 | { |
| 60 | if ($result->getResult() === CommandResult::RESULT_SUCCESS) { |
| 61 | $eventBus->emit('user.updated', $result); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 |