Completed
Push — 2.1 ( d7139b...4f94f6 )
by Rafał
09:57
created

AuthorSearchController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 7
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A searchAction() 0 43 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher ElasticSearch Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ElasticSearchBundle\Controller\Api;
18
19
use SWP\Bundle\ElasticSearchBundle\Criteria\Criteria;
20
use SWP\Component\Common\Response\ResourcesListResponse;
21
use SWP\Component\Common\Response\ResponseContext;
22
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\Routing\Annotation\Route;
25
26
class AuthorSearchController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
27
{
28
    /**
29
     * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors")
30
     */
31
    public function searchAction(Request $request): ResourcesListResponse
32
    {
33
        $criteria = Criteria::fromQueryParameters(
34
            $request->query->get('term', ''),
35
            [
36
                'page' => $request->query->get('page'),
37
                'sort' => $request->query->get('sorting'),
38
                'limit' => $request->query->get('limit', 10),
39
            ]
40
        );
41
42
        $result = $this->get('fos_elastica.manager')
43
            ->getRepository($this->getParameter('swp.model.author.class'))
44
            ->findByCriteria($criteria);
45
46
        $pagination = $this->get('knp_paginator')->paginate(
47
            $result,
48
            $request->query->get('page', 1),
49
            $criteria->getPagination()->getItemsPerPage()
50
        );
51
52
        $responseContext = new ResponseContext();
53
        $responseContext->setSerializationGroups(
54
            [
55
                'Default',
56
                'api_packages_list',
57
                'api_packages_items_list',
58
                'api_tenant_list',
59
                'api_articles_list',
60
                'api_articles_slideshows',
61
                'api_articles_featuremedia',
62
                'api_articles_statistics_list',
63
                'api_article_authors',
64
                'api_article_media_list',
65
                'api_article_media_renditions',
66
                'api_image_details',
67
                'api_groups_list',
68
                'api_routes_list',
69
            ]
70
        );
71
72
        return new ResourcesListResponse($pagination, $responseContext);
73
    }
74
}
75