Skip to content

[Storybook] Improve Storybook examples #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions api/migrations/Version20250306152729.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250306152729 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE book (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, isbn VARCHAR(255) DEFAULT NULL, title VARCHAR(255) NOT NULL, description TEXT NOT NULL, author VARCHAR(255) NOT NULL, publication_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE review (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, rating SMALLINT NOT NULL, body TEXT NOT NULL, author VARCHAR(255) NOT NULL, publication_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, book_id INT DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_794381C616A2B381 ON review (book_id)');
$this->addSql('ALTER TABLE review ADD CONSTRAINT FK_794381C616A2B381 FOREIGN KEY (book_id) REFERENCES book (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE review DROP CONSTRAINT FK_794381C616A2B381');
$this->addSql('DROP TABLE book');
$this->addSql('DROP TABLE review');
}
}
77 changes: 77 additions & 0 deletions api/src/Entity/Book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;


#[ApiResource(mercure: true)]
#[ORM\Entity]
#[ApiFilter(OrderFilter::class, properties: [
'id' => 'ASC',
'isbn' => 'ASC',
'title' => 'ASC',
'author' => 'ASC',
'publicationDate' => 'DESC'
])]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'title' => 'ipartial',
'author' => 'ipartial'
])]
#[ApiFilter(DateFilter::class, properties: ['publicationDate'])]
class Book
{
/** The ID of this book */
#[ORM\Id]
#[ORM\Column]
#[ORM\GeneratedValue]
private ?int $id = null;

/** The ISBN of this book (or null if doesn't have one) */
#[ORM\Column(nullable: true)]
public ?string $isbn = null;

/** The title of this book */
#[ORM\Column]
#[Assert\NotBlank]
#[ApiProperty(iris: ['http://schema.org/name'])]
public string $title = '';

/** The description of this book */
#[ORM\Column(type: 'text')]
#[Assert\NotBlank]
public string $description = '';

/** The author of this book */
#[ORM\Column]
#[Assert\NotBlank]
public string $author = '';

/** The publication date of this book */
#[ORM\Column]
#[Assert\NotNull]
public ?\DateTimeImmutable $publicationDate = null;

/** @var Review[] Available reviews for this book */
#[ORM\OneToMany(mappedBy: 'book', targetEntity: Review::class, cascade: ['persist', 'remove'])]
public iterable $reviews;

public function __construct()
{
$this->reviews = new ArrayCollection();
}

public function getId(): ?int
{
return $this->id;
}
}
69 changes: 69 additions & 0 deletions api/src/Entity/Review.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;


#[ApiResource(mercure: true)]
#[ORM\Entity]
#[ApiFilter(OrderFilter::class, properties: [
'id' => 'ASC',
'rating' => 'ASC',
'author' => 'ASC',
'publicationDate' => 'DESC'
])]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'body' => 'ipartial',
'author' => 'ipartial'
])]
#[ApiFilter(NumericFilter::class, properties: ['rating'])]
#[ApiFilter(DateFilter::class, properties: ['publicationDate'])]
class Review
{
/** The ID of this review */
#[ORM\Id]
#[ORM\Column]
#[ORM\GeneratedValue]
private ?int $id = null;

/** The rating of this review (between 0 and 5) */
#[ORM\Column(type: 'smallint')]
#[Assert\Range(min: 0, max: 5)]
public int $rating = 0;

/** The body of this review */
#[ORM\Column(type: 'text')]
#[Assert\NotBlank]
public string $body = '';

/** The author of this review */
#[ORM\Column]
#[Assert\NotBlank]
public string $author = '';

/** The publication date of this review */
#[ORM\Column]
#[Assert\NotNull]
#[ApiProperty(iris: ['http://schema.org/name'])]
public ?\DateTimeImmutable $publicationDate = null;

/** The book this review is about */
#[ORM\ManyToOne(inversedBy: 'reviews')]
#[Assert\NotNull]
public ?Book $book = null;

public function getId(): ?int
{
return $this->id;
}
}
53 changes: 0 additions & 53 deletions src/stories/Custom.stories.tsx

This file was deleted.

Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy