/** * Returns the POST response * * @param \PSX\Data\RecordInterface $record * @param \PSX\Api\Version $version * @return array|\PSX\Data\RecordInterface */ protected function doCreate(RecordInterface $record, Version $version) { $scopeTable = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope'); $scopeTable->create(array('name' => $record->getName())); // insert routes $scopeId = $scopeTable->getLastInsertId(); $this->insertRoutes($scopeId, $record->getRoutes()); return array('success' => true, 'message' => 'Scope successful created'); }
/** * Returns the PUT response * * @param \PSX\Data\RecordInterface $record * @param \PSX\Api\Version $version * @return array|\PSX\Data\RecordInterface */ protected function doUpdate(RecordInterface $record, Version $version) { $scopeId = (int) $this->getUriFragment('scope_id'); $scope = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope')->get($scopeId); if (!empty($scope)) { $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope')->update(array('id' => $scope['id'], 'name' => $record->getName())); $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope\\Route')->deleteAllFromScope($record->getId()); $this->insertRoutes($record->getId(), $record->getRoutes()); return array('success' => true, 'message' => 'Scope successful updated'); } else { throw new StatusCode\NotFoundException('Could not find scope'); } }