Skip to content

Commit 0179110

Browse files
authored
PHRAS-4151_stories-reference-in-api (#4602)
* add `include[]=results.records.stories` to searchV3 api * cleanup * cleanup * doc
1 parent 368c86f commit 0179110

File tree

4 files changed

+90
-7
lines changed

4 files changed

+90
-7
lines changed

doc/API_documentation/v3/_compiled.yaml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,36 @@ paths:
400400
401401
### results.records.technical_informations
402402
always included
403-
403+
404404
_nb:_ since stories are not related to a document, there is no technical_informations for stories.
405-
406-
### results.records.children
405+
406+
### results.records.stories
407+
Include a list of stories that contains the record
408+
409+
stories is an array of small objects containing only the `story_id` (= `record_id`) of the story.
410+
```
411+
"response": {
412+
"results": {
413+
"records": [
414+
{
415+
"stories": [
416+
{
417+
"story_id": 100
418+
},
419+
{
420+
"story_id": 102
421+
},
422+
...
423+
],
424+
...
425+
},
426+
...
427+
]
428+
}
429+
}
430+
```
431+
432+
### results.stories.children
407433
In story search mode, will publish a children[] array for each result. See _story_children_limit_ parameter.
408434
409435
children is an array of records, with same structure as a result record.

doc/API_documentation/v3/api.yaml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,36 @@ paths:
443443
444444
### results.records.technical_informations
445445
always included
446-
446+
447447
_nb:_ since stories are not related to a document, there is no technical_informations for stories.
448-
449-
### results.records.children
448+
449+
### results.records.stories
450+
Include a list of stories that contains the record
451+
452+
stories is an array of small objects containing only the `story_id` (= `record_id`) of the story.
453+
```
454+
"response": {
455+
"results": {
456+
"records": [
457+
{
458+
"stories": [
459+
{
460+
"story_id": 100
461+
},
462+
{
463+
"story_id": 102
464+
},
465+
...
466+
],
467+
...
468+
},
469+
...
470+
]
471+
}
472+
}
473+
```
474+
475+
### results.stories.children
450476
In story search mode, will publish a children[] array for each result. See _story_children_limit_ parameter.
451477
452478
children is an array of records, with same structure as a result record.

lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function searchAction(Request $request)
6969
$technicalDataTransformer = new TechnicalDataTransformer();
7070
$recordTransformer = new RecordTransformer($subdefTransformer, $technicalDataTransformer, $this->getResourceIdResolver());
7171
$storyTransformer = new V3StoryTransformer($recordTransformer);
72+
$recordTransformer->setStoryTransformer($storyTransformer);
7273
$compositeTransformer = new V3SearchCompositeResultTransformer($recordTransformer, $storyTransformer);
7374
$searchTransformer = new V3SearchResultTransformer($compositeTransformer);
7475

@@ -79,6 +80,9 @@ public function searchAction(Request $request)
7980
'suggestions' => new CallbackTransformer(),
8081
'results.stories' => $storyTransformer,
8182
'results.stories.children' => $recordTransformer,
83+
'results.records.stories' => $storyTransformer,
84+
'results.records.stories.thumbnail' => $subdefTransformer,
85+
'results.records.stories.metadata' => new CallbackTransformer(),
8286
'results.stories.children.thumbnail' => $subdefTransformer,
8387
'results.stories.children.technical_informations' => $technicalDataTransformer,
8488
'results.stories.children.subdefs' => $subdefTransformer,

lib/Alchemy/Phrasea/Search/RecordTransformer.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class RecordTransformer extends TransformerAbstract
2222
'metadata',
2323
// 'metadatas',
2424
'status',
25-
'caption'
25+
'caption',
26+
'stories'
2627
];
2728

2829
protected $defaultIncludes = [
@@ -45,6 +46,10 @@ class RecordTransformer extends TransformerAbstract
4546
* @var callable
4647
*/
4748
private $resourceIdResolver;
49+
/**
50+
* @var V3StoryTransformer
51+
*/
52+
private $storyTransformer;
4853

4954
public function __construct(SubdefTransformer $subdefTransformer, TechnicalDataTransformer $technicalDataTransformer, callable $resourceIdResolver)
5055
{
@@ -171,11 +176,33 @@ public function includeCaption(RecordView $recordView)
171176
});
172177
}
173178

179+
public function includeStories(RecordView $recordView)
180+
{
181+
$data = [];
182+
183+
/** @var record_adapter $story */
184+
foreach($recordView->getRecord()->get_grouping_parents() as $story) {
185+
$data[] = [
186+
// 'title' => $story->get_title(),
187+
'story_id' => $story->getRecordId(),
188+
];
189+
}
190+
191+
return $this->collection($data, function (array $storyData) {
192+
return $storyData;
193+
});
194+
}
195+
174196
/**
175197
* @return callable
176198
*/
177199
public function getResourceIdResolver(): callable
178200
{
179201
return $this->resourceIdResolver;
180202
}
203+
204+
public function setStoryTransformer(V3StoryTransformer $storyTransformer)
205+
{
206+
$this->storyTransformer = $storyTransformer;
207+
}
181208
}

0 commit comments

Comments
 (0)