From 00108bb083095d91c96e5079972c00a894932567 Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Tue, 7 Apr 2026 13:18:47 +0200 Subject: [PATCH] refactor(api): add wishlists get controller --- index.php | 1 + src/assets/js/inline.js.php | 2 +- .../wishthis/PageControllerApiWishlists.php | 52 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/classes/wishthis/PageControllerApiWishlists.php diff --git a/index.php b/index.php index 1edf77b0..57e2655c 100644 --- a/index.php +++ b/index.php @@ -145,6 +145,7 @@ $router = new Router(); $router->get('/', [PageControllerHome::class, 'default']); $router->get('/api/blog', [PageControllerApiBlog::class, 'blog']); $router->get('/api/statistics/all', [PageControllerApiStatistics::class, 'all']); +$router->get('/api/wishlists', [PageControllerApiWishlists::class, 'get']); $router->get('/blog', [PageControllerBlog::class, 'default']); $router->get('/blog/post/(?.+)', [PageControllerBlogPost::class, 'default']); $router->get('/changelog', [PageControllerChangelog::class, 'default']); diff --git a/src/assets/js/inline.js.php b/src/assets/js/inline.js.php index b8270ea6..6b4c5e08 100644 --- a/src/assets/js/inline.js.php +++ b/src/assets/js/inline.js.php @@ -162,7 +162,7 @@ global $options, $locale; */ '/index.php?page=api&module=wishlists', + 'get wishlists' => '/api/wishlists', 'get wishes by wishlist id' => '/index.php?page=api&module=wishlists&style={style}&priority={priority}&wishlist_id={wishlistid}', 'get wishes by wishlist hash' => '/index.php?page=api&module=wishlists&style={style}&priority={priority}&wishlist_hash={wishlisthash}', 'delete wishlist' => '/index.php?page=api&module=wishlists', diff --git a/src/classes/wishthis/PageControllerApiWishlists.php b/src/classes/wishthis/PageControllerApiWishlists.php new file mode 100644 index 00000000..5d9cd12e --- /dev/null +++ b/src/classes/wishthis/PageControllerApiWishlists.php @@ -0,0 +1,52 @@ +pageTitle = 'API'; + + $this->wishlistId = $parameters['id']; + + parent::__construct(); + } + + public function get(): void + { + $user = User::getCurrent(); + + $wishlists = []; + $wishlistsItems = []; + + foreach ($user->getWishlists() as $wishlistData) { + $wishlist = new Wishlist($wishlistData); + $wishlistId = $wishlist->getId(); + $wishlistName = $wishlist->getName(); + + $wishlists[] = [ + 'id' => $wishlistId, + 'hash' => $wishlist->getHash(), + 'userId' => $wishlist->getUserId(), + ]; + $wishlistsItems[] = [ + 'name' => $wishlistName, + 'value' => $wishlistId, + 'text' => $wishlistName, + ]; + } + + $response['wishlists'] = $wishlists; + $response['wishlistsItems'] = $wishlistsItems; + + $response['warning'] = \ob_get_clean(); + $response['success'] = true; + + \header('Content-type: application/json; charset=utf-8'); + echo \json_encode($response); + }