feat: Calculer automatiquement les moyennes après chaque saisie de notes
Les enseignants ont besoin de moyennes à jour immédiatement après la publication ou modification des notes, sans attendre un batch nocturne. Le système recalcule via Domain Events synchrones : statistiques d'évaluation (min/max/moyenne/médiane), moyennes matières pondérées (normalisation /20), et moyenne générale par élève. Les résultats sont stockés dans des tables dénormalisées avec cache Redis (TTL 5 min). Trois endpoints API exposent les données avec contrôle d'accès par rôle. Une commande console permet le backfill des données historiques au déploiement.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\DeleteAppreciationTemplate;
|
||||
|
||||
final readonly class DeleteAppreciationTemplateCommand
|
||||
{
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $teacherId,
|
||||
public string $templateId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\DeleteAppreciationTemplate;
|
||||
|
||||
use App\Scolarite\Domain\Exception\AppreciationTemplateNonTrouveeException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDuModeleException;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class DeleteAppreciationTemplateHandler
|
||||
{
|
||||
public function __construct(
|
||||
private AppreciationTemplateRepository $templateRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(DeleteAppreciationTemplateCommand $command): void
|
||||
{
|
||||
$tenantId = TenantId::fromString($command->tenantId);
|
||||
$templateId = AppreciationTemplateId::fromString($command->templateId);
|
||||
|
||||
$template = $this->templateRepository->findById($templateId, $tenantId);
|
||||
|
||||
if ($template === null) {
|
||||
throw AppreciationTemplateNonTrouveeException::withId($templateId);
|
||||
}
|
||||
|
||||
if ((string) $template->teacherId !== $command->teacherId) {
|
||||
throw NonProprietaireDuModeleException::withId($templateId);
|
||||
}
|
||||
|
||||
$this->templateRepository->delete($templateId, $tenantId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user