mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add endpoint for listing evaluation
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
class SocialWorkEvaluationApiController extends AbstractController
|
||||
{
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
/**
|
||||
* @param PaginatorFactory $paginatorFactory
|
||||
*/
|
||||
public function __construct(PaginatorFactory $paginatorFactory)
|
||||
{
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/social-work/evaluation/by-social-action/{action_id}.json",
|
||||
* name="chill_person_evaluation_index_by_social_action",
|
||||
* requirements={
|
||||
* "_format": "json"
|
||||
* }
|
||||
* )
|
||||
* @ParamConverter("action", options={"id": "action_id"})
|
||||
* @param SocialAction $action
|
||||
* @return Response
|
||||
*/
|
||||
public function listEvaluationBySocialAction(SocialAction $action): Response
|
||||
{
|
||||
$pagination = $this->paginatorFactory->create($action->getEvaluations()->count());
|
||||
|
||||
$evaluations = $action->getEvaluations()->slice($pagination->getCurrentPageFirstItemNumber(),
|
||||
$pagination->getItemsPerPage());
|
||||
$collection = new Collection($evaluations, $pagination);
|
||||
|
||||
return $this->json($collection, Response::HTTP_OK, [], [ 'groups' => [ 'read' ]]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user