mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
add api for getting goal and results by social action and goal
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AccompanyingCourseWorkApiController extends ApiController
|
||||
{
|
||||
protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array
|
||||
{
|
||||
switch($action) {
|
||||
case '_entity':
|
||||
switch ($request->getMethod()) {
|
||||
case Request::METHOD_PUT:
|
||||
return [ 'groups' => [ 'accompanying_period_work:edit' ] ];
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getContextForSerialization($action, $request, $_format, $entity);
|
||||
}
|
||||
|
||||
}
|
@@ -3,6 +3,7 @@
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -27,7 +28,7 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
* methods={"GET", "POST"}
|
||||
* )
|
||||
*/
|
||||
public function createWork(AccompanyingPeriod $period)
|
||||
public function createWork(AccompanyingPeriod $period): Response
|
||||
{
|
||||
// TODO ACL
|
||||
|
||||
@@ -49,4 +50,10 @@ class AccompanyingCourseWorkController extends AbstractController
|
||||
'json' => $json
|
||||
]);
|
||||
}
|
||||
|
||||
public function editWork(AccompanyingPeriodWork $work): Response
|
||||
{
|
||||
// TODO ACL
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SocialWorkGoalApiController extends ApiController
|
||||
{
|
||||
private GoalRepository $goalRepository;
|
||||
|
||||
private PaginatorFactory $paginator;
|
||||
|
||||
|
||||
public function __construct(GoalRepository $goalRepository, PaginatorFactory $paginator)
|
||||
{
|
||||
$this->goalRepository = $goalRepository;
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
public function listBySocialAction(Request $request, SocialAction $action): Response
|
||||
{
|
||||
$totalItems = $this->goalRepository->countBySocialActionWithDescendants($action);
|
||||
$paginator = $this->getPaginatorFactory()->create($totalItems);
|
||||
|
||||
$entities = $this->goalRepository->findBySocialActionWithDescendants($action, ["id" => "ASC"],
|
||||
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||
|
||||
$model = new Collection($entities, $paginator);
|
||||
|
||||
return $this->json($model, Response::HTTP_OK, [], [ "groups" => [ "read" ]]);
|
||||
}
|
||||
|
||||
}
|
@@ -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" ]]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user