task: api endpoint for my tasks

This commit is contained in:
2022-01-23 23:13:25 +01:00
parent 6ab8f95f7d
commit 7e2fbf93f9
2 changed files with 39 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ namespace Chill\TaskBundle\Controller;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
use Chill\MainBundle\Timeline\TimelineBuilder;
@@ -31,6 +32,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -431,10 +434,15 @@ final class SingleTaskController extends AbstractController
* @return Response
* @Route(
* "/{_locale}/task/single-task/list/my",
* name="chill_task_singletask_my_tasks"
* name="chill_task_singletask_my_tasks",
* defaults={"_format": "html"}
* )
* @Route(
* "/api/1.0/task/single-task/list/my",
* defaults={"_format": "json"}
* )
*/
public function myTasksAction()
public function myTasksAction(string $_format)
{
$this->denyAccessUnlessGranted('ROLE_USER');
@@ -459,11 +467,23 @@ final class SingleTaskController extends AbstractController
]
);
return $this->render('@ChillTask/SingleTask/List/index_my_tasks.html.twig', [
'tasks' => $tasks,
'paginator' => $paginator,
'filter_order' => $filterOrder,
]);
switch ($_format) {
case 'html':
return $this->render('@ChillTask/SingleTask/List/index_my_tasks.html.twig', [
'tasks' => $tasks,
'paginator' => $paginator,
'filter_order' => $filterOrder,
]);
case 'json':
$collection = new Collection($tasks, $paginator);
return $this->json($collection, JsonResponse::HTTP_OK, [],
['groups' => ['read']]);
default:
throw new BadRequestException("format not supported: $format");
}
}
/**