mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
accompanying period work list for my, near end date
This commit is contained in:
@@ -12,10 +12,21 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class AccompanyingCourseWorkApiController extends ApiController
|
||||
{
|
||||
private AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository;
|
||||
|
||||
public function __construct(AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository)
|
||||
{
|
||||
$this->accompanyingPeriodWorkRepository = $accompanyingPeriodWorkRepository;
|
||||
}
|
||||
|
||||
protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array
|
||||
{
|
||||
switch ($action) {
|
||||
@@ -28,4 +39,25 @@ class AccompanyingCourseWorkApiController extends ApiController
|
||||
|
||||
return parent::getContextForSerialization($action, $request, $_format, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/accompanying-period/work/my-near-end")
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function myWorksNearEndDate(Request $request): JsonResponse
|
||||
{
|
||||
$since = (new \DateTimeImmutable('now'))->sub(new \DateInterval('P15D'));
|
||||
$until = (new \DateTimeImmutable('now'))->add(new \DateInterval('P15D'));
|
||||
$total = $this->accompanyingPeriodWorkRepository
|
||||
->countNearEndDateByUser($this->getUser(), $since, $until);
|
||||
$paginator = $this->getPaginatorFactory()->create($total);
|
||||
$works = $this->accompanyingPeriodWorkRepository
|
||||
->findNearEndDateByUser($this->getUser(), $since, $until, $paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||
|
||||
$collection = new Collection($works, $paginator);
|
||||
|
||||
return $this->json($collection, 200, [], ['groups' => ['read']]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user