add api for getting goal and results by social action and goal

This commit is contained in:
2021-06-22 16:08:53 +02:00
parent 34d6452286
commit b53f6af8d8
14 changed files with 700 additions and 12 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class SocialWorkResultApiController extends ApiController
{
private ResultRepository $resultRepository;
public function __construct(ResultRepository $resultRepository)
{
$this->resultRepository = $resultRepository;
}
public function listBySocialAction(Request $request, SocialAction $action): Response
{
$totalItems = $this->resultRepository->countBySocialActionWithDescendants($action);
$paginator = $this->getPaginatorFactory()->create($totalItems);
$entities = $this->resultRepository->findBySocialActionWithDescendants($action, ["id" => "ASC"],
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
$model = new Collection($entities, $paginator);
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
}
public function listByGoal(Request $request, Goal $goal): Response
{
$totalItems = $this->resultRepository->countByGoal($goal);
$paginator = $this->getPaginatorFactory()->create($totalItems);
$entities = $this->resultRepository->findByGoal($goal, ["id" => "ASC"],
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
$model = new Collection($entities, $paginator);
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
}
}