Skip to content

Commit

Permalink
Add conditions on endpoints for testing parameters and headers
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Dec 19, 2024
1 parent 75760f5 commit 59fee5e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The OpenConnector Nextcloud app provides a ESB-framework to work together in an
- 🆓 Map and translate API calls
]]></description>
<version>0.1.26</version>
<version>0.1.27</version>
<licence>agpl</licence>
<category>integration</category>
<author mail="[email protected]" homepage="https://www.conduction.nl/">Conduction</author>
Expand Down
7 changes: 4 additions & 3 deletions lib/Db/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Endpoint extends Entity implements JsonSerializable
protected ?string $method = null; // One of GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD. method and endpoint combination should be unique
protected ?string $targetType = null; // The target to attach this endpoint to, should be one of source (to create a proxy endpoint) or register/schema (to create an object endpoint) or job (to fire an event) or synchronization (to create a synchronization endpoint)
protected ?string $targetId = null; // The target id to attach this endpoint to

protected array $conditions = [];
protected ?DateTime $created = null;
protected ?DateTime $updated = null;

Expand All @@ -34,9 +36,7 @@ public function __construct() {
$this->addType(fieldName:'method', type: 'string');
$this->addType(fieldName:'targetType', type: 'string');
$this->addType(fieldName:'targetId', type: 'string');
$this->addType(fieldName:'schema', type: 'int');
$this->addType(fieldName:'register', type: 'int');
$this->addType(fieldName:'source', type: 'int');
$this->addType(fieldName:'conditions', type: 'json');
$this->addType(fieldName:'created', type: 'datetime');
$this->addType(fieldName:'updated', type: 'datetime');
}
Expand Down Expand Up @@ -86,6 +86,7 @@ public function jsonSerialize(): array
'method' => $this->method,
'targetType' => $this->targetType,
'targetId' => $this->targetId,
'conditions' => $this->conditions,
'created' => isset($this->created) ? $this->created->format('c') : null,
'updated' => isset($this->updated) ? $this->updated->format('c') : null,

Expand Down
6 changes: 5 additions & 1 deletion lib/Migration/Version1Date20241218122932.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
if($schema->hasTable(tableName: 'openconnector_consumers') === true) {
$table = $schema->getTable(tableName: 'openconnector_consumers');
$table->addColumn('authorization_configuration', Types::JSON);
$table->addColumn('user_id', Types::STRING);
$table->addColumn('user_id', Types::STRING)->setNotnull(false);
}
if($schema->hasTable(tableName: 'openconnector_endpoints') === true) {
$table = $schema->getTable(tableName: 'openconnector_endpoints');
$table->addColumn('conditions', Types::JSON);
}

return $schema;
Expand Down
4 changes: 3 additions & 1 deletion lib/Service/EndpointService.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ private function handleSchemaRequest(Endpoint $endpoint, IRequest $request, stri

$status = 200;

$headers = $request->getHeader('Accept-Crs') === '' ? [] : ['Content-Crs' => $request->getHeader('Accept-Crs')];

// Route to appropriate ObjectService method based on HTTP method
return match ($method) {
'GET' => new JSONResponse(
$this->getObjects(mapper: $mapper, parameters: $parameters, pathParams: $pathParams, status: $status), statusCode: $status
$this->getObjects(mapper: $mapper, parameters: $parameters, pathParams: $pathParams, status: $status), statusCode: $status, headers: $headers
),
'POST' => new JSONResponse(
$mapper->createFromArray(object: $parameters)
Expand Down

0 comments on commit 59fee5e

Please sign in to comment.