Skip to content

Commit

Permalink
feat(Contexts): API endpoint to update basic information of a Context
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz authored and juliusknorr committed Mar 6, 2024
1 parent cb2eaf0 commit ba90263
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
['name' => 'Context#index', 'url' => '/api/2/contexts', 'verb' => 'GET'],
['name' => 'Context#show', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'GET'],
['name' => 'Context#create', 'url' => '/api/2/contexts', 'verb' => 'POST'],
['name' => 'Context#update', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'PUT'],
['name' => 'Context#addNode', 'url' => '/api/2/contexts/{contextId}/nodes', 'verb' => 'POST'],
['name' => 'Context#removeNode', 'url' => '/api/2/contexts/{contextId}/nodes/{nodeRelId}', 'verb' => 'DELETE'],

Expand Down
14 changes: 14 additions & 0 deletions lib/Controller/ContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ public function create(string $name, string $iconName, string $description = '',
}
}

/**
* @NoAdminRequired
* @CanManageContext
*/
public function update(int $contextId, ?string $name, ?string $iconName, ?string $description): DataResponse {
try {
return new DataResponse($this->contextService->update($contextId, $name, $iconName, $description)->jsonSerialize());
} catch (Exception|MultipleObjectsReturnedException $e) {
return $this->handleError($e);
} catch (DoesNotExistException $e) {
return $this->handleNotFoundError(new NotFoundError($e->getMessage(), $e->getCode(), $e));
}
}

/**
* @NoAdminRequired
* @CanManageNode
Expand Down
21 changes: 21 additions & 0 deletions lib/Service/ContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ public function create(string $name, string $iconName, string $description, arra
return $context;
}

/**
* @throws Exception
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function update(int $contextId, ?string $name, ?string $iconName, ?string $description): Context {
$context = $this->contextMapper->findById($contextId);

if ($name !== null) {
$context->setName(trim($name));
}
if ($iconName !== null) {
$context->setIcon(trim($iconName));
}
if ($description !== null) {
$context->setDescription(trim($description));
}

return $this->contextMapper->update($context);
}

/**
* @throws MultipleObjectsReturnedException
* @throws DoesNotExistException
Expand Down

0 comments on commit ba90263

Please sign in to comment.