15
15
use ApiPlatform \Metadata \GetCollection ;
16
16
use ApiPlatform \Metadata \Post ;
17
17
use ApiPlatform \Metadata \Put ;
18
+ use ApiPlatform \Metadata \UrlGeneratorInterface ;
18
19
use App \Enum \BookCondition ;
19
20
use App \Repository \BookRepository ;
20
21
use App \State \Processor \BookPersistProcessor ;
21
22
use App \State \Processor \BookRemoveProcessor ;
23
+ use Doctrine \Common \Collections \ArrayCollection ;
24
+ use Doctrine \Common \Collections \Collection ;
22
25
use Doctrine \DBAL \Types \Types ;
23
26
use Doctrine \ORM \Mapping as ORM ;
24
27
use Symfony \Bridge \Doctrine \IdGenerator \UuidGenerator ;
44
47
paginationClientItemsPerPage: true
45
48
),
46
49
new Post (
47
- // Mercure publish is done manually in MercureProcessor through BookPersistProcessor
48
50
processor: BookPersistProcessor::class,
49
51
itemUriTemplate: '/admin/books/{id}{._format} '
50
52
),
54
56
// https://github.com/api-platform/admin/issues/370
55
57
new Put (
56
58
uriTemplate: '/admin/books/{id}{._format} ' ,
57
- // Mercure publish is done manually in MercureProcessor through BookPersistProcessor
58
59
processor: BookPersistProcessor::class
59
60
),
60
61
new Delete (
61
62
uriTemplate: '/admin/books/{id}{._format} ' ,
62
- // Mercure publish is done manually in MercureProcessor through BookRemoveProcessor
63
63
processor: BookRemoveProcessor::class
64
64
),
65
65
],
71
71
AbstractNormalizer::GROUPS => ['Book:write ' ],
72
72
],
73
73
collectDenormalizationErrors: true ,
74
- security: 'is_granted("OIDC_ADMIN") '
74
+ security: 'is_granted("OIDC_ADMIN") ' ,
75
+ mercure: [
76
+ 'topics ' => [
77
+ '@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/admin/books/{id}{._format}")) ' ,
78
+ '@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/books/{id}{._format}")) ' ,
79
+ ],
80
+ ]
75
81
)]
76
82
#[ApiResource(
77
83
types: ['https://schema.org/Book ' , 'https://schema.org/Offer ' ],
@@ -155,14 +161,18 @@ class Book
155
161
/**
156
162
* An IRI of reviews.
157
163
*
164
+ * @var Collection<int, Review>
165
+ *
158
166
* @see https://schema.org/reviews
159
167
*/
160
168
#[ApiProperty(
161
169
types: ['https://schema.org/reviews ' ],
162
- example: '/books/6acacc80-8321-4d83-9b02-7f2c7bf6eb1d/reviews '
170
+ example: '/books/6acacc80-8321-4d83-9b02-7f2c7bf6eb1d/reviews ' ,
171
+ uriTemplate: '/books/{bookId}/reviews{._format} '
163
172
)]
164
173
#[Groups(groups: ['Book:read ' , 'Bookmark:read ' ])]
165
- public ?string $ reviews = null ;
174
+ #[ORM \OneToMany(targetEntity: Review::class, mappedBy: 'book ' )]
175
+ public Collection $ reviews ;
166
176
167
177
/**
168
178
* The overall rating, based on a collection of reviews or ratings, of the item.
@@ -176,6 +186,11 @@ class Book
176
186
#[Groups(groups: ['Book:read ' , 'Book:read:admin ' , 'Bookmark:read ' ])]
177
187
public ?int $ rating = null ;
178
188
189
+ public function __construct ()
190
+ {
191
+ $ this ->reviews = new ArrayCollection ();
192
+ }
193
+
179
194
public function getId (): ?Uuid
180
195
{
181
196
return $ this ->id ;
0 commit comments