src/ApiV3Bundle/Controller/AiCoachMasterDataController.php line 41

Open in your IDE?
  1. <?php
  2. namespace ApiV3Bundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  5. class AiCoachMasterDataController extends BaseController
  6. {
  7.     private $authenticator;
  8.     private $biz;
  9.     public function __construct($authenticator, $biz)
  10.     {
  11.         $this->authenticator = $authenticator;
  12.         $this->biz = $biz;
  13.     }
  14.     public function departmentAction(Request $request, $sourceId)
  15.     {
  16.         $claims = $this->authenticator->authenticate($request, 'master-data:projection');
  17.         return $this->response($this->service()->upsertDepartment(
  18.             (int) $claims['providerBindingId'],
  19.             $sourceId,
  20.             $this->body($request)
  21.         ));
  22.     }
  23.     public function positionGroupAction(Request $request, $sourceId)
  24.     {
  25.         $claims = $this->authenticator->authenticate($request, 'master-data:projection');
  26.         return $this->response($this->service()->upsertPositionGroup(
  27.             (int) $claims['providerBindingId'],
  28.             $sourceId,
  29.             $this->body($request)
  30.         ));
  31.     }
  32.     public function positionAction(Request $request, $sourceId)
  33.     {
  34.         $claims = $this->authenticator->authenticate($request, 'master-data:projection');
  35.         return $this->response($this->service()->upsertPosition(
  36.             (int) $claims['providerBindingId'],
  37.             $sourceId,
  38.             $this->body($request)
  39.         ));
  40.     }
  41.     public function userProjectionAction(Request $request, $externalId)
  42.     {
  43.         $claims = $this->authenticator->authenticate($request, 'user:projection');
  44.         return $this->response($this->service()->projectUser(
  45.             (int) $claims['providerBindingId'],
  46.             $externalId,
  47.             $this->body($request)
  48.         ));
  49.     }
  50.     private function body(Request $request)
  51.     {
  52.         $fields = json_decode((string) $request->getContent(), true);
  53.         if (!is_array($fields)) {
  54.             throw new BadRequestHttpException('Request body must be valid JSON');
  55.         }
  56.         return $fields;
  57.     }
  58.     private function response(array $mapping)
  59.     {
  60.         return $this->createJsonResponse([
  61.             'id' => (int) $mapping['targetId'],
  62.             'version' => (int) $mapping['version'],
  63.             'deleted' => !empty($mapping['deleted']),
  64.         ]);
  65.     }
  66.     private function service()
  67.     {
  68.         return $this->biz->service('CorporateTrainingBundle:AiCoachMasterData:AiCoachMasterDataService');
  69.     }
  70. }