-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBookmarkIsBookmarkedController.php
More file actions
117 lines (108 loc) · 3.69 KB
/
Copy pathBookmarkIsBookmarkedController.php
File metadata and controls
117 lines (108 loc) · 3.69 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?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\Model;
use Ibexa\Bundle\Rest\ApiPlatform\Head;
use Ibexa\Contracts\Core\Repository\BookmarkService;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values;
use Symfony\Component\HttpFoundation\Response;
#[Head(
uriTemplate: '/bookmark/{locationId}',
openapi: new Model\Operation(
operationId: 'ibexa.rest.is_bookmarked.head',
summary: 'Check if Location is bookmarked',
description: 'Checks if the given Location is bookmarked by the current user.',
tags: [
'Bookmark',
],
parameters: [
new Model\Parameter(
name: 'locationId',
in: 'path',
required: true,
schema: [
'type' => 'integer',
],
),
],
responses: [
Response::HTTP_OK => [
'description' => 'OK - the given Location is bookmarked.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized for the given Location.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the given Location is not bookmarked or does not exist.',
],
],
),
)]
#[Get(
uriTemplate: '/bookmark/{locationId}',
openapi: new Model\Operation(
operationId: 'ibexa.rest.is_bookmarked.get',
summary: 'Check if Location is bookmarked',
description: 'Checks if the given Location is bookmarked by the current user.',
tags: [
'Bookmark',
],
parameters: [
new Model\Parameter(
name: 'locationId',
in: 'path',
required: true,
schema: [
'type' => 'integer',
],
),
],
responses: [
Response::HTTP_OK => [
'description' => 'OK - the given Location is bookmarked.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized for the given Location.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the given Location is not bookmarked or does not exist.',
],
],
),
)]
class BookmarkIsBookmarkedController extends RestController
{
protected BookmarkService $bookmarkService;
protected LocationService $locationService;
/**
* Bookmark constructor.
*/
public function __construct(BookmarkService $bookmarkService, LocationService $locationService)
{
$this->bookmarkService = $bookmarkService;
$this->locationService = $locationService;
}
/**
* Checks if a given location is bookmarked.
*
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*/
public function isBookmarked(int $locationId): Values\OK
{
$location = $this->locationService->loadLocation($locationId);
if (!$this->bookmarkService->isBookmarked($location)) {
throw new Exceptions\NotFoundException("Location {$locationId} is not bookmarked");
}
return new Values\OK();
}
}