Browse Source

wip media object post normalizing

master
Daniel 1 year ago
parent
commit
00d0a0858b
1 changed files with 10 additions and 2 deletions
  1. +10
    -2
      httpdocs/src/Controller/CreateMediaObjectAction.php

+ 10
- 2
httpdocs/src/Controller/CreateMediaObjectAction.php View File

@@ -13,13 +13,16 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfonycasts\MicroMapper\MicroMapperInterface; use Symfonycasts\MicroMapper\MicroMapperInterface;
use ApiPlatform\Core\Api\IriConverterInterface;
use Symfony\Component\Serializer\SerializerInterface;


#[AsController] #[AsController]
final class CreateMediaObjectAction extends AbstractController final class CreateMediaObjectAction extends AbstractController
{ {
public function __construct( public function __construct(
private MicroMapperInterface $microMapper, private MicroMapperInterface $microMapper,
private EntityManagerInterface $em
private EntityManagerInterface $em,
private SerializerInterface $serializer
) { ) {
} }


@@ -42,6 +45,11 @@ final class CreateMediaObjectAction extends AbstractController
$this->em->flush(); $this->em->flush();


$mediaObjectApi = $this->microMapper->map($mediaObject, MediaObjectApi::class); $mediaObjectApi = $this->microMapper->map($mediaObject, MediaObjectApi::class);
return new JsonResponse($mediaObjectApi);

// Serialisieren Sie das Objekt mit dem API Platform Serializer
$jsonContent = $this->serializer->serialize($mediaObjectApi, 'jsonld', ['groups' => 'media_object:read']);

// Erstellen Sie eine JsonResponse mit dem serialisierten Inhalt
return new JsonResponse($jsonContent, 200, [], true);
} }
} }

Loading…
Cancel
Save