refs #725. Added RemoteCalendar and RemoteCalendarRule APIs
parent
bdd5093a6a
commit
083ac514a8
|
@ -0,0 +1,31 @@
|
|||
resources:
|
||||
App\Entity\RemoteCalendar:
|
||||
processor: App\State\Processor\RemoteCalendarProcessor
|
||||
input: App\Dto\Input\RemoteCalendarInput
|
||||
output: App\Dto\Output\RemoteCalendarOutput
|
||||
normalizationContext:
|
||||
groups: ['default', 'remote-calendar:read']
|
||||
denormalizationContext:
|
||||
groups: ['remote-calendar:write']
|
||||
operations:
|
||||
ApiPlatform\Metadata\GetCollection:
|
||||
provider: App\State\Provider\RemoteCalendarProvider
|
||||
filters:
|
||||
- 'api_platform.filter.remote_calendar.order'
|
||||
- 'api_platform.filter.remote_calendar.search'
|
||||
|
||||
ApiPlatform\Metadata\Get:
|
||||
provider: App\State\Provider\RemoteCalendarProvider
|
||||
ApiPlatform\Metadata\Put:
|
||||
provider: App\State\Provider\RemoteCalendarProvider
|
||||
ApiPlatform\Metadata\Patch:
|
||||
provider: App\State\Provider\RemoteCalendarProvider
|
||||
ApiPlatform\Metadata\Post: ~
|
||||
ApiPlatform\Metadata\Delete: ~
|
||||
|
||||
properties:
|
||||
App\Entity\RemoteCalendar:
|
||||
id:
|
||||
identifier: false
|
||||
uuid:
|
||||
identifier: true
|
|
@ -0,0 +1,31 @@
|
|||
resources:
|
||||
App\Entity\RemoteCalendarRule:
|
||||
processor: App\State\Processor\RemoteCalendarRuleProcessor
|
||||
input: App\Dto\Input\RemoteCalendarRuleInput
|
||||
output: App\Dto\Output\RemoteCalendarRuleOutput
|
||||
normalizationContext:
|
||||
groups: ['default', 'remote-calendar-rule:read']
|
||||
denormalizationContext:
|
||||
groups: ['remote-calendar-rule:write']
|
||||
operations:
|
||||
ApiPlatform\Metadata\GetCollection:
|
||||
provider: App\State\Provider\RemoteCalendarRuleProvider
|
||||
filters:
|
||||
- 'api_platform.filter.remote_calendar_rule.order'
|
||||
- 'api_platform.filter.remote_calendar_rule.search'
|
||||
|
||||
ApiPlatform\Metadata\Get:
|
||||
provider: App\State\Provider\RemoteCalendarRuleProvider
|
||||
ApiPlatform\Metadata\Put:
|
||||
provider: App\State\Provider\RemoteCalendarRuleProvider
|
||||
ApiPlatform\Metadata\Patch:
|
||||
provider: App\State\Provider\RemoteCalendarRuleProvider
|
||||
ApiPlatform\Metadata\Post: ~
|
||||
ApiPlatform\Metadata\Delete: ~
|
||||
|
||||
properties:
|
||||
App\Entity\RemoteCalendarRule:
|
||||
id:
|
||||
identifier: false
|
||||
uuid:
|
||||
identifier: true
|
|
@ -101,3 +101,13 @@ services:
|
|||
bind:
|
||||
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
|
||||
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
|
||||
|
||||
App\State\Provider\RemoteCalendarProvider:
|
||||
bind:
|
||||
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
|
||||
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
|
||||
|
||||
App\State\Provider\RemoteCalendarRuleProvider:
|
||||
bind:
|
||||
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
|
||||
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240924095558 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_from_hour busy_from_hour TIME NOT NULL, CHANGE busy_to_hour busy_to_hour TIME NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_from_hour busy_from_hour DATETIME NOT NULL, CHANGE busy_to_hour busy_to_hour DATETIME NOT NULL');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240924100335 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON remote_calendar (name)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON remote_calendar');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240924102357 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_weekdays busy_weekdays JSON DEFAULT NULL COMMENT \'(DC2Type:json)\', CHANGE busy_from_hour busy_from_hour TIME DEFAULT NULL, CHANGE busy_to_hour busy_to_hour TIME DEFAULT NULL, CHANGE available_from_date available_from_date DATE DEFAULT NULL, CHANGE available_to_date available_to_date DATE DEFAULT NULL, CHANGE available_reason available_reason VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE remote_calendar_rule CHANGE busy_weekdays busy_weekdays JSON NOT NULL COMMENT \'(DC2Type:json)\', CHANGE busy_from_hour busy_from_hour TIME NOT NULL, CHANGE busy_to_hour busy_to_hour TIME NOT NULL, CHANGE available_from_date available_from_date DATE NOT NULL, CHANGE available_to_date available_to_date DATE NOT NULL, CHANGE available_reason available_reason VARCHAR(255) NOT NULL');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Dto\Output\RemoteCalendarRuleOutput;
|
||||
use App\Entity\RemoteCalendar;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class RemoteCalendarInput
|
||||
{
|
||||
#[Groups(['remote-calendar:write'])]
|
||||
#[ApiProperty(description: 'The name of the remote calendar', example: "calendar")]
|
||||
public ?string $name = null;
|
||||
|
||||
/**
|
||||
* @var RemoteCalendarRuleOutput[]
|
||||
*/
|
||||
#[Groups(['remote-calendar:write'])]
|
||||
#[ApiProperty(readableLink: false, writableLink: false)]
|
||||
public array $remoteCalendarRules = [];
|
||||
|
||||
public function __construct(?RemoteCalendar $remoteCalendar = null)
|
||||
{
|
||||
if (!$remoteCalendar) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->name = $remoteCalendar->getName();
|
||||
|
||||
if ($remoteCalendar->getRules()) {
|
||||
foreach ($remoteCalendar->getRules() as $rule) {
|
||||
$this->remoteCalendarRules[] = new RemoteCalendarRuleOutput($rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function createOrUpdateEntity(?RemoteCalendar $remoteCalendar = null): RemoteCalendar
|
||||
{
|
||||
if (!$remoteCalendar) {
|
||||
$remoteCalendar = new RemoteCalendar();
|
||||
}
|
||||
|
||||
$remoteCalendar->setName($this->name);
|
||||
|
||||
foreach ($this->remoteCalendarRules as $rule) {
|
||||
$ruleToAdd[] = $rule->getEntity();
|
||||
}
|
||||
|
||||
$remoteCalendar->setRules( $ruleToAdd ?? [] );
|
||||
|
||||
return $remoteCalendar;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Dto\Output\RemoteCalendarOutput;
|
||||
use App\Entity\RemoteCalendarRule;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class RemoteCalendarRuleInput
|
||||
{
|
||||
#[Assert\NotNull()]
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The remote calendar of the remote calendar rule')]
|
||||
public ?RemoteCalendarOutput $remoteCalendar = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The busy week days of the remote calendar rule', example: [1, 2, 3])]
|
||||
public ?array $busyWeekDays = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The busy from hour of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
|
||||
public ?string $busyFromHour = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The busy to hour of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
|
||||
public ?string $busyToHour = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The remote availability of the remote calendar rule', example: true)]
|
||||
public ?bool $isRemoteAvailable = false;
|
||||
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The available from date of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
|
||||
public ?\DateTimeInterface $availableFromDate = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The available to date of the remote calendar rule', example: "2021-10-10T10:00:00+00:00")]
|
||||
public ?\DateTimeInterface $availableToDate = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:write'])]
|
||||
#[ApiProperty(description: 'The reason of the remote calendar rule', example: "reason")]
|
||||
public ?string $availableReason = null;
|
||||
|
||||
public function __construct(?RemoteCalendarRule $remoteCalendarRule = null)
|
||||
{
|
||||
if (!$remoteCalendarRule) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->remoteCalendar = new RemoteCalendarOutput($remoteCalendarRule->getRemoteCalendar());
|
||||
$this->busyWeekDays = $remoteCalendarRule->getBusyWeekDays();
|
||||
$this->busyFromHour = $remoteCalendarRule->getBusyFromHour();
|
||||
$this->busyToHour = $remoteCalendarRule->getBusyToHour();
|
||||
$this->isRemoteAvailable = $remoteCalendarRule->isRemoteAvailable();
|
||||
$this->availableFromDate = $remoteCalendarRule->getAvailableFromDate();
|
||||
$this->availableToDate = $remoteCalendarRule->getAvailableToDate();
|
||||
$this->availableReason = $remoteCalendarRule->getAvailableReason();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createOrUpdateEntity(?RemoteCalendarRule $remoteCalendarRule = null): RemoteCalendarRule
|
||||
{
|
||||
if (!$remoteCalendarRule) {
|
||||
$remoteCalendarRule = new RemoteCalendarRule();
|
||||
}
|
||||
|
||||
$remoteCalendarRule->setRemoteCalendar($this->remoteCalendar->getEntity());
|
||||
$remoteCalendarRule->setBusyWeekDays($this->busyWeekDays);
|
||||
$remoteCalendarRule->setBusyFromHour($this->busyFromHour);
|
||||
$remoteCalendarRule->setBusyToHour($this->busyToHour);
|
||||
$remoteCalendarRule->setRemoteAvailable($this->isRemoteAvailable);
|
||||
$remoteCalendarRule->setAvailableFromDate($this->availableFromDate);
|
||||
$remoteCalendarRule->setAvailableToDate($this->availableToDate);
|
||||
$remoteCalendarRule->setAvailableReason($this->availableReason);
|
||||
|
||||
return $remoteCalendarRule;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Output;
|
||||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Entity\RemoteCalendar;
|
||||
use App\Entity\RemoteCalendarRule;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
#[Get(shortName: 'RemoteCalendar')]
|
||||
final class RemoteCalendarOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['remote-calendar:read'])]
|
||||
public ?string $name = null;
|
||||
|
||||
/**
|
||||
* @var RemoteCalendarRuleOutput[]
|
||||
*/
|
||||
#[Groups(['remote-calendar:read'])]
|
||||
public array $remoteCalendarRules = [];
|
||||
|
||||
public function __construct(RemoteCalendar $remoteCalendar)
|
||||
{
|
||||
parent::__construct($remoteCalendar);
|
||||
|
||||
$this->name = $remoteCalendar->getName();
|
||||
|
||||
$this->remoteCalendarRules = $remoteCalendar->getRules()->map(
|
||||
fn(RemoteCalendarRule $rule) => new RemoteCalendarRuleOutput($rule)
|
||||
)->toArray();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Output;
|
||||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Entity\RemoteCalendarRule;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
#[Get(shortName: 'RemoteCalendarRule')]
|
||||
final class RemoteCalendarRuleOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
|
||||
public ?array $busyWeekDays = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
|
||||
public ?string $busyFromHour = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
|
||||
public ?string $busyToHour = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
|
||||
public ?bool $isRemoteAvailable = false;
|
||||
|
||||
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
|
||||
public ?\DateTimeInterface $availableFromDate = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
|
||||
public ?\DateTimeInterface $availableToDate = null;
|
||||
|
||||
#[Groups(['remote-calendar-rule:read', 'remote-calendar:read'])]
|
||||
public ?string $availableReason = null;
|
||||
|
||||
public function __construct(RemoteCalendarRule $remoteCalendarRule)
|
||||
{
|
||||
parent::__construct($remoteCalendarRule);
|
||||
|
||||
$this->busyWeekDays = $remoteCalendarRule->getBusyWeekDays();
|
||||
$this->busyFromHour = $remoteCalendarRule->getBusyFromHour();
|
||||
$this->busyToHour = $remoteCalendarRule->getBusyToHour();
|
||||
$this->isRemoteAvailable = $remoteCalendarRule->isRemoteAvailable();
|
||||
$this->availableFromDate = $remoteCalendarRule->getAvailableFromDate();
|
||||
$this->availableToDate = $remoteCalendarRule->getAvailableToDate();
|
||||
$this->availableReason = $remoteCalendarRule->getAvailableReason();
|
||||
}
|
||||
}
|
|
@ -6,8 +6,11 @@ use App\Repository\RemoteCalendarRepository;
|
|||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
|
||||
#[ORM\Entity(repositoryClass: RemoteCalendarRepository::class)]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_NAME', fields: ['name'])]
|
||||
#[UniqueEntity(fields: ['name'], message: 'This name is already in use.')]
|
||||
class RemoteCalendar extends AbstractEntity
|
||||
{
|
||||
use NameableTrait;
|
||||
|
@ -48,6 +51,17 @@ class RemoteCalendar extends AbstractEntity
|
|||
return $this->rules;
|
||||
}
|
||||
|
||||
public function setRules(array $rules): static
|
||||
{
|
||||
$this->rules->clear();
|
||||
|
||||
foreach ($rules as $rule){
|
||||
$this->addRule($rule);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addRule(RemoteCalendarRule $rule): static
|
||||
{
|
||||
if (!$this->rules->contains($rule)) {
|
||||
|
|
|
@ -12,25 +12,25 @@ class RemoteCalendarRule extends AbstractEntity
|
|||
#[ORM\ManyToOne(inversedBy: 'rules')]
|
||||
private ?RemoteCalendar $remoteCalendar = null;
|
||||
|
||||
#[ORM\Column(type: Types::JSON)]
|
||||
#[ORM\Column(type: Types::JSON, nullable: true)]
|
||||
private array $busyWeekdays = [];
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
||||
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
|
||||
private ?\DateTimeInterface $busyFromHour = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
||||
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
|
||||
private ?\DateTimeInterface $busyToHour = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $isRemoteAvailable = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
||||
private ?\DateTimeInterface $availableFromDate = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
||||
private ?\DateTimeInterface $availableToDate = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $availableReason = null;
|
||||
|
||||
public function getBusyWeekdays(): array
|
||||
|
@ -38,33 +38,39 @@ class RemoteCalendarRule extends AbstractEntity
|
|||
return $this->busyWeekdays;
|
||||
}
|
||||
|
||||
public function setBusyWeekdays(array $busyWeekdays): static
|
||||
public function setBusyWeekdays(?array $busyWeekdays): static
|
||||
{
|
||||
$this->busyWeekdays = $busyWeekdays;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBusyFromHour(): ?\DateTimeInterface
|
||||
public function getBusyFromHour(): string
|
||||
{
|
||||
return $this->busyFromHour;
|
||||
return $this->busyFromHour->format('H:i');
|
||||
}
|
||||
|
||||
public function setBusyFromHour(\DateTimeInterface $busyFromHour): static
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setBusyFromHour(?string $busyFromHour): static
|
||||
{
|
||||
$this->busyFromHour = $busyFromHour;
|
||||
$this->busyFromHour = new \DateTimeImmutable($busyFromHour);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBusyToHour(): ?\DateTimeInterface
|
||||
public function getBusyToHour(): string
|
||||
{
|
||||
return $this->busyToHour;
|
||||
return $this->busyToHour->format('H:i');
|
||||
}
|
||||
|
||||
public function setBusyToHour(\DateTimeInterface $busyToHour): static
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setBusyToHour(?string $busyToHour): static
|
||||
{
|
||||
$this->busyToHour = $busyToHour;
|
||||
$this->busyToHour = new \DateTimeImmutable($busyToHour);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -86,7 +92,7 @@ class RemoteCalendarRule extends AbstractEntity
|
|||
return $this->availableFromDate;
|
||||
}
|
||||
|
||||
public function setAvailableFromDate(\DateTimeInterface $availableFromDate): static
|
||||
public function setAvailableFromDate(?\DateTimeInterface $availableFromDate): static
|
||||
{
|
||||
$this->availableFromDate = $availableFromDate;
|
||||
|
||||
|
@ -98,7 +104,7 @@ class RemoteCalendarRule extends AbstractEntity
|
|||
return $this->availableToDate;
|
||||
}
|
||||
|
||||
public function setAvailableToDate(\DateTimeInterface $availableToDate): static
|
||||
public function setAvailableToDate(?\DateTimeInterface $availableToDate): static
|
||||
{
|
||||
$this->availableToDate = $availableToDate;
|
||||
|
||||
|
@ -110,7 +116,7 @@ class RemoteCalendarRule extends AbstractEntity
|
|||
return $this->availableReason;
|
||||
}
|
||||
|
||||
public function setAvailableReason(string $availableReason): static
|
||||
public function setAvailableReason(?string $availableReason): static
|
||||
{
|
||||
$this->availableReason = $availableReason;
|
||||
|
||||
|
|
|
@ -9,35 +9,10 @@ use Doctrine\Persistence\ManagerRegistry;
|
|||
/**
|
||||
* @extends ServiceEntityRepository<RemoteCalendar>
|
||||
*/
|
||||
class RemoteCalendarRepository extends ServiceEntityRepository
|
||||
class RemoteCalendarRepository extends AbstractRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, RemoteCalendar::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return RemoteCalendar[] Returns an array of RemoteCalendar 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): ?RemoteCalendar
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -9,35 +9,10 @@ use Doctrine\Persistence\ManagerRegistry;
|
|||
/**
|
||||
* @extends ServiceEntityRepository<RemoteCalendarRule>
|
||||
*/
|
||||
class RemoteCalendarRuleRepository extends ServiceEntityRepository
|
||||
class RemoteCalendarRuleRepository extends AbstractRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, RemoteCalendarRule::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return RemoteCalendarRule[] Returns an array of RemoteCalendarRule 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): ?RemoteCalendarRule
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\State\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use ApiPlatform\Validator\ValidatorInterface;
|
||||
use App\Dto\Input\RemoteCalendarInput;
|
||||
use App\Dto\Output\RemoteCalendarOutput;
|
||||
use App\Repository\RemoteCalendarRepository;
|
||||
|
||||
readonly class RemoteCalendarProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private RemoteCalendarRepository $remoteCalendarRepository,
|
||||
private ValidatorInterface $validator
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarOutput|null
|
||||
{
|
||||
switch ($operation){
|
||||
case $operation instanceof Post:
|
||||
case $operation instanceof Put:
|
||||
case $operation instanceof Patch:
|
||||
return $this->processCreateOrUpdate($data, $operation, $uriVariables, $context);
|
||||
case $operation instanceof Delete:
|
||||
return $this->processDelete($data, $operation, $uriVariables, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarOutput
|
||||
{
|
||||
if (!($data instanceof RemoteCalendarInput)) {
|
||||
throw new \Exception(sprintf('data is not instance of %s', RemoteCalendarInput::class));
|
||||
}
|
||||
|
||||
$entity = null;
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$entity = $this->remoteCalendarRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$partition = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($partition);
|
||||
$this->remoteCalendarRepository->save($partition);
|
||||
|
||||
return new RemoteCalendarOutput($partition);
|
||||
}
|
||||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
{
|
||||
$user = $this->remoteCalendarRepository->findOneByUuid($uriVariables['uuid']);
|
||||
$this->remoteCalendarRepository->delete($user);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\State\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use ApiPlatform\Validator\ValidatorInterface;
|
||||
use App\Dto\Input\RemoteCalendarRuleInput;
|
||||
use App\Dto\Output\RemoteCalendarRuleOutput;
|
||||
use App\Repository\RemoteCalendarRuleRepository;
|
||||
|
||||
readonly class RemoteCalendarRuleProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private RemoteCalendarRuleRepository $remoteCalendarRuleRepository,
|
||||
private ValidatorInterface $validator
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarRuleOutput|null
|
||||
{
|
||||
switch ($operation){
|
||||
case $operation instanceof Post:
|
||||
case $operation instanceof Put:
|
||||
case $operation instanceof Patch:
|
||||
return $this->processCreateOrUpdate($data, $operation, $uriVariables, $context);
|
||||
case $operation instanceof Delete:
|
||||
return $this->processDelete($data, $operation, $uriVariables, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): RemoteCalendarRuleOutput
|
||||
{
|
||||
if (!($data instanceof RemoteCalendarRuleInput)) {
|
||||
throw new \Exception(sprintf('data is not instance of %s', RemoteCalendarRuleInput::class));
|
||||
}
|
||||
|
||||
$entity = null;
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$entity = $this->remoteCalendarRuleRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$partition = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($partition);
|
||||
$this->remoteCalendarRuleRepository->save($partition);
|
||||
|
||||
return new RemoteCalendarRuleOutput($partition);
|
||||
}
|
||||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
{
|
||||
$user = $this->remoteCalendarRuleRepository->findOneByUuid($uriVariables['uuid']);
|
||||
$this->remoteCalendarRuleRepository->delete($user);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use ApiPlatform\State\Pagination\TraversablePaginator;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Dto\Input\RemoteCalendarInput;
|
||||
use App\Dto\Output\RemoteCalendarOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
readonly class RemoteCalendarProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
switch ($operation){
|
||||
case $operation instanceof GetCollection:
|
||||
return $this->provideCollection($operation, $uriVariables, $context);
|
||||
case $operation instanceof Patch:
|
||||
case $operation instanceof Put:
|
||||
return $this->provideInput($operation, $uriVariables, $context);
|
||||
case $operation instanceof Get:
|
||||
return $this->provideItem($operation, $uriVariables, $context);
|
||||
}
|
||||
}
|
||||
|
||||
private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object
|
||||
{
|
||||
$paginator = $this->collectionProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
$items = new \ArrayObject();
|
||||
foreach ($paginator->getIterator() as $item){
|
||||
$items[] = new RemoteCalendarOutput($item);
|
||||
}
|
||||
|
||||
return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems());
|
||||
}
|
||||
|
||||
public function provideItem(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
if (!$item) {
|
||||
throw new NotFoundHttpException('RemoteCalendar not found');
|
||||
}
|
||||
|
||||
return new RemoteCalendarOutput($item);
|
||||
}
|
||||
|
||||
public function provideInput(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
return $item !== null ? new RemoteCalendarInput($item) : null;
|
||||
}
|
||||
|
||||
return new RemoteCalendarInput();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use ApiPlatform\State\Pagination\TraversablePaginator;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Dto\Input\RemoteCalendarRuleInput;
|
||||
use App\Dto\Output\RemoteCalendarRuleOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
readonly class RemoteCalendarRuleProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
switch ($operation){
|
||||
case $operation instanceof GetCollection:
|
||||
return $this->provideCollection($operation, $uriVariables, $context);
|
||||
case $operation instanceof Patch:
|
||||
case $operation instanceof Put:
|
||||
return $this->provideInput($operation, $uriVariables, $context);
|
||||
case $operation instanceof Get:
|
||||
return $this->provideItem($operation, $uriVariables, $context);
|
||||
}
|
||||
}
|
||||
|
||||
private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object
|
||||
{
|
||||
$paginator = $this->collectionProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
$items = new \ArrayObject();
|
||||
foreach ($paginator->getIterator() as $item){
|
||||
$items[] = new RemoteCalendarRuleOutput($item);
|
||||
}
|
||||
|
||||
return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems());
|
||||
}
|
||||
|
||||
public function provideItem(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
if (!$item) {
|
||||
throw new NotFoundHttpException('RemoteCalendarRule not found');
|
||||
}
|
||||
|
||||
return new RemoteCalendarRuleOutput($item);
|
||||
}
|
||||
|
||||
public function provideInput(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
return $item !== null ? new RemoteCalendarRuleInput($item) : null;
|
||||
}
|
||||
|
||||
return new RemoteCalendarRuleInput();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue