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.
49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Scolarite\Application\Command\CreateAppreciationTemplate;
|
|
|
|
use App\Administration\Domain\Model\User\UserId;
|
|
use App\Scolarite\Domain\Exception\CategorieAppreciationInvalideException;
|
|
use App\Scolarite\Domain\Model\Grade\AppreciationCategory;
|
|
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
|
|
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
|
use App\Shared\Domain\Clock;
|
|
use App\Shared\Domain\Tenant\TenantId;
|
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
|
|
|
#[AsMessageHandler(bus: 'command.bus')]
|
|
final readonly class CreateAppreciationTemplateHandler
|
|
{
|
|
public function __construct(
|
|
private AppreciationTemplateRepository $templateRepository,
|
|
private Clock $clock,
|
|
) {
|
|
}
|
|
|
|
public function __invoke(CreateAppreciationTemplateCommand $command): AppreciationTemplate
|
|
{
|
|
$category = null;
|
|
if ($command->category !== null) {
|
|
$category = AppreciationCategory::tryFrom($command->category);
|
|
if ($category === null) {
|
|
throw CategorieAppreciationInvalideException::pourValeur($command->category);
|
|
}
|
|
}
|
|
|
|
$template = AppreciationTemplate::creer(
|
|
tenantId: TenantId::fromString($command->tenantId),
|
|
teacherId: UserId::fromString($command->teacherId),
|
|
title: $command->title,
|
|
content: $command->content,
|
|
category: $category,
|
|
now: $this->clock->now(),
|
|
);
|
|
|
|
$this->templateRepository->save($template);
|
|
|
|
return $template;
|
|
}
|
|
}
|