ameliabooking
/
src
/
Application
/
Commands
/
User
/
Customer
/
UpdateCustomerStatusCommandHandler.php
AddCustomerCommand.php
7 years ago
AddCustomerCommandHandler.php
1 year ago
GetCustomerCommand.php
7 years ago
GetCustomerCommandHandler.php
1 year ago
GetCustomersCommand.php
7 years ago
GetCustomersCommandHandler.php
1 year ago
UpdateCustomerCommand.php
7 years ago
UpdateCustomerCommandHandler.php
1 year ago
UpdateCustomerStatusCommand.php
1 year ago
UpdateCustomerStatusCommandHandler.php
1 year ago
UpdateCustomerStatusCommandHandler.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\User\Customer; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | use AmeliaBooking\Application\Commands\CommandResult; |
| 7 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 8 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 9 | use AmeliaBooking\Infrastructure\Repository\User\ProviderRepository; |
| 10 | |
| 11 | /** |
| 12 | * Class UpdateCustomerStatusCommandHandler |
| 13 | * |
| 14 | * @package AmeliaBooking\Application\Common |
| 15 | */ |
| 16 | class UpdateCustomerStatusCommandHandler extends CommandHandler |
| 17 | { |
| 18 | /** |
| 19 | * @var array |
| 20 | */ |
| 21 | public $mandatoryFields = [ |
| 22 | 'status', |
| 23 | ]; |
| 24 | |
| 25 | /** |
| 26 | * @param UpdateCustomerStatusCommand $command |
| 27 | * |
| 28 | * @return CommandResult |
| 29 | * @throws \InvalidArgumentException |
| 30 | * @throws QueryExecutionException |
| 31 | * @throws InvalidArgumentException |
| 32 | */ |
| 33 | public function handle(UpdateCustomerStatusCommand $command) |
| 34 | { |
| 35 | $result = new CommandResult(); |
| 36 | |
| 37 | $this->checkMandatoryFields($command); |
| 38 | |
| 39 | /** @var ProviderRepository $providerRepository */ |
| 40 | $providerRepository = $this->container->get('domain.users.providers.repository'); |
| 41 | |
| 42 | $status = $command->getField('status'); |
| 43 | |
| 44 | $providerRepository->updateFieldById($command->getArg('id'), $status, 'status'); |
| 45 | |
| 46 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 47 | $result->setMessage('Successfully updated user'); |
| 48 | $result->setData(true); |
| 49 | |
| 50 | return $result; |
| 51 | } |
| 52 | } |
| 53 |