tenantId); $classId = ClassId::fromString($command->classId); $subjectId = SubjectId::fromString($command->subjectId); $teacherId = UserId::fromString($command->teacherId); $now = $this->clock->now(); if (!$this->affectationChecker->estAffecte($teacherId, $classId, $subjectId, $tenantId)) { throw EnseignantNonAffecteException::pourClasseEtMatiere($teacherId, $classId, $subjectId); } $calendar = $this->calendarProvider->forCurrentYear($tenantId); $dueDate = new DateTimeImmutable($command->dueDate); $this->dueDateValidator->valider($dueDate, $now, $calendar); $rulesResult = $this->rulesChecker->verifier($tenantId, $dueDate, $now); if (!$rulesResult->estBloquant()) { throw ExceptionNonNecessaireException::carReglesNonBloquantes(); } $homework = Homework::creer( tenantId: $tenantId, classId: $classId, subjectId: $subjectId, teacherId: $teacherId, title: $command->title, description: $command->description, dueDate: $dueDate, now: $now, ); $exception = HomeworkRuleException::demander( tenantId: $tenantId, homeworkId: $homework->id, ruleTypes: $rulesResult->ruleTypes(), justification: $command->justification, createdBy: $teacherId, now: $now, ); $this->connection->beginTransaction(); try { $this->homeworkRepository->save($homework); $this->exceptionRepository->save($exception); $this->connection->commit(); } catch (Throwable $e) { $this->connection->rollBack(); throw $e; } return ['homework' => $homework, 'exception' => $exception]; } }