diff --git a/src/Service/Trace/CreateService.php b/src/Service/Trace/CreateService.php index c518697..1af179f 100644 --- a/src/Service/Trace/CreateService.php +++ b/src/Service/Trace/CreateService.php @@ -2,7 +2,32 @@ namespace App\Service\Trace; -class CreateService -{ +use App\Entity\Client; +use App\Entity\Command; +use App\Entity\Trace; +use Doctrine\ORM\EntityManagerInterface; +readonly class CreateService +{ + public function __construct( + private EntityManagerInterface $entityManager + ) + { + } + + public function __invoke(Client $client, Command $command, string $status, ?string $jobId = null, array $input): Trace + { + $trace = new Trace(); + $trace->setClient($client); + $trace->setCommand($command ?? null); + $trace->setStatus($status); + $trace->setJobId($jobId); + $trace->setExecutedAt(new \DateTime()); + $trace->setInput($input); + + $this->entityManager->persist($trace); + $this->entityManager->flush(); + + return $trace; + } } \ No newline at end of file