Commit 63504798 by Lech Sawon

get room controller

parent c1c9ba16
<?php
declare(strict_types=1);
namespace App\Controller\Api;
use App\Entity\Room;
use PHPUnit\Util\Json;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
final class GetRoomController extends AbstractController
{
/**
* @Route("/api/room/{id}", name="api_get_room", methods={"GET"}))
*/
public function __invoke(Room $room, SerializerInterface $serializer): JsonResponse
{
// jak zronbić, żeby encja nie robiła wszystkiego (serializacj, walidacja, mapowanie na baze)
// 1. przyjmuje po prostu id jako int albo IdDto
// 2. przekazujemy id do odpowiedniego serwisu
// 3. serwis pyta baza danych i zwraca Dto, które tworzy na podstawie encji
// 4. serializujemy dto.
return JsonResponse::fromJsonString(
$serializer->serialize($room, 'json')
);
}
}
...@@ -4,6 +4,8 @@ namespace App\Entity; ...@@ -4,6 +4,8 @@ namespace App\Entity;
use App\Repository\RoomRepository; use App\Repository\RoomRepository;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* @ORM\Entity(repositoryClass=RoomRepository::class) * @ORM\Entity(repositoryClass=RoomRepository::class)
...@@ -19,6 +21,8 @@ class Room ...@@ -19,6 +21,8 @@ class Room
/** /**
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
* @Assert\Length(min=3, max=128)
* @SerializedName("room_name")
*/ */
private string $name; private string $name;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment