mirror of
https://github.com/wishthis/wishthis.git
synced 2026-05-19 12:25:48 -04:00
refactor(api): add wishlists get controller
This commit is contained in:
@@ -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/(?<slug>.+)', [PageControllerBlogPost::class, 'default']);
|
||||
$router->get('/changelog', [PageControllerChangelog::class, 'default']);
|
||||
|
||||
@@ -162,7 +162,7 @@ global $options, $locale;
|
||||
*/
|
||||
<?php
|
||||
$api_urls = [
|
||||
'get wishlists' => '/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',
|
||||
|
||||
52
src/classes/wishthis/PageControllerApiWishlists.php
Normal file
52
src/classes/wishthis/PageControllerApiWishlists.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace wishthis;
|
||||
|
||||
class PageControllerApiWishlists extends PageController
|
||||
{
|
||||
protected string $id = 'api-wishlists';
|
||||
|
||||
private int $wishlistId;
|
||||
|
||||
public function __construct(array $parameters = [])
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
Reference in New Issue
Block a user