Skip to content

Commit

Permalink
Merge pull request afup#1514 from Mopolo/planete-php-add-header
Browse files Browse the repository at this point in the history
[Planete PHP] Correction d'un header et ajout d'un autre
  • Loading branch information
agallou authored Jul 7, 2024
2 parents 1fec830 + 4cf694f commit 78985ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion sources/AppBundle/Controller/Planete/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke(Request $request): Response
$page = 1;
}

$totalCount = $this->feedArticleRepository->count();
$totalCount = $this->feedArticleRepository->countRelevant();
$articles = $this->feedArticleRepository->findLatest($page - 1, DATE_RSS, $perPage);

$data = [];
Expand All @@ -54,6 +54,7 @@ public function __invoke(Request $request): Response
'Content-Type' => 'application/json',
'X-Pagination-Total' => $totalCount,
'X-Pagination-Per-Page' => $perPage,
'X-Pagination-Has-Next-Page' => json_encode($totalCount > $page * $perPage),
]
);
}
Expand Down
9 changes: 9 additions & 0 deletions sources/PlanetePHP/FeedArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public function count(): int
return intval($query->fetchColumn());
}

public function countRelevant(): int
{
$query = $this->connection->prepare('SELECT COUNT(b.id) FROM afup_planete_billet b WHERE b.etat = :status');
$query->bindValue('status', self::RELEVANT);
$query->execute();

return intval($query->fetchColumn());
}

/**
* @param string $sort
* @param string $direction
Expand Down
6 changes: 4 additions & 2 deletions tests/behat/features/Api/PlanetePHPApi.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Feature: PlanetePHP API routes
Given I am on "/planete-php-api/articles"
Then the response status code should be 200
And the response header "Content-Type" should equal "application/json"
And the response header "X-Pagination-Total" should equal 23
And the response header "X-Pagination-Total" should equal 22
And the response header "X-Pagination-Per-Page" should equal 20
And the response header "X-Pagination-Has-Next-Page" should equal true
And the json response has the key "title" with value "Un titre"
And the json response has the key "url" with value "https:\/\/afup.org\/url.html"
And the json response has the key "author" with value "Un super auteur"
Expand All @@ -15,8 +16,9 @@ Feature: PlanetePHP API routes
Given I am on "/planete-php-api/articles?page=2"
Then the response status code should be 200
And the response header "Content-Type" should equal "application/json"
And the response header "X-Pagination-Total" should equal 23
And the response header "X-Pagination-Total" should equal 22
And the response header "X-Pagination-Per-Page" should equal 20
And the response header "X-Pagination-Has-Next-Page" should equal false
And the json response has the key "title" with value "Un titre 18"
And the json response has the key "url" with value "https:\/\/afup.org\/url-18.html"
And the json response has the key "author" with value "Un super auteur 18"
Expand Down

0 comments on commit 78985ab

Please sign in to comment.