- Modification des Favoris bdd + code
This commit is contained in:
@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use App\Repository\FavorisRepository;
|
||||
use App\Entity\Favoris;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
class APISearchController extends AbstractController
|
||||
{
|
||||
@ -31,27 +32,46 @@ class APISearchController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/toggleLike/{idGoogle}', name: 'like', methods: "POST")]
|
||||
public function addFavoris(FavorisRepository $favorisRepository, String $idGoogle)
|
||||
public function addFavoris(Request $request, FavorisRepository $favorisRepository, String $idGoogle)
|
||||
{
|
||||
$content = $request->getContent();
|
||||
$data = json_decode($content, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE || empty($data)) {
|
||||
return new JsonResponse(['status' => 'error', 'message' => 'Invalid data'], 400);
|
||||
}
|
||||
|
||||
$title = $data['title'] ?? '';
|
||||
$authors = $data['authors'] ?? '';
|
||||
$images = $data['images'] ?? '';
|
||||
$description = $data['description'] ?? '';
|
||||
$date = $data['date'] ?? '';
|
||||
$pages = $data['pages'] ?? '';
|
||||
|
||||
$favoris = new Favoris();
|
||||
$user = $this->getUser();
|
||||
$favoris->setUser($user);
|
||||
$favoris->setIdGoogle($idGoogle);
|
||||
$favoris->setTitle($title);
|
||||
$favoris->setAuthors($authors);
|
||||
$favoris->setImage($images);
|
||||
$favoris->setDescription($description);
|
||||
$favoris->setPublication($date);
|
||||
$favoris->setPages($pages);
|
||||
$favoris->setPublication($date);
|
||||
|
||||
|
||||
$favorisRepository->addFavoris($favoris);
|
||||
return $this->json(['success' => true, 'message' => 'Favoris ajouté']);
|
||||
return $this->json(['success' => true, 'message' => 'Favoris ajouté', "status" => "added"]);
|
||||
}
|
||||
|
||||
#[Route('/untoggleLike/{idGoogle}', name: 'unlike', methods: "POST")]
|
||||
public function removeFavoris(FavorisRepository $favorisRepository, String $idGoogle)
|
||||
{
|
||||
$favoris = new Favoris();
|
||||
$user = $this->getUser();
|
||||
$favoris->setUser($user);
|
||||
$favoris->setIdGoogle($idGoogle);
|
||||
$favorisRepository->removeFavoris($user, $idGoogle);
|
||||
|
||||
return $this->json(['success' => true, 'message' => 'Favoris supprimé']);
|
||||
return $this->json(['success' => true, 'message' => 'Favoris supprimé', "status" => "removed"]);
|
||||
}
|
||||
|
||||
#[Route('/api/search', name: 'api_search')]
|
||||
|
@ -19,6 +19,30 @@ class Favoris
|
||||
#[ORM\ManyToOne(inversedBy: 'favoris')]
|
||||
private ?User $user = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $authors = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $edition = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $publication = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $categorie = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $pages = null;
|
||||
|
||||
#[ORM\Column(length: 2555, nullable: true)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $image = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@ -47,4 +71,100 @@ class Favoris
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): static
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAuthors(): ?string
|
||||
{
|
||||
return $this->authors;
|
||||
}
|
||||
|
||||
public function setAuthors(?string $authors): static
|
||||
{
|
||||
$this->authors = $authors;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEdition(): ?string
|
||||
{
|
||||
return $this->edition;
|
||||
}
|
||||
|
||||
public function setEdition(?string $edition): static
|
||||
{
|
||||
$this->edition = $edition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPublication(): ?string
|
||||
{
|
||||
return $this->publication;
|
||||
}
|
||||
|
||||
public function setPublication(?string $publication): static
|
||||
{
|
||||
$this->publication = $publication;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategorie(): ?string
|
||||
{
|
||||
return $this->categorie;
|
||||
}
|
||||
|
||||
public function setCategorie(?string $categorie): static
|
||||
{
|
||||
$this->categorie = $categorie;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPages(): ?string
|
||||
{
|
||||
return $this->pages;
|
||||
}
|
||||
|
||||
public function setPages(?string $pages): static
|
||||
{
|
||||
$this->pages = $pages;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImage(): ?string
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
public function setImage(?string $image): static
|
||||
{
|
||||
$this->image = $image;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user