From 9e638c32b8414cb489ca8bf36f8dee2c3030ee0d Mon Sep 17 00:00:00 2001 From: matthieu Date: Sun, 15 Mar 2026 18:10:47 +0100 Subject: [PATCH] feat(bookstack) : add BookStackSearchResult API resource for shelf-scoped search Co-Authored-By: Claude Sonnet 4.6 --- src/ApiResource/BookStackSearchResult.php | 35 ++++++++++++ src/State/BookStackSearchResultProvider.php | 62 +++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/ApiResource/BookStackSearchResult.php create mode 100644 src/State/BookStackSearchResultProvider.php diff --git a/src/ApiResource/BookStackSearchResult.php b/src/ApiResource/BookStackSearchResult.php new file mode 100644 index 0000000..f52a50c --- /dev/null +++ b/src/ApiResource/BookStackSearchResult.php @@ -0,0 +1,35 @@ + ['bookstack_search:read']], + provider: BookStackSearchResultProvider::class, + security: "is_granted('IS_AUTHENTICATED_FULLY')", + ), + ], +)] +final class BookStackSearchResult +{ + #[Groups(['bookstack_search:read'])] + public int $id = 0; + + #[Groups(['bookstack_search:read'])] + public string $type = ''; + + #[Groups(['bookstack_search:read'])] + public string $name = ''; + + #[Groups(['bookstack_search:read'])] + public string $url = ''; +} diff --git a/src/State/BookStackSearchResultProvider.php b/src/State/BookStackSearchResultProvider.php new file mode 100644 index 0000000..d7bb95b --- /dev/null +++ b/src/State/BookStackSearchResultProvider.php @@ -0,0 +1,62 @@ +em->getRepository(Task::class)->find($taskId); + + if (null === $task || null === $task->getProject()) { + return []; + } + + $shelfId = $task->getProject()->getBookstackShelfId(); + if (null === $shelfId) { + return []; + } + + $request = $this->requestStack->getCurrentRequest(); + $query = $request?->query->get('q', '') ?? ''; + + if ('' === trim($query)) { + return []; + } + + try { + $results = $this->bookStackApiService->searchInShelf($shelfId, $query); + } catch (BookStackApiException $e) { + throw new BadRequestHttpException($e->getMessage(), $e); + } + + return array_map(static function (array $item): BookStackSearchResult { + $dto = new BookStackSearchResult(); + $dto->id = $item['id']; + $dto->type = $item['type']; + $dto->name = $item['name']; + $dto->url = $item['url']; + + return $dto; + }, $results); + } +}