Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traçabilité des modifications sur un arrêté #1147

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Application\Regulation\Command;

use App\Application\CommandInterface;
use App\Domain\Regulation\RegulationOrder;
use App\Domain\User\User;

final class CreateRegulationOrderHistoryCommand implements CommandInterface
{
public function __construct(
public RegulationOrder $regulationOrder,
public User $user,
public string $action,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Application\Regulation\Command;

use App\Application\DateUtilsInterface;
use App\Application\IdFactoryInterface;
use App\Domain\Regulation\RegulationOrderHistory;
use App\Domain\Regulation\Repository\RegulationOrderHistoryRepositoryInterface;

final class CreateRegulationOrderHistoryCommandHandler
{
public function __construct(
private IdFactoryInterface $idFactory,
private RegulationOrderHistoryRepositoryInterface $regulationOrderHistoryRepository,
private DateUtilsInterface $dateUtils,
) {
}

public function __invoke(CreateRegulationOrderHistoryCommand $command): RegulationOrderHistory
{
$regulationOrderHistory = $this->regulationOrderHistoryRepository->add(
new RegulationOrderHistory(
uuid: $this->idFactory->make(),
regulationOrderUuid: $command->regulationOrder->getUuid(),
userUuid: $command->user->getUuid(),
florimondmanca marked this conversation as resolved.
Show resolved Hide resolved
action: $command->action,
date: $this->dateUtils->getNow(),
),
);

return $regulationOrderHistory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@

namespace App\Application\Regulation\Command;

use App\Application\CommandBusInterface;
use App\Domain\Regulation\Enum\ActionTypeEnum;
use App\Domain\Regulation\Exception\RegulationOrderRecordCannotBeDeletedException;
use App\Domain\Regulation\Repository\RegulationOrderRepositoryInterface;
use App\Domain\Regulation\Specification\CanOrganizationAccessToRegulation;
use App\Infrastructure\Security\AuthenticatedUser;

final class DeleteRegulationCommandHandler
{
public function __construct(
private RegulationOrderRepositoryInterface $regulationOrderRepository,
private CanOrganizationAccessToRegulation $canOrganizationAccessToRegulation,
private CommandBusInterface $commandBus,
private AuthenticatedUser $authenticatedUser,
) {
}

public function __invoke(DeleteRegulationCommand $command): void
{
$regulationOrderRecord = $command->regulationOrderRecord;
$regulationOrder = $regulationOrderRecord->getRegulationOrder();
$user = $this->authenticatedUser->getUser();

if (false === $this->canOrganizationAccessToRegulation->isSatisfiedBy($regulationOrderRecord, $command->userOrganizationUuids)) {
throw new RegulationOrderRecordCannotBeDeletedException();
}

$this->regulationOrderRepository->delete($regulationOrderRecord->getRegulationOrder());
$action = ActionTypeEnum::DELETE->value;

$this->commandBus->handle(new CreateRegulationOrderHistoryCommand($regulationOrder, $user, $action));
Lealefoulon marked this conversation as resolved.
Show resolved Hide resolved

$this->regulationOrderRepository->delete($regulationOrder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

namespace App\Application\Regulation\Command;

use App\Application\CommandBusInterface;
use App\Domain\Regulation\Enum\ActionTypeEnum;
use App\Domain\Regulation\Enum\RegulationOrderRecordStatusEnum;
use App\Domain\Regulation\Exception\RegulationOrderRecordCannotBePublishedException;
use App\Domain\Regulation\Specification\CanRegulationOrderRecordBePublished;
use App\Infrastructure\Security\AuthenticatedUser;

final class PublishRegulationCommandHandler
{
public function __construct(
private CanRegulationOrderRecordBePublished $canRegulationOrderRecordBePublished,
private CommandBusInterface $commandBus,
private AuthenticatedUser $authenticatedUser,
) {
}

Expand All @@ -21,6 +26,12 @@ public function __invoke(PublishRegulationCommand $command): void
throw new RegulationOrderRecordCannotBePublishedException();
}

$regulationOrder = $command->regulationOrderRecord->getRegulationOrder();
$user = $this->authenticatedUser->getUser();
$action = ActionTypeEnum::PUBLISH->value;

$this->commandBus->handle(new CreateRegulationOrderHistoryCommand($regulationOrder, $user, $action));
Lealefoulon marked this conversation as resolved.
Show resolved Hide resolved

$command->regulationOrderRecord->updateStatus(RegulationOrderRecordStatusEnum::PUBLISHED->value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace App\Application\Regulation\Command;

use App\Application\CommandBusInterface;
use App\Application\IdFactoryInterface;
use App\Application\Organization\VisaModel\Query\GetVisaModelQuery;
use App\Application\QueryBusInterface;
use App\Domain\Regulation\Enum\ActionTypeEnum;
use App\Domain\Regulation\Enum\RegulationOrderRecordStatusEnum;
use App\Domain\Regulation\RegulationOrder;
use App\Domain\Regulation\RegulationOrderRecord;
use App\Domain\Regulation\Repository\RegulationOrderRecordRepositoryInterface;
use App\Domain\Regulation\Repository\RegulationOrderRepositoryInterface;
use App\Infrastructure\Security\AuthenticatedUser;

final class SaveRegulationGeneralInfoCommandHandler
{
Expand All @@ -21,11 +24,14 @@ public function __construct(
private RegulationOrderRecordRepositoryInterface $regulationOrderRecordRepository,
private \DateTimeInterface $now,
private QueryBusInterface $queryBus,
private CommandBusInterface $commandBus,
private AuthenticatedUser $authenticatedUser,
Lealefoulon marked this conversation as resolved.
Show resolved Hide resolved
) {
}

public function __invoke(SaveRegulationGeneralInfoCommand $command): RegulationOrderRecord
{
$user = $this->authenticatedUser->getUser();
$command->cleanOtherCategoryText();
$visaModel = $command->visaModelUuid
? $this->queryBus->handle(new GetVisaModelQuery($command->visaModelUuid))
Expand Down Expand Up @@ -57,11 +63,18 @@ public function __invoke(SaveRegulationGeneralInfoCommand $command): RegulationO
),
);

$action = ActionTypeEnum::CREATE->value;

$this->commandBus->handle(new CreateRegulationOrderHistoryCommand($regulationOrder, $user, $action));
Lealefoulon marked this conversation as resolved.
Show resolved Hide resolved

return $regulationOrderRecord;
}

$command->regulationOrderRecord->updateOrganization($command->organization);
$command->regulationOrderRecord->getRegulationOrder()->update(

$regulationOrder = $command->regulationOrderRecord->getRegulationOrder();

$regulationOrder->update(
identifier: $command->identifier,
category: $command->category,
subject: $command->subject,
Expand All @@ -72,6 +85,10 @@ public function __invoke(SaveRegulationGeneralInfoCommand $command): RegulationO
visaModel: $visaModel,
);

$action = ActionTypeEnum::UPDATE->value;

$this->commandBus->handle(new CreateRegulationOrderHistoryCommand($regulationOrder, $user, $action));
Lealefoulon marked this conversation as resolved.
Show resolved Hide resolved

return $command->regulationOrderRecord;
}
}
13 changes: 13 additions & 0 deletions src/Domain/Regulation/Enum/ActionTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Domain\Regulation\Enum;

enum ActionTypeEnum: string
{
case CREATE = 'create';
case UPDATE = 'update';
case PUBLISH = 'publish';
case DELETE = 'delete';
}
42 changes: 42 additions & 0 deletions src/Domain/Regulation/RegulationOrderHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\Domain\Regulation;

class RegulationOrderHistory
{
public function __construct(
private string $uuid,
private string $regulationOrderUuid,
private string $userUuid,
private string $action,
private \DateTimeInterface $date,
) {
}

public function getUuid(): string
{
return $this->uuid;
}

public function getRegulationOrderUuid(): string
{
return $this->regulationOrderUuid;
}

public function getUserUuid(): string
{
return $this->userUuid;
}

public function getAction(): string
{
return $this->action;
}

public function getDate(): \DateTimeInterface
{
return $this->date;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Domain\Regulation\Repository;

use App\Domain\Regulation\RegulationOrderHistory;

interface RegulationOrderHistoryRepositoryInterface
{
public function add(RegulationOrderHistory $regulationOrderHistory): RegulationOrderHistory;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity
name="App\Domain\Regulation\RegulationOrderHistory"
table="regulation_order_history">
<indexes>
<index columns="regulation_order_uuid"/>
<index columns="user_uuid"/>
</indexes>
<id name="uuid" type="guid" column="uuid"/>
<field name="regulationOrderUuid" type="string" column="regulation_order_uuid" length="50" nullable="false"/>
<field name="userUuid" type="string" column="user_uuid" length="50" nullable="false"/>
<field name="action" type="string" column="action" length="20" nullable="false"/>
<field name="date" type="datetimetz" column="date" nullable="false">
<options>
<option name="default">CURRENT_TIMESTAMP</option>
</options>
</field>
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace App\Infrastructure\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250116114330 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 TABLE regulation_order_history (uuid UUID NOT NULL, regulation_order_uuid VARCHAR(50) NOT NULL, user_uuid VARCHAR(50) NOT NULL, action VARCHAR(20) NOT NULL, date TIMESTAMP(0) WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY(uuid))');
$this->addSql('CREATE INDEX IDX_E47F415B267E0D5E ON regulation_order_history (regulation_order_uuid)');
$this->addSql('CREATE INDEX IDX_E47F415BABFE1C6F ON regulation_order_history (user_uuid)');
}

public function down(Schema $schema): void
{
$this->addSql('DROP TABLE regulation_order_history');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Infrastructure\Persistence\Doctrine\Repository\Regulation;

use App\Domain\Regulation\RegulationOrderHistory;
use App\Domain\Regulation\Repository\RegulationOrderHistoryRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

final class RegulationOrderHistoryRepository extends ServiceEntityRepository implements RegulationOrderHistoryRepositoryInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, RegulationOrderHistory::class);
}

public function add(RegulationOrderHistory $regulationOrderHistory): RegulationOrderHistory
{
$this->getEntityManager()->persist($regulationOrderHistory);

return $regulationOrderHistory;
}
}
Loading
Loading