json(array_map(static fn ($p) => [ 'id' => $p->getId()->toRfc4122(), 'type' => $p->getType(), 'label' => $p->getLabel(), ], $this->service->findAll())); } #[Route('', name: 'create', methods: ['POST'])] public function create(Request $request): JsonResponse { $data = $request->toArray(); if (empty($data['type']) || empty($data['label'])) { return $this->json(['error' => 'type and label are required'], Response::HTTP_BAD_REQUEST); } $platform = $this->service->create($data['type'], $data['label'], $data['config'] ?? []); return $this->json(['id' => $platform->getId()->toRfc4122(), 'type' => $platform->getType()], Response::HTTP_CREATED); } #[Route('/{id}/channel-fields', name: 'list_fields', methods: ['GET'])] public function listFields(string $id): JsonResponse { $fields = $this->service->findChannelFields(Uuid::fromString($id)); return $this->json(array_map(static fn ($f) => [ 'id' => $f->getId()->toRfc4122(), 'label' => $f->getLabel(), 'path' => $f->getPath(), ], $fields)); } #[Route('/{id}/channel-fields', name: 'add_field', methods: ['POST'])] public function addField(string $id, Request $request): JsonResponse { $data = $request->toArray(); if (empty($data['label']) || empty($data['path'])) { return $this->json(['error' => 'label and path are required'], Response::HTTP_BAD_REQUEST); } try { $field = $this->service->addChannelField(Uuid::fromString($id), $data['label'], $data['path']); } catch (\DomainException $e) { return $this->json(['error' => $e->getMessage()], Response::HTTP_NOT_FOUND); } return $this->json(['id' => $field->getId()->toRfc4122(), 'label' => $field->getLabel()], Response::HTTP_CREATED); } #[Route('/channel-fields/{fieldId}', name: 'remove_field', methods: ['DELETE'])] public function removeField(string $fieldId): JsonResponse { try { $this->service->removeChannelField(Uuid::fromString($fieldId)); } catch (\DomainException $e) { return $this->json(['error' => $e->getMessage()], Response::HTTP_NOT_FOUND); } return $this->json(null, Response::HTTP_NO_CONTENT); } }