forked from Somnia/SomniaRooms
New API - RoomCategory
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
use App\Entity\RoomCategory;
|
||||
use App\Entity\RoomCategoryDetails;
|
||||
use App\Entity\RoomCategoryPhoto;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Serializer\Context\Normalizer\ObjectNormalizerContextBuilder;
|
||||
|
||||
class RoomCategoryController extends AbstractController
|
||||
{
|
||||
|
||||
#[Route('/room/category', name: 'app_room_category')]
|
||||
public function getAll(RoomCategoryRepository $catRepo, SerializerInterface $serializer): Response
|
||||
{
|
||||
$catList = $catRepo->findAll();
|
||||
|
||||
return $this->json(["results" => $catList]);
|
||||
}
|
||||
|
||||
#[Route('/room/category/{id}', name: 'app_room_category')]
|
||||
public function getById(RoomCategory $category, SerializerInterface $serializer): Response
|
||||
{
|
||||
return $this->json($category);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\RoomCategoryRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Component\Serializer\Annotation\Ignore;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: RoomCategoryRepository::class)]
|
||||
class RoomCategory
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 64)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 64, nullable: true)]
|
||||
private ?string $bedType = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $maxGuestNum = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, RoomCategoryPhoto>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: RoomCategoryPhoto::class, mappedBy: 'roomCategory', orphanRemoval: true)]
|
||||
private Collection $roomCategoryPhotos;
|
||||
|
||||
/**
|
||||
* @var Collection<int, RoomCategoryDetails>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: RoomCategoryDetails::class, mappedBy: 'roomCategory', orphanRemoval: true)]
|
||||
private Collection $roomCategoryDetails;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->roomCategoryPhotos = new ArrayCollection();
|
||||
$this->roomCategoryDetails = new ArrayCollection();
|
||||
}
|
||||
|
||||
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 getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBedType(): ?string
|
||||
{
|
||||
return $this->bedType;
|
||||
}
|
||||
|
||||
public function setBedType(?string $bedType): static
|
||||
{
|
||||
$this->bedType = $bedType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaxGuestNum(): ?int
|
||||
{
|
||||
return $this->maxGuestNum;
|
||||
}
|
||||
|
||||
public function setMaxGuestNum(int $maxGuestNum): static
|
||||
{
|
||||
$this->maxGuestNum = $maxGuestNum;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, RoomCategoryPhoto>
|
||||
*/
|
||||
public function getRoomCategoryPhotos(): Collection
|
||||
{
|
||||
return $this->roomCategoryPhotos;
|
||||
}
|
||||
|
||||
public function addRoomCategoryPhoto(RoomCategoryPhoto $roomCategoryPhoto): static
|
||||
{
|
||||
if (!$this->roomCategoryPhotos->contains($roomCategoryPhoto)) {
|
||||
$this->roomCategoryPhotos->add($roomCategoryPhoto);
|
||||
$roomCategoryPhoto->setRoomCategory($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRoomCategoryPhoto(RoomCategoryPhoto $roomCategoryPhoto): static
|
||||
{
|
||||
if ($this->roomCategoryPhotos->removeElement($roomCategoryPhoto)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($roomCategoryPhoto->getRoomCategory() === $this) {
|
||||
$roomCategoryPhoto->setRoomCategory(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, RoomCategoryDetails>
|
||||
*/
|
||||
public function getRoomCategoryDetails(): Collection
|
||||
{
|
||||
return $this->roomCategoryDetails;
|
||||
}
|
||||
|
||||
public function addRoomCategoryDetail(RoomCategoryDetails $roomCategoryDetail): static
|
||||
{
|
||||
if (!$this->roomCategoryDetails->contains($roomCategoryDetail)) {
|
||||
$this->roomCategoryDetails->add($roomCategoryDetail);
|
||||
$roomCategoryDetail->setRoomCategory($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRoomCategoryDetail(RoomCategoryDetails $roomCategoryDetail): static
|
||||
{
|
||||
if ($this->roomCategoryDetails->removeElement($roomCategoryDetail)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($roomCategoryDetail->getRoomCategory() === $this) {
|
||||
$roomCategoryDetail->setRoomCategory(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\RoomCategoryDetailsRepository;
|
||||
use Symfony\Component\Serializer\Annotation\Ignore;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: RoomCategoryDetailsRepository::class)]
|
||||
class RoomCategoryDetails
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $detailsSection = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $detailValue = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'roomCategoryDetails')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Ignore]
|
||||
private ?RoomCategory $roomCategory = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getDetailsSection(): ?string
|
||||
{
|
||||
return $this->detailsSection;
|
||||
}
|
||||
|
||||
public function setDetailsSection(string $detailsSection): static
|
||||
{
|
||||
$this->detailsSection = $detailsSection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDetailValue(): ?string
|
||||
{
|
||||
return $this->detailValue;
|
||||
}
|
||||
|
||||
public function setDetailValue(string $detailValue): static
|
||||
{
|
||||
$this->detailValue = $detailValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function getRoomCategory(): ?RoomCategory
|
||||
{
|
||||
return $this->roomCategory;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function setRoomCategory(?RoomCategory $roomCategory): static
|
||||
{
|
||||
$this->roomCategory = $roomCategory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\RoomCategoryPhotoRepository;
|
||||
use Symfony\Component\Serializer\Annotation\Ignore;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: RoomCategoryPhotoRepository::class)]
|
||||
class RoomCategoryPhoto
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $path = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $altText = null;
|
||||
|
||||
#[ORM\Column(length: 30)]
|
||||
private ?string $kind = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'roomCategoryPhotos')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[Ignore]
|
||||
private ?RoomCategory $roomCategory = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPath(): ?string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath(string $path): static
|
||||
{
|
||||
$this->path = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAltText(): ?string
|
||||
{
|
||||
return $this->altText;
|
||||
}
|
||||
|
||||
public function setAltText(?string $altText): static
|
||||
{
|
||||
$this->altText = $altText;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getKind(): ?string
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
public function setKind(string $kind): static
|
||||
{
|
||||
$this->kind = $kind;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function getRoomCategory(): ?RoomCategory
|
||||
{
|
||||
return $this->roomCategory;
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public function setRoomCategory(?RoomCategory $roomCategory): static
|
||||
{
|
||||
$this->roomCategory = $roomCategory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\RoomCategoryDetails;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<RoomCategoryDetails>
|
||||
*
|
||||
* @method RoomCategoryDetails|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method RoomCategoryDetails|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method RoomCategoryDetails[] findAll()
|
||||
* @method RoomCategoryDetails[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class RoomCategoryDetailsRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, RoomCategoryDetails::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return RoomCategoryDetails[] Returns an array of RoomCategoryDetails objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('r.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?RoomCategoryDetails
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\RoomCategoryPhoto;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<RoomCategoryPhoto>
|
||||
*
|
||||
* @method RoomCategoryPhoto|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method RoomCategoryPhoto|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method RoomCategoryPhoto[] findAll()
|
||||
* @method RoomCategoryPhoto[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class RoomCategoryPhotoRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, RoomCategoryPhoto::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return RoomCategoryPhoto[] Returns an array of RoomCategoryPhoto objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('r.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?RoomCategoryPhoto
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\RoomCategory;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<RoomCategory>
|
||||
*
|
||||
* @method RoomCategory|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method RoomCategory|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method RoomCategory[] findAll()
|
||||
* @method RoomCategory[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class RoomCategoryRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, RoomCategory::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return RoomCategory[] Returns an array of RoomCategory objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('r.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?RoomCategory
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user