mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add endpoint for getting suggestion on household by accompanying period
This commit is contained in:
@@ -4,15 +4,50 @@ namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\Household\HouseholdRepository;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
class HouseholdApiController extends ApiController
|
||||
{
|
||||
private HouseholdRepository $householdRepository;
|
||||
|
||||
public function __construct(HouseholdRepository $householdRepository)
|
||||
{
|
||||
$this->householdRepository = $householdRepository;
|
||||
}
|
||||
|
||||
|
||||
public function householdAddressApi($id, Request $request, string $_format): Response
|
||||
{
|
||||
return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, [ 'groups' => [ 'read' ] ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Household of people participating to the same AccompanyingPeriod
|
||||
*
|
||||
* @ParamConverter("person", options={"id" = "person_id"})
|
||||
*/
|
||||
public function suggestHouseholdByAccompanyingPeriodParticipationApi(Person $person, string $_format)
|
||||
{
|
||||
// TODO add acl
|
||||
|
||||
$count = $this->householdRepository->countByAccompanyingPeriodParticipation($person);
|
||||
$paginator = $this->getPaginatorFactory()->create($count);
|
||||
|
||||
if ($count === 0) {
|
||||
$households = [];
|
||||
} else {
|
||||
$households = $this->householdRepository->findByAccompanyingPeriodParticipation($person,
|
||||
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||
}
|
||||
|
||||
$collection = new Collection($households, $paginator);
|
||||
|
||||
return $this->json($collection, Response::HTTP_OK, [],
|
||||
[ "groups" => ["read"]]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user