<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\AppointmentController;
use App\Controller\CountAppointmentController;
use App\Repository\AppointmentRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: AppointmentRepository::class)]
#[ApiResource(
collectionOperations:[
'get',
'post',
'countAppointmentsUser' => [
'method' => 'GET',
'path' => '/users/{id}/appointments/count',
'controller' => CountAppointmentController::class,
'openapi_context' => [
'summary' => 'Count Appointments per User',
'parameters' => [
[
'in' => 'query',
'name' => 'id',
'schema' => [
'type' => 'integer'
]
]
],
'response' => [
'200' => [
'description' => 'OK',
'content' => [
'application/json' => [
'schema' => [
'type' => 'integer'
]
]
]
]
]
]
]
],
itemOperations: [
'put',
'delete',
'get' => [
'normalization_context' => ['groups' => ['read:User:collection', 'read:User:item']],
],
'appointementsByUser' => [
'method' => 'GET',
'path' => '/users/{userId}/appointments',
'controller' => AppointmentController::class,
'openapi_context' => [
'summary' => 'Display Appointments per User',
'parameters' => [
[
'in' => 'query',
'name' => 'userId',
'schema' => [
'type' => 'integer'
]
]
]
]
],
],
denormalizationContext: ['groups' => ['read:User:collection', 'write:User']],
normalizationContext: ['groups' => ['read:User:collection']]
)]
class Appointment
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read:User:collection'])]
private ?int $id = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups(['read:User:collection', 'write:User'])]
private ?\DateTimeInterface $appointment_at = null;
#[ORM\Column]
#[Groups(['read:User:collection'])]
private ?\DateTimeImmutable $created_at = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['read:User:collection'])]
private ?\DateTimeInterface $updated_at = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['read:User:item', 'write:User'])]
private ?string $infos_sup = null;
#[ORM\ManyToOne(inversedBy: 'appointments')]
#[Groups(['read:User:item'])]
private ?User $patient = null;
#[ORM\ManyToOne(inversedBy: 'appointments')]
#[Groups(['read:User:item'])]
private ?User $doctor = null;
#[ORM\Column(length: 255)]
#[Groups(['read:User:item', 'write:User', 'read:User:collection'])]
private ?string $status = 'Encours';
public function getId(): ?int
{
return $this->id;
}
public function getAppointmentAt(): ?\DateTimeInterface
{
return $this->appointment_at;
}
public function setAppointmentAt(\DateTimeInterface $appointment_at): static
{
$this->appointment_at = $appointment_at;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): static
{
$this->updated_at = $updated_at;
return $this;
}
public function getInfosSup(): ?string
{
return $this->infos_sup;
}
public function setInfosSup(?string $infos_sup): static
{
$this->infos_sup = $infos_sup;
return $this;
}
public function getPatient(): ?object
{
return $this->patient;
}
public function setPatient(?object $patient): static
{
$this->patient = $patient;
return $this;
}
public function getDoctor(): ?object
{
return $this->doctor;
}
public function setDoctor(?object $doctor): static
{
$this->doctor = $doctor;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
}