Created
April 7, 2024 18:05
-
-
Save mmouih/b0524d76c73afd176c0a75cd94da4fce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
#[ORM\Entity] | |
#[ORM\Table(name: "invoice")] | |
class Invoice | |
{ | |
#[ORM\Id] | |
#[ORM\GeneratedValue] | |
#[ORM\Column(type: "integer")] | |
private int $id; | |
#[ORM\Column(type: "string", length: 255)] | |
private string $invoiceNumber; | |
#[ORM\Column(type: "decimal", precision: 10, scale: 2)] | |
private string $amount; | |
#[ORM\Column(type: "datetime")] | |
private \DateTimeInterface $createdAt; | |
// Constructor | |
public function __construct(string $invoiceNumber, string $amount) | |
{ | |
$this->invoiceNumber = $invoiceNumber; | |
$this->amount = $amount; | |
$this->createdAt = new \DateTimeImmutable(); | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
use App\Entity\Invoice; | |
use Symfony\Component\Serializer\SerializerInterface; | |
#[Route('/invoices')] | |
class InvoiceController extends AbstractController | |
{ | |
#[Route('/{id}', name: 'invoice_show', methods: ['GET'])] | |
public function show(Invoice $invoice, SerializerInterface $serializer): JsonResponse | |
{ | |
$jsonData = $serializer->serialize($invoice, 'json'); | |
return new JsonResponse($jsonData, 200, [], true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment