do no use header application/vnd.phraseanet.story-paginate

This commit is contained in:
aynsix
2019-12-04 10:17:59 +04:00
parent 3d1983452e
commit 530397db00
3 changed files with 5 additions and 18 deletions

View File

@@ -51,8 +51,7 @@ class ApiApplicationLoader extends BaseApplicationLoader
['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'], ['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'],
V1::$extendedContentTypes['json'], V1::$extendedContentTypes['json'],
V1::$extendedContentTypes['jsonp'], V1::$extendedContentTypes['jsonp'],
V1::$extendedContentTypes['yaml'], V1::$extendedContentTypes['yaml']
[V1::HEADER_ACCEPT_STORY_PAGINATE]
); );
$app['phraseanet.content-negotiation.custom_formats'] = [ $app['phraseanet.content-negotiation.custom_formats'] = [

View File

@@ -1217,18 +1217,12 @@ class V1Controller extends Controller
$fractal->setSerializer(new TraceableArraySerializer($this->app['dispatcher'])); $fractal->setSerializer(new TraceableArraySerializer($this->app['dispatcher']));
$fractal->parseIncludes($this->resolveSearchIncludes($request)); $fractal->parseIncludes($this->resolveSearchIncludes($request));
$story_max_items = null;
// if the header accept story paginate, take account story_max_items parameter
if (in_array(V1::HEADER_ACCEPT_STORY_PAGINATE, $request->getAcceptableContentTypes())) {
$story_max_items = (int)$request->get('story_max_items') ?: 10;
}
$result = $this->doSearch($request); $result = $this->doSearch($request);
$searchView = $this->buildSearchView( $searchView = $this->buildSearchView(
$result, $result,
$includeResolver->resolve($fractal), $includeResolver->resolve($fractal),
$this->resolveSubdefUrlTTL($request), $this->resolveSubdefUrlTTL($request),
$story_max_items (int)$request->get('story_max_items') ?: 10
); );
$ret = $fractal->createData(new Item($searchView, $searchTransformer))->toArray(); $ret = $fractal->createData(new Item($searchView, $searchTransformer))->toArray();
@@ -1682,13 +1676,9 @@ class V1Controller extends Controller
return Result::createError($request, 404, 'Story not found')->createResponse(); return Result::createError($request, 404, 'Story not found')->createResponse();
} }
$offset = 1; $max_items = (int)$request->get('max_items')?:10;
$max_items = null; $page = (int)$request->get('page')?:1;
if (in_array(V1::HEADER_ACCEPT_STORY_PAGINATE, $request->getAcceptableContentTypes())) { $offset = ($max_items * ($page - 1)) + 1;
$max_items = (int)$request->get('max_items')?:10;
$page = (int)$request->get('page')?:1;
$offset = ($max_items * ($page - 1)) + 1;
}
$caption = $story->get_caption(); $caption = $story->get_caption();

View File

@@ -25,8 +25,6 @@ class V1 extends Api implements ControllerProviderInterface, ServiceProviderInte
{ {
const VERSION = '2.0.0'; const VERSION = '2.0.0';
const HEADER_ACCEPT_STORY_PAGINATE = 'application/vnd.phraseanet.story-paginate';
public static $extendedContentTypes = [ public static $extendedContentTypes = [
'json' => ['application/vnd.phraseanet.record-extended+json'], 'json' => ['application/vnd.phraseanet.record-extended+json'],
'yaml' => ['application/vnd.phraseanet.record-extended+yaml'], 'yaml' => ['application/vnd.phraseanet.record-extended+yaml'],