tenantId); $studentId = UserId::fromString($command->studentId); $newClassId = ClassId::fromString($command->newClassId); $academicYearId = AcademicYearId::fromString($command->academicYearId); // Valider l'existence de la nouvelle classe, son tenant et son statut $class = $this->classRepository->get($newClassId); if (!$class->tenantId->equals($tenantId)) { throw ClasseNotFoundException::withId($newClassId); } if (!$class->status->peutRecevoirEleves()) { throw ClasseNotFoundException::withId($newClassId); } // Trouver l'affectation existante $assignment = $this->classAssignmentRepository->findByStudent($studentId, $academicYearId, $tenantId); if ($assignment === null) { throw AffectationEleveNonTrouveeException::pourEleve($studentId); } $assignment->changerClasse($newClassId, $this->clock->now()); $this->classAssignmentRepository->save($assignment); return $assignment; } }