public function destroy(Request $request)
 {
     $partId = PartId::fromString($request->get('partId'));
     $command = new RemovePartCommand($partId);
     $this->commandBus->dispatch($command);
     return Redirect::route('parts.index')->with('success', 'Part successfully deleted.');
 }
 /**
  * @Route("/", methods={"POST"})
  * @param CreateExpenseList $createExpenseList
  * @return JsonResponse|Response
  */
 public function createAction(CreateExpenseList $createExpenseList)
 {
     $violations = $this->validator->validate($createExpenseList);
     if (count($violations) > 0) {
         return new Response(null, Response::HTTP_BAD_REQUEST);
     }
     $id = (string) Uuid::uuid4();
     $this->commandBus->dispatch(new CreateExpenseListCommand($id, $createExpenseList->name, $this->accountId));
     return new JsonResponse(['id' => $id], Response::HTTP_CREATED);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function send($command, Callback $callback = null)
 {
     $retry = new RetryCallback($this->commandBus, $command, $this->scheduler, $callback);
     try {
         $this->commandBus->dispatch($command);
     } catch (Exception $e) {
         return $retry->onFailure($e);
     }
     return $retry->onSuccess();
 }
Esempio n. 4
0
 /**
  * Applies a web command to the domain
  *
  * @param CommandInterface $web_command
  * @throws \LogicException
  * @throws CannotApplyWebCommand
  */
 public function apply(CommandInterface $web_command)
 {
     if (!$web_command instanceof WebCommandInterface) {
         throw new \LogicException('Given command must implement WebCommandInterface');
     }
     try {
         $domainCommand = $this->toDomainCommand($web_command);
         $this->commandBus->dispatch($domainCommand);
     } catch (DomainException $exception) {
         throw new CannotApplyWebCommand($exception->getMessage());
     }
 }
Esempio n. 5
0
 /**
  * @param $command
  */
 private function handleCommand($command)
 {
     try {
         $this->commandBus->dispatch($command);
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage());
     }
 }
 /**
  * @param $command
  */
 private function handleCommand($command)
 {
     try {
         $this->commandBus->dispatch($command);
     } catch (\Exception $e) {
         throw new \Exception("Municipality config could not be found or created");
     }
 }
 function it_creates_a_new_expense_list(CommandBusInterface $commandBus)
 {
     $createExpenseList = new CreateExpenseList();
     $createExpenseList->name = 'Home';
     $commandBus->dispatch(Argument::type(CreateExpenseListCommand::class))->shouldBeCalled();
     /** @var Response $response */
     $response = $this->createAction($createExpenseList);
     $response->getStatusCode()->shouldBe(201);
 }