|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Controller\Article; |
|
6
|
|
|
|
|
7
|
|
|
use App\Repository\ArticleRepository; |
|
8
|
|
|
use App\Security\UserResolver; |
|
9
|
|
|
use FOS\RestBundle\Controller\Annotations\QueryParam; |
|
10
|
|
|
use FOS\RestBundle\Request\ParamFetcher; |
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
13
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @Route("/api/articles/feed", methods={"GET"}, name="api_articles_feed") |
|
17
|
|
|
* |
|
18
|
|
|
* @QueryParam(name="limit", requirements="\d+", default="20") |
|
19
|
|
|
* @QueryParam(name="offset", requirements="\d+", default="0") |
|
20
|
|
|
* |
|
21
|
|
|
* @Security("is_granted('ROLE_USER')") |
|
22
|
|
|
*/ |
|
23
|
|
|
final class GetArticlesFeedController extends AbstractController |
|
24
|
|
|
{ |
|
25
|
|
|
private UserResolver $userResolver; |
|
26
|
|
|
private ArticleRepository $articleRepository; |
|
27
|
|
|
|
|
28
|
4 |
|
public function __construct(UserResolver $userResolver, ArticleRepository $repository) |
|
29
|
|
|
{ |
|
30
|
4 |
|
$this->userResolver = $userResolver; |
|
31
|
4 |
|
$this->articleRepository = $repository; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
3 |
|
public function __invoke(ParamFetcher $paramFetcher): array |
|
35
|
|
|
{ |
|
36
|
3 |
|
$user = $this->userResolver->getCurrentUser(); |
|
37
|
|
|
|
|
38
|
3 |
|
$offset = (int) $paramFetcher->get('offset'); |
|
39
|
3 |
|
$limit = (int) $paramFetcher->get('limit'); |
|
40
|
|
|
|
|
41
|
3 |
|
$articlesCount = $this->articleRepository->getArticlesFeedCount($user); |
|
42
|
3 |
|
$articles = $this->articleRepository->getArticlesFeed($user, $offset, $limit); |
|
43
|
|
|
|
|
44
|
|
|
return [ |
|
45
|
3 |
|
'articlesCount' => $articlesCount, |
|
46
|
|
|
'articles' => $articles, |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|