feat: Permettre aux enseignants de dupliquer un devoir vers plusieurs classes
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Naming Conventions (push) Has been cancelled
CI / Build Check (push) Has been cancelled

Un enseignant qui donne le même travail à plusieurs classes devait
jusqu'ici recréer manuellement chaque devoir. La duplication permet
de sélectionner les classes cibles, d'ajuster les dates d'échéance
par classe, et de créer tous les devoirs en une seule opération
atomique (transaction).

La validation s'effectue par classe (affectation enseignant, date
d'échéance) avec un rapport d'erreurs détaillé. L'infrastructure
de warnings est prête pour les règles de timing de la Story 5.3.
Le filtrage par classe dans la liste des devoirs passe côté serveur
pour rester compatible avec la pagination.
This commit is contained in:
2026-03-15 14:20:48 +01:00
parent e9efb90f59
commit 68179a929f
18 changed files with 1831 additions and 2 deletions

View File

@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
use App\Scolarite\Domain\Model\Homework\HomeworkAttachment;
use App\Scolarite\Domain\Model\Homework\HomeworkAttachmentId;
use App\Scolarite\Domain\Model\Homework\HomeworkId;
use App\Scolarite\Domain\Repository\HomeworkAttachmentRepository;
use function array_map;
use DateTimeImmutable;
use Doctrine\DBAL\Connection;
use Override;
final readonly class DoctrineHomeworkAttachmentRepository implements HomeworkAttachmentRepository
{
public function __construct(
private Connection $connection,
) {
}
#[Override]
public function findByHomeworkId(HomeworkId $homeworkId): array
{
$rows = $this->connection->fetchAllAssociative(
'SELECT * FROM homework_attachments WHERE homework_id = :homework_id',
['homework_id' => (string) $homeworkId],
);
return array_map($this->hydrate(...), $rows);
}
#[Override]
public function save(HomeworkId $homeworkId, HomeworkAttachment $attachment): void
{
$this->connection->executeStatement(
'INSERT INTO homework_attachments (id, homework_id, filename, file_path, file_size, mime_type, uploaded_at)
VALUES (:id, :homework_id, :filename, :file_path, :file_size, :mime_type, :uploaded_at)',
[
'id' => (string) $attachment->id,
'homework_id' => (string) $homeworkId,
'filename' => $attachment->filename,
'file_path' => $attachment->filePath,
'file_size' => $attachment->fileSize,
'mime_type' => $attachment->mimeType,
'uploaded_at' => $attachment->uploadedAt->format(DateTimeImmutable::ATOM),
],
);
}
/** @param array<string, mixed> $row */
private function hydrate(array $row): HomeworkAttachment
{
/** @var string $id */
$id = $row['id'];
/** @var string $filename */
$filename = $row['filename'];
/** @var string $filePath */
$filePath = $row['file_path'];
/** @var string|int $rawFileSize */
$rawFileSize = $row['file_size'];
$fileSize = (int) $rawFileSize;
/** @var string $mimeType */
$mimeType = $row['mime_type'];
/** @var string $uploadedAt */
$uploadedAt = $row['uploaded_at'];
return new HomeworkAttachment(
id: HomeworkAttachmentId::fromString($id),
filename: $filename,
filePath: $filePath,
fileSize: $fileSize,
mimeType: $mimeType,
uploadedAt: new DateTimeImmutable($uploadedAt),
);
}
}