refs #436. Change parent ou
parent
e4e9e3c07f
commit
8e8947cdfa
|
@ -3,10 +3,13 @@
|
|||
namespace App\Controller;
|
||||
|
||||
use App\Dto\Input\OrganizationalUnitInput;
|
||||
use App\Dto\Output\OrganizationalUnitOutput;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Handler\OrganizationalUnitChangeParentHandler;
|
||||
use App\Repository\OrganizationalUnitRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class OrganizationalUnitChangeParentAction extends AbstractController
|
||||
{
|
||||
|
@ -17,10 +20,10 @@ class OrganizationalUnitChangeParentAction extends AbstractController
|
|||
|
||||
}
|
||||
|
||||
public function __invoke(OrganizationalUnit $organizationalUnit): OrganizationalUnitInput
|
||||
public function __invoke(OrganizationalUnit $organizationalUnit): JsonResponse
|
||||
{
|
||||
$this->organizationalUnitChangeParentHandler->handle($organizationalUnit);
|
||||
|
||||
return new OrganizationalUnitInput($organizationalUnit);
|
||||
return new JsonResponse(data: 'Organizational unit parent changed successfully', status: Response::HTTP_OK);
|
||||
}
|
||||
}
|
|
@ -31,6 +31,9 @@ final class ClientOutput extends AbstractOutput
|
|||
#[Groups(['client:read'])]
|
||||
public ?string $netiface = '';
|
||||
|
||||
#[Groups(['client:read'])]
|
||||
public ?string $netDriver = '';
|
||||
|
||||
#[Groups(['client:read'])]
|
||||
#[ApiProperty(readableLink: true)]
|
||||
public ?OrganizationalUnitOutput $organizationalUnit = null;
|
||||
|
@ -60,6 +63,7 @@ final class ClientOutput extends AbstractOutput
|
|||
$this->mac = $client->getMac();
|
||||
$this->ip = $client->getIp();
|
||||
$this->netiface = $client->getNetiface();
|
||||
$this->netDriver = $client->getNetDriver();
|
||||
|
||||
if ($client->getOrganizationalUnit()) {
|
||||
$this->organizationalUnit = new OrganizationalUnitOutput($client->getOrganizationalUnit());
|
||||
|
|
|
@ -11,7 +11,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
#[Get(shortName: 'HardwareProfile')]
|
||||
final class HardwareProfileOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['hardware-profile:read', 'client:read'])]
|
||||
#[Groups(['hardware-profile:read', 'client:read', 'organizational-unit:read'])]
|
||||
public ?string $description = '';
|
||||
|
||||
#[Groups(['hardware-profile:read'])]
|
||||
|
|
|
@ -45,7 +45,7 @@ final class NetworkSettingsOutput extends AbstractOutput
|
|||
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
|
||||
public ?MenuOutput $menu = null;
|
||||
|
||||
#[Groups(['organizational-unit:read'])]
|
||||
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
|
||||
public ?HardwareProfileOutput $hardwareProfile = null;
|
||||
|
||||
#[Groups(['network-settings:read', "organizational-unit:read", "client:read"])]
|
||||
|
|
|
@ -17,6 +17,9 @@ final class OrganizationalUnitOutput extends AbstractOutput
|
|||
#[Groups(['organizational-unit:read'])]
|
||||
public ?string $comments = null;
|
||||
|
||||
#[Groups(['organizational-unit:read'])]
|
||||
public ?string $description = null;
|
||||
|
||||
#[Groups(['organizational-unit:read'])]
|
||||
public ?string $location = null;
|
||||
|
||||
|
@ -60,6 +63,7 @@ final class OrganizationalUnitOutput extends AbstractOutput
|
|||
|
||||
$this->name = $organizationalUnit->getName();
|
||||
$this->comments = $organizationalUnit->getComments();
|
||||
$this->description = $organizationalUnit->getDescription();
|
||||
$this->location = $organizationalUnit->getLocation();
|
||||
$this->projector = $organizationalUnit->isProjector();
|
||||
$this->board = $organizationalUnit->isBoard();
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
namespace App\Handler;
|
||||
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Repository\ClientRepository;
|
||||
use App\Repository\OrganizationalUnitRepository;
|
||||
|
||||
readonly class OrganizationalUnitChangeParentHandler
|
||||
{
|
||||
public function __construct(
|
||||
private OrganizationalUnitRepository $organizationalUnitRepository
|
||||
private OrganizationalUnitRepository $organizationalUnitRepository,
|
||||
private ClientRepository $clientRepository
|
||||
)
|
||||
{
|
||||
}
|
||||
|
@ -23,7 +25,7 @@ readonly class OrganizationalUnitChangeParentHandler
|
|||
|
||||
foreach ($organizationalUnit->getClients() as $client) {
|
||||
$client->setOrganizationalUnit($parent);
|
||||
$this->organizationalUnitRepository->save($client);
|
||||
$this->clientRepository->save($client);
|
||||
}
|
||||
|
||||
$this->organizationalUnitRepository->delete($organizationalUnit);
|
||||
|
|
|
@ -24,7 +24,7 @@ abstract class AbstractRepository extends ServiceEntityRepository
|
|||
}
|
||||
}
|
||||
|
||||
public function delete (AbstractEntity $entity, bool $flush = true): void
|
||||
public function delete(AbstractEntity $entity, bool $flush = true): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
|
||||
|
|
Loading…
Reference in New Issue