<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Repository\PostLikeRepository;
use App\Entity\Contact;
use App\Entity\Agences;
use App\Repository\AnnoncesRepository;
use App\Entity\User;
use Doctrine\Persistence\ManagerRegistry;
use App\Controller\Fonctions\Fonctions;
/**
* Class ContactController
* @package App\Controller
*/
class ContactController extends AbstractController
{
/**
* @Route(path="/contact/{type}/{id}", name="contact", methods={"GET"})
* @param Contact $contact
* @param PostLikeRepository $repository
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function index(Request $request, ManagerRegistry $doctrine, AnnoncesRepository $annoncesRepository, $id): Response
{
// insertion
$entityManager = $doctrine->getManager();
$user = $this->getUser();
$userRepoAgence = $entityManager->getRepository(Agences::class);
$idagence = $userRepoAgence->find($id);
$user = $this->getUser();
$userRepo = $entityManager->getRepository(User::class);
$iduser = $userRepo->find($user);
// création de la relation contact
$contact = new Contact();
$contact->setAgence($idagence);
$contact->setUser($iduser);
$contact->setType(1);
$contact->setIsVerified(0);
$entityManager->persist($contact);
$entityManager->flush();
$code = 200;
return new JsonResponse([
'code' => $code,
]);
}
/**
* @Route(path="/acceptation/{id}", name="acceptation", methods={"GET"})
* @param Contact $contact
* @param PostLikeRepository $repository
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function acceptation(Request $request, ManagerRegistry $doctrine, $id): Response
{
$entityManager = $doctrine->getManager();
$userRepo = $entityManager->getRepository(Contact::class);
$id = $userRepo->findOneBy(["id" => $id]);
$idagence = $id->getAgence();
$idcontact = $id->getUser();
$user = $userRepo->find($id);
$user->setIsVerified(1);
$entityManager->flush();
// on met à jour le contact.
$userRepo = $entityManager->getRepository(User::class);
$user = $userRepo->find($idcontact);
$user->setAgence($idagence);
$entityManager->flush();
$code = 200;
return new JsonResponse([
'code' => $code,
]);
}
/**
* @Route(path="/refu/{type}/{id}", name="refu", methods={"GET"})
* @param Contact $contact
* @param PostLikeRepository $repository
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function refu(): Response
{
$code = 200;
return new JsonResponse([
'code' => $code,
]);
}
}