Exemplo n.º 1
0
 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Check that user is authorized to view this resource
     $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'), 'view', 'users');
     //Validate input
     $inputValidator = v::key('id', v::intVal());
     $inputValidator->assert($input);
     //Get user from repository and transform into resource
     $user = $this->userRepository->getOneByIdOrFail($input['id']);
     $this->item->setData($user)->setTransformer($this->userTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($this->item)->toArray());
 }
Exemplo n.º 2
0
 /**
  * Handle domain logic for an action.
  *
  * @param array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Ensure that the use has permission to create shifts
     $user = $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity');
     $this->authorizeUser($user, 'create', 'shifts');
     //If no manager_id is specified in request, default to user creating shift
     if (!array_key_exists('manager_id', $input)) {
         $input['manager_id'] = $user->getId();
     }
     //Validate input
     $inputValidator = v::key('break', v::floatVal())->key('start_time', v::date())->key('end_time', v::date()->min($input['start_time']))->key('manager_id', v::intVal());
     $inputValidator->assert($input);
     //Execute command to create shift
     $shift = $this->commandBus->handle(new CreateShift($input['manager_id'], $input['employee_id'], $input['break'], $input['start_time'], $input['end_time']));
     $this->item->setData($shift)->setTransformer($this->shiftTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->item)->toArray());
 }