/** * 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) { $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->create(array('methods' => $record->getMethods(), 'path' => $record->getPath(), 'controller' => 'Fusio\\Impl\\Controller\\SchemaApiController', 'config' => $record->getConfig())); // get last insert id $routeId = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->getLastInsertId(); // insert dependency links $this->routesDependencyManager->insertDependencyLinks($routeId, $record->getConfig()); // lock dependencies $this->routesDependencyManager->lockExistingDependencies($routeId); return array('success' => true, 'message' => 'Route successful created'); }
/** * Returns the DELETE response * * @param \PSX\Data\RecordInterface $record * @param \PSX\Api\Version $version * @return array|\PSX\Data\RecordInterface */ protected function doDelete(RecordInterface $record, Version $version) { $routeId = (int) $this->getUriFragment('route_id'); $route = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->get($routeId); if (!empty($route)) { // check whether route has a production version if ($this->hasProductionVersion($route->getConfig())) { throw new StatusCode\ConflictException('It is not possible to delete a route which contains a production version'); } // remove all dependency links $this->routesDependencyManager->removeExistingDependencyLinks($route->getId()); // unlock dependencies $this->routesDependencyManager->unlockExistingDependencies($route->getId()); // remove all scope routes $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope\\Route')->deleteAllFromRoute($route->getId()); // delete route $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->delete(array('id' => $route->getId())); return array('success' => true, 'message' => 'Routes successful deleted'); } else { throw new StatusCode\NotFoundException('Could not find route'); } }