← Back
Editing: ReportCommentTemplateApiController.php
<?php namespace App\Controller\Api; use App\Entity\ReportCommentTemplate; use App\Enum\ReportType; use App\Form\Api\ReportCommentTemplateApiType; use App\Repository\ReportCommentTemplateRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\ExpressionLanguage\Expression; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; #[IsGranted(new Expression('is_granted("ROLE_AGENT") or is_granted("ROLE_MANAGER")'))] #[Route(path: '/api/report/comment/template', name: 'api_report_comment_template_')] class ReportCommentTemplateApiController extends AbstractApiController { public function __construct( private readonly ReportCommentTemplateRepository $reportCommentTemplateRepository, protected EntityManagerInterface $em, ) { } #[Route(path: '/{reportType}', name: 'list', methods: ['GET'])] public function getList(ReportType $reportType): JsonResponse { $comments = $this->reportCommentTemplateRepository->findBy(criteria: [ 'reportType' => $reportType, ], orderBy: ['position' => 'ASC']); return $this->response( $comments, 'show_comment_template' ); } #[Route(path: '/add', name: 'add', methods: ['POST'])] public function add( Request $request ): JsonResponse { $body = $request->getContent(); $data = json_decode($body, true); $reportCommentTemplate = new ReportCommentTemplate(); $form = $this->createForm(ReportCommentTemplateApiType::class, $reportCommentTemplate); $form->submit($data); $this->em->persist($reportCommentTemplate); $this->em->flush(); return $this->response($reportCommentTemplate, 'show_comment_template'); } }
Save File
Cancel