- $this->linkDb[$link['id']] = $link;
- $this->linkDb->save($this->conf->get('resource.page_cache'));
- $out = ApiUtils::formatLink($link, index_url($this->ci['environment']));
- $redirect = $this->ci->router->relativePathFor('getLink', ['id' => $link['id']]);
- return $response->withAddedHeader('Location', $redirect)
- ->withJson($out, 201, $this->jsonStyle);
+ $responseBookmark = $this->bookmarkService->get($id);
+ $responseBookmark = ApiUtils::updateLink($responseBookmark, $requestBookmark);
+ $this->bookmarkService->set($responseBookmark);
+
+ $out = ApiUtils::formatLink($responseBookmark, $index);
+ return $response->withJson($out, 200, $this->jsonStyle);
+ }
+
+ /**
+ * Delete an existing link by its ID.
+ *
+ * @param Request $request Slim request.
+ * @param Response $response Slim response.
+ * @param array $args Path parameters. including the ID.
+ *
+ * @return Response response.
+ *
+ * @throws ApiLinkNotFoundException generating a 404 error.
+ */
+ public function deleteLink($request, $response, $args)
+ {
+ $id = is_integer_mixed($args['id']) ? (int) $args['id'] : null;
+ if ($id === null || !$this->bookmarkService->exists($id)) {
+ throw new ApiLinkNotFoundException();
+ }
+ $bookmark = $this->bookmarkService->get($id);
+ $this->bookmarkService->remove($bookmark);
+
+ return $response->withStatus(204);