mirror of
https://forge.chapril.org/tykayn/caisse-bliss
synced 2025-06-20 01:44:42 +02:00
add api platform to entitites
This commit is contained in:
parent
c44ac9c522
commit
9c9f8984af
15 changed files with 13 additions and 369 deletions
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Form\CategoryType;
|
||||
use App\Repository\CategoryRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/category')]
|
||||
final class CategoryController extends AbstractController
|
||||
{
|
||||
#[Route(name: 'app_category_index', methods: ['GET'])]
|
||||
public function index(CategoryRepository $categoryRepository): Response
|
||||
{
|
||||
return $this->render('category/index.html.twig', [
|
||||
'categories' => $categoryRepository->findAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/new', name: 'app_category_new', methods: ['GET', 'POST'])]
|
||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$category = new Category();
|
||||
$form = $this->createForm(CategoryType::class, $category);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->persist($category);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_category_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('category/new.html.twig', [
|
||||
'category' => $category,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_category_show', methods: ['GET'])]
|
||||
public function show(Category $category): Response
|
||||
{
|
||||
return $this->render('category/show.html.twig', [
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}/edit', name: 'app_category_edit', methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request, Category $category, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$form = $this->createForm(CategoryType::class, $category);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_category_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('category/edit.html.twig', [
|
||||
'category' => $category,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_category_delete', methods: ['POST'])]
|
||||
public function delete(Request $request, Category $category, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
if ($this->isCsrfTokenValid('delete'.$category->getId(), $request->getPayload()->getString('_token'))) {
|
||||
$entityManager->remove($category);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_category_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\CategoryRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
|
||||
class Category
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'categories')]
|
||||
private ?User $user = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(?User $user): static
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,9 @@ namespace App\Entity;
|
|||
|
||||
use App\Repository\ExpenseRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
|
||||
#[ApiResource(paginationEnabled: false)]
|
||||
#[ORM\Entity(repositoryClass: ExpenseRepository::class)]
|
||||
class Expense
|
||||
{
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\FestvialRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: FestvialRepository::class)]
|
||||
class Festvial
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
||||
private ?\DateTimeInterface $dateCreation = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?float $chiffreAffaire = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $clientsCount = null;
|
||||
|
||||
#[ORM\Column(length: 500, nullable: true)]
|
||||
private ?string $commentaire = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateCreation(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->dateCreation;
|
||||
}
|
||||
|
||||
public function setDateCreation(?\DateTimeInterface $dateCreation): static
|
||||
{
|
||||
$this->dateCreation = $dateCreation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChiffreAffaire(): ?float
|
||||
{
|
||||
return $this->chiffreAffaire;
|
||||
}
|
||||
|
||||
public function setChiffreAffaire(?float $chiffreAffaire): static
|
||||
{
|
||||
$this->chiffreAffaire = $chiffreAffaire;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClientsCount(): ?int
|
||||
{
|
||||
return $this->clientsCount;
|
||||
}
|
||||
|
||||
public function setClientsCount(?int $clientsCount): static
|
||||
{
|
||||
$this->clientsCount = $clientsCount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommentaire(): ?string
|
||||
{
|
||||
return $this->commentaire;
|
||||
}
|
||||
|
||||
public function setCommentaire(?string $commentaire): static
|
||||
{
|
||||
$this->commentaire = $commentaire;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,9 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
|
||||
#[ApiResource(paginationEnabled: false)]
|
||||
#[ORM\Entity(repositoryClass: GroupOfProductsRepository::class)]
|
||||
class GroupOfProducts
|
||||
{
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
|
||||
use App\Repository\ProductRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ApiResource(paginationEnabled: false)]
|
||||
#[ORM\Entity(repositoryClass: ProductRepository::class)]
|
||||
class Product
|
||||
{
|
||||
|
|
|
@ -7,7 +7,9 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
|
||||
#[ApiResource(paginationEnabled: false)]
|
||||
#[ORM\Entity(repositoryClass: SellingRepository::class)]
|
||||
class Selling
|
||||
{
|
||||
|
|
|
@ -7,7 +7,9 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
|
||||
#[ApiResource(paginationEnabled: false)]
|
||||
#[ORM\Entity(repositoryClass: SerieFestivalRepository::class)]
|
||||
class SerieFestival
|
||||
{
|
||||
|
|
|
@ -10,7 +10,9 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
|
||||
#[ApiResource(paginationEnabled: false)]
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
||||
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
|
||||
|
@ -75,12 +77,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||
#[ORM\OneToMany(targetEntity: Festival::class, mappedBy: 'user')]
|
||||
private Collection $festivals;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Category>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Category::class, mappedBy: 'user')]
|
||||
private Collection $categories;
|
||||
|
||||
/**
|
||||
* @var Collection<int, SerieFestival>
|
||||
*/
|
||||
|
@ -94,7 +90,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||
$this->products = new ArrayCollection();
|
||||
$this->groupOfProducts = new ArrayCollection();
|
||||
$this->festivals = new ArrayCollection();
|
||||
$this->categories = new ArrayCollection();
|
||||
$this->seriesFestival = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
@ -173,18 +168,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||
// $this->plainPassword = null;
|
||||
}
|
||||
|
||||
public function getOwner(): ?object
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner(object $owner): static
|
||||
{
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getExpenses(): ?object
|
||||
{
|
||||
return $this->expenses;
|
||||
|
@ -333,35 +316,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Category>
|
||||
*/
|
||||
public function getCategories(): Collection
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
public function addCategory(Category $category): static
|
||||
{
|
||||
if (!$this->categories->contains($category)) {
|
||||
$this->categories->add($category);
|
||||
$category->setUser($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCategory(Category $category): static
|
||||
{
|
||||
if ($this->categories->removeElement($category)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($category->getUser() === $this) {
|
||||
$category->setUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, SerieFestival>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue