Convert Moderation to a service+validator

This commit is contained in:
2024-06-12 20:37:24 +02:00
parent 32e0774302
commit b0f09a8217
12 changed files with 126 additions and 53 deletions

View File

@@ -8,11 +8,8 @@ use App\Entity\User;
use App\Form\CommentType;
use App\Form\PostType;
use App\Repository\PostRepository;
use App\Security\Moderation\Moderation;
use CURLFile;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@@ -48,19 +45,15 @@ class PostController extends AbstractController
#[Route('/post/new', name: 'app_post_new', methods: ['GET', 'POST'])]
#[IsGranted('ROLE_USER')]
public function new(Request $request, EntityManagerInterface $entityManager, ParameterBagInterface $env): Response
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$post = new Post();
$form = $this->createForm(PostType::class, $post);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$api_key = $this->getParameter('app.API_KEY_SIGHT_ENGINE');
$moderation = new Moderation($api_key);
if($moderation->valide($post->getImageFile()->getRealPath())){
$entityManager->persist($post);
$entityManager->flush();
}
$entityManager->persist($post);
$entityManager->flush();
return $this->redirectToRoute('app_posts', [], Response::HTTP_SEE_OTHER);
}