diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-24 14:16:07 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-24 14:16:07 +0300 |
| commit | 1bdf80397c19362c019cdd231e8813e251764370 (patch) | |
| tree | 126c1e0ffcc5664ac2b5883bec64007070411a9b /classes/Handler/GetinfoHandler.php | |
| parent | 1917ab77550613654620b6f5d4ad8570704246de (diff) | |
| download | the-epube-1bdf80397c19362c019cdd231e8813e251764370.tar.gz the-epube-1bdf80397c19362c019cdd231e8813e251764370.tar.xz | |
switch to PSR-4 router with namespaced handlers
Diffstat (limited to 'classes/Handler/GetinfoHandler.php')
| -rw-r--r-- | classes/Handler/GetinfoHandler.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/classes/Handler/GetinfoHandler.php b/classes/Handler/GetinfoHandler.php new file mode 100644 index 0000000..e599671 --- /dev/null +++ b/classes/Handler/GetinfoHandler.php @@ -0,0 +1,34 @@ +<?php + +namespace Handler; + +use Config; +use Request; +use RequestHandlerInterface; +use Response; +use PDO; + +class GetinfoHandler implements RequestHandlerInterface +{ + public function handle(Request $request): Response + { + $id = (int) $request->getAttribute('id'); + $caldb = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB)); + + $sth = $caldb->prepare("SELECT books.*, s.name AS series_name, + (SELECT text FROM comments WHERE book = books.id) AS comment, + (SELECT id FROM data WHERE book = books.id AND format = 'EPUB' LIMIT 1) AS epub_id FROM books + LEFT JOIN books_series_link AS bsl ON (bsl.book = books.id) + LEFT JOIN series AS s ON (bsl.series = s.id) + WHERE books.id = ?"); + $sth->execute([$id]); + + if ($row = $sth->fetch()) { + return (new Response())->withBody(json_encode($row)); + } + + return (new Response()) + ->withStatus(404) + ->withBody("Not found."); + } +} |
