-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBookmarkListController.php
More file actions
92 lines (83 loc) · 3.25 KB
/
Copy pathBookmarkListController.php
File metadata and controls
92 lines (83 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Rest\Server\Controller\Bookmark;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
use ApiPlatform\OpenApi\Model;
use Ibexa\Contracts\Core\Repository\BookmarkService;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values;
use Ibexa\Rest\Value as RestValue;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
#[Get(
uriTemplate: '/bookmark',
extraProperties: [OpenApiFactory::OVERRIDE_OPENAPI_RESPONSES => false],
openapi: new Model\Operation(
operationId: 'ibexa.rest.load_bookmarks',
summary: 'List of bookmarks',
description: 'Lists bookmarked Locations for the current user.',
tags: [
'Bookmark',
],
responses: [
Response::HTTP_OK => [
'description' => 'If set, the list is returned in XML or JSON format.',
'content' => [
'application/vnd.ibexa.api.BookmarkList+json' => [
'schema' => [
'$ref' => '#/components/schemas/BookmarkListWrapper',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/bookmark/GET/BookmarkList.json.example',
],
'application/vnd.ibexa.api.BookmarkList+xml' => [
'schema' => [
'$ref' => '#/components/schemas/BookmarkList',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/bookmark/GET/BookmarkList.xml.example',
],
],
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to list bookmarks.',
],
],
),
)]
class BookmarkListController extends RestController
{
protected BookmarkService $bookmarkService;
protected LocationService $locationService;
/**
* Bookmark constructor.
*/
public function __construct(BookmarkService $bookmarkService, LocationService $locationService)
{
$this->bookmarkService = $bookmarkService;
$this->locationService = $locationService;
}
/**
* List bookmarked locations.
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function loadBookmarks(Request $request): RestValue
{
$offset = $request->query->getInt('offset', 0);
$limit = $request->query->getInt('limit', 25);
$restLocations = [];
$bookmarks = $this->bookmarkService->loadBookmarks($offset, $limit);
foreach ($bookmarks as $bookmark) {
$restLocations[] = new Values\RestLocation(
$bookmark,
$this->locationService->getLocationChildCount($bookmark)
);
}
return new Values\BookmarkList($bookmarks->totalCount, $restLocations);
}
}