refs #723. Updated CommandTask. Added clients

feature/actions
Manuel Aranda Rosales 2024-09-27 12:43:38 +02:00
parent 04cee6c4c0
commit 4ff77d7e2b
4 changed files with 75 additions and 1 deletions

View File

@ -8,7 +8,7 @@ services:
api_platform.filter.client.search:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'id': 'exact', 'name': 'partial', 'serialNumber': 'exact', organizationalUnit.id: 'exact' } ]
arguments: [ { 'id': 'exact', 'name': 'partial', 'serialNumber': 'exact', organizationalUnit.id: 'exact', mac: 'exact', ip: 'exact' } ]
tags: [ 'api_platform.filter' ]
api_platform.filter.command.order:

View File

@ -3,6 +3,7 @@
namespace App\Dto\Input;
use ApiPlatform\Metadata\ApiProperty;
use App\Dto\Output\ClientOutput;
use App\Dto\Output\CommandGroupOutput;
use App\Dto\Output\CommandOutput;
use App\Entity\CommandTask;
@ -33,6 +34,16 @@ final class CommandTaskInput
)]
public array $commandGroups = [];
/**
* @var ClientOutput[]
*/
#[Groups(['command-task:write'])]
#[ApiProperty(
description: 'Los clientes de la tarea',
example: 'Clientes de la tarea',
)]
public array $clients = [];
#[Assert\NotBlank(message: 'validators.command_task.datetime.not_blank')]
#[Groups(['command-task:write'])]
#[ApiProperty(
@ -66,6 +77,12 @@ final class CommandTaskInput
}
}
if ($commandTask->getClients()) {
foreach ($commandTask->getClients() as $client) {
$this->clients[] = new ClientOutput($client);
}
}
$this->dateTime = $commandTask->getDatetime();
$this->notes = $commandTask->getNotes();
}
@ -87,6 +104,13 @@ final class CommandTaskInput
}
$commandTask->setCommandGroups( $commandGroupsToAdd ?? [] );
foreach ($this->clients as $client) {
$clientsToAdd[] = $client->getEntity();
}
$commandTask->setClients( $clientsToAdd ?? [] );
$commandTask->setDatetime($this->dateTime);
$commandTask->setStatus(CommandTaskStatus::PENDING);
$commandTask->setNotes($this->notes);

View File

@ -3,6 +3,7 @@
namespace App\Dto\Output;
use ApiPlatform\Metadata\Get;
use App\Entity\Client;
use App\Entity\Command;
use App\Entity\CommandGroup;
use App\Entity\CommandTask;
@ -17,6 +18,9 @@ final class CommandTaskOutput extends AbstractOutput
#[Groups(['command-task:read'])]
public array $commandGroups = [];
#[Groups(['command-task:read'])]
public array $clients = [];
#[Groups(['command-task:read'])]
public \DateTimeInterface $dateTime;
@ -45,6 +49,10 @@ final class CommandTaskOutput extends AbstractOutput
fn(CommandGroup $commandGroup) => new CommandGroupOutput($commandGroup)
)->toArray();
$this->clients = $commandTask->getClients()->map(
fn(Client $client) => new ClientOutput($client)
)->toArray();
$this->dateTime = $commandTask->getDateTime();
$this->notes = $commandTask->getNotes();
$this->status = $commandTask->getStatus();

View File

@ -32,12 +32,19 @@ class CommandTask extends AbstractEntity
#[ORM\Column(length: 255)]
private ?string $status = null;
/**
* @var Collection<int, Client>
*/
#[ORM\ManyToMany(targetEntity: Client::class)]
private Collection $clients;
public function __construct()
{
parent::__construct();
$this->commands = new ArrayCollection();
$this->commandGroups = new ArrayCollection();
$this->clients = new ArrayCollection();
}
/**
@ -145,4 +152,39 @@ class CommandTask extends AbstractEntity
return $this;
}
/**
* @return Collection<int, Client>
*/
public function getClients(): Collection
{
return $this->clients;
}
public function addClient(Client $client): static
{
if (!$this->clients->contains($client)) {
$this->clients->add($client);
}
return $this;
}
public function removeClient(Client $client): static
{
$this->clients->removeElement($client);
return $this;
}
public function setClients(array $clients): static
{
$this->clients->clear();
foreach ($clients as $client){
$this->addClient($client);
}
return $this;
}
}