Skip to content

Commit 367040d

Browse files
committed
[BUGFIX] Refine file reference handling for POST requests. Before this fix it was not possible to add sys_file_reference in one go with the main record. It was only possible to add a file reference using PATCH after to existing main record. Additional changes: a) Standardize serialization groups in News model for consistent API access. b) Enhance Postman tests to verify multiple file references in POST requests. c) Update test assertions to validate file reference properties.
1 parent 70b7494 commit 367040d

File tree

4 files changed

+267
-18
lines changed

4 files changed

+267
-18
lines changed

.ddev/test/files/src/t3apinews/Classes/Domain/Model/News.php

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
139139
* @T3api\Serializer\Groups({
140140
* "api_get_collection_t3apinews_news",
141141
* "api_get_item_t3apinews_news",
142+
* "api_post_item_t3apinews_news",
143+
* "api_patch_item_t3apinews_news",
144+
* "api_put_item_t3apinews_news",
142145
* })
143146
*/
144147
protected $teaser = '';
@@ -148,6 +151,8 @@ class News extends \GeorgRinger\News\Domain\Model\News
148151
* @T3api\Serializer\Groups({
149152
* "api_get_item_t3apinews_news",
150153
* "api_post_item_t3apinews_news",
154+
* "api_patch_item_t3apinews_news",
155+
* "api_put_item_t3apinews_news",
151156
* })
152157
*/
153158
protected $bodytext = '';
@@ -156,20 +161,20 @@ class News extends \GeorgRinger\News\Domain\Model\News
156161
* @var \DateTime
157162
* @T3api\Serializer\Groups({
158163
* "api_get_collection_t3apinews_news",
159-
* "api_get_item_t3apinews_news",
160-
* "api_post_item_t3apinews_news",
161-
* "api_patch_item_t3apinews_news",
162-
* "api_put_item_t3apinews_news",
164+
* "api_get_item_t3apinews_news",
165+
* "api_post_item_t3apinews_news",
166+
* "api_patch_item_t3apinews_news",
167+
* "api_put_item_t3apinews_news",
163168
* })
164169
*/
165170
protected $datetime;
166171

167172
/**
168173
* @var \Datetime
169174
* @T3api\Serializer\Groups({
170-
* "api_post_item_t3apinews_news",
171-
* "api_patch_item_t3apinews_news",
172-
* "api_put_item_t3apinews_news",
175+
* "api_post_item_t3apinews_news",
176+
* "api_patch_item_t3apinews_news",
177+
* "api_put_item_t3apinews_news",
173178
* })
174179
*/
175180
protected $crdate;
@@ -179,6 +184,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
179184
* @T3api\Serializer\Groups({
180185
* "api_get_collection_t3apinews_news",
181186
* "api_get_item_t3apinews_news",
187+
* "api_post_item_t3apinews_news",
188+
* "api_patch_item_t3apinews_news",
189+
* "api_put_item_t3apinews_news",
182190
* })
183191
*/
184192
protected $author = '';
@@ -188,6 +196,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
188196
* @T3api\Serializer\Groups({
189197
* "api_get_collection_t3apinews_news",
190198
* "api_get_item_t3apinews_news",
199+
* "api_post_item_t3apinews_news",
200+
* "api_patch_item_t3apinews_news",
201+
* "api_put_item_t3apinews_news",
191202
* })
192203
*/
193204
protected $authorEmail = '';
@@ -207,21 +218,21 @@ class News extends \GeorgRinger\News\Domain\Model\News
207218
/**
208219
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SourceBroker\T3apinews\Domain\Model\News>
209220
* @T3api\Serializer\Groups({
210-
* "api_get_item_t3apinews_news",
211-
* "api_post_item_t3apinews_news",
212-
* "api_patch_item_t3apinews_news",
213-
* "api_put_item_t3apinews_news",
221+
* "api_get_item_t3apinews_news",
222+
* "api_post_item_t3apinews_news",
223+
* "api_patch_item_t3apinews_news",
224+
* "api_put_item_t3apinews_news",
214225
* })
215226
*/
216227
protected $related;
217228

218229
/**
219230
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SourceBroker\T3apinews\Domain\Model\News>
220231
* @T3api\Serializer\Groups({
221-
* "api_get_item_t3apinews_news",
222-
* "api_post_item_t3apinews_news",
223-
* "api_patch_item_t3apinews_news",
224-
* "api_put_item_t3apinews_news",
232+
* "api_get_item_t3apinews_news",
233+
* "api_post_item_t3apinews_news",
234+
* "api_patch_item_t3apinews_news",
235+
* "api_put_item_t3apinews_news",
225236
* })
226237
*/
227238
protected $relatedFrom;
@@ -231,13 +242,18 @@ class News extends \GeorgRinger\News\Domain\Model\News
231242
* @T3api\Serializer\Groups({
232243
* "api_get_collection_t3apinews_news",
233244
* "api_get_item_t3apinews_news",
245+
* "api_post_item_t3apinews_news",
246+
* "api_patch_item_t3apinews_news",
247+
* "api_put_item_t3apinews_news",
234248
* })
235249
*/
236250
protected $type = '';
237251

238252
/**
239253
* @var string
240254
* @T3api\Serializer\Groups({
255+
* "api_get_collection_t3apinews_news",
256+
* "api_get_item_t3apinews_news",
241257
* "api_post_item_t3apinews_news",
242258
* "api_patch_item_t3apinews_news",
243259
* "api_put_item_t3apinews_news",
@@ -249,6 +265,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
249265
* @T3api\Serializer\Groups({
250266
* "api_get_collection_t3apinews_news",
251267
* "api_get_item_t3apinews_news",
268+
* "api_post_item_t3apinews_news",
269+
* "api_patch_item_t3apinews_news",
270+
* "api_put_item_t3apinews_news",
252271
* })
253272
*/
254273
protected $internalurl = '';
@@ -258,6 +277,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
258277
* @T3api\Serializer\Groups({
259278
* "api_get_collection_t3apinews_news",
260279
* "api_get_item_t3apinews_news",
280+
* "api_post_item_t3apinews_news",
281+
* "api_patch_item_t3apinews_news",
282+
* "api_put_item_t3apinews_news",
261283
* })
262284
*/
263285
protected $externalurl = '';
@@ -267,6 +289,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
267289
* @T3api\Serializer\Groups({
268290
* "api_get_collection_t3apinews_news",
269291
* "api_get_item_t3apinews_news",
292+
* "api_post_item_t3apinews_news",
293+
* "api_patch_item_t3apinews_news",
294+
* "api_put_item_t3apinews_news",
270295
* })
271296
*/
272297
protected $istopnews = false;
@@ -276,6 +301,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
276301
* @T3api\Serializer\Groups({
277302
* "api_get_collection_t3apinews_news",
278303
* "api_get_item_t3apinews_news",
304+
* "api_post_item_t3apinews_news",
305+
* "api_patch_item_t3apinews_news",
306+
* "api_put_item_t3apinews_news",
279307
* })
280308
*/
281309
protected \TYPO3\CMS\Extbase\Persistence\ObjectStorage $tags;
@@ -285,7 +313,9 @@ class News extends \GeorgRinger\News\Domain\Model\News
285313
* @T3api\Serializer\Groups({
286314
* "api_get_collection_t3apinews_news",
287315
* "api_get_item_t3apinews_news",
316+
* "api_post_item_t3apinews_news",
288317
* "api_patch_item_t3apinews_news",
318+
* "api_put_item_t3apinews_news",
289319
* })
290320
*/
291321
protected $falMedia;

Classes/Serializer/Handler/FileReferenceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected function createSysFileReference(
205205
if ($visitor->getCurrentObject() instanceof AbstractDomainObject) {
206206
/** @var AbstractDomainObject $currentObject */
207207
$currentObject = $visitor->getCurrentObject();
208-
$fileReference->setPid($currentObject->getPid());
208+
$fileReference->setPid($currentObject->getPid() ?? 0);
209209
$fileReference->_setProperty('_languageUid', $currentObject->_getProperty('_languageUid'));
210210
}
211211

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ At frontend part you can at once test REST API responses for ext news:
4444
* https://13.t3api.ddev.site/_api/news/categories
4545
* etc
4646

47-
You can also run Postman test with ``ddev ci:tests:postman`` command or full test suite with ``ddev composer ci``.
47+
You can also run Postman test with ``ddev composer ci:tests:postman`` command or full test suite with ``ddev composer ci``.
4848
Postman is doing full CRUD test with category and news (with image).
4949

5050
Development

0 commit comments

Comments
 (0)