diff --git a/api/config/packages/api_platform.yaml b/api/config/packages/api_platform.yaml new file mode 100644 index 0000000..b277bdd --- /dev/null +++ b/api/config/packages/api_platform.yaml @@ -0,0 +1,23 @@ +api_platform: + title: 'How To Code Well Code Quiz API' + description: 'The Code Quiz API from How To Code Well' + version: '1.0.0' + show_webby: false + + openapi: + # The contact information for the exposed API. + contact: + # The identifying name of the contact person/organization. + name: + # The URL pointing to the contact information. MUST be in the format of a URL. + url: + # The email address of the contact person/organization. MUST be in the format of an email address. + email: + # A URL to the Terms of Service for the API. MUST be in the format of a URL. + termsOfService: + # The license information for the exposed API. + license: + # The license name used for the API. + name: + # URL to the license used for the API. MUST be in the format of a URL. + url: \ No newline at end of file diff --git a/api/src/Entity/Question.php b/api/src/Entity/Question.php index 21cefa2..8918997 100644 --- a/api/src/Entity/Question.php +++ b/api/src/Entity/Question.php @@ -8,12 +8,14 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; #[ApiResource( operations: [ new Get( uriTemplate: '/question/{id}', - requirements: ['id' => '\d+'] + requirements: ['id' => '\d+'], + normalizationContext: ['groups' => 'question:item'], ) ] )] @@ -23,19 +25,23 @@ class Question #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] + #[Groups(['question:item'])] private ?int $id = null; #[ORM\ManyToOne(inversedBy: 'questions')] #[ORM\JoinColumn(nullable: false)] + #[Groups(['question:item'])] private ?Quiz $quiz = null; #[ORM\Column(length: 255)] + #[Groups(['question:item'])] private ?string $content = null; /** * @var Collection $answers */ #[ORM\OneToMany(mappedBy: 'question', targetEntity: Answer::class)] + #[Groups(['question:item'])] private Collection $answers; public function __construct() diff --git a/api/src/Entity/Quiz.php b/api/src/Entity/Quiz.php index a72640b..d2b4e35 100644 --- a/api/src/Entity/Quiz.php +++ b/api/src/Entity/Quiz.php @@ -9,14 +9,19 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; #[ORM\Entity(repositoryClass: QuizRepository::class)] #[ApiResource( operations: [ - new GetCollection(), + new GetCollection( + paginationEnabled: false, + normalizationContext: ['groups' => 'quiz:list'], + ), new Get( uriTemplate: '/quiz/{id}', - requirements: ['id' => '\d+'] + requirements: ['id' => '\d+'], + normalizationContext: ['groups' => 'quiz:item'], ) ] )] @@ -25,12 +30,15 @@ class Quiz #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] + #[Groups(['quiz:list', 'quiz:item'])] private ?int $id = null; #[ORM\Column(length: 255)] + #[Groups(['quiz:list', 'quiz:item'])] private ?string $title = null; #[ORM\Column(length: 255)] + #[Groups(['quiz:list', 'quiz:item'])] private ?string $slug = null; /** diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..dc9b237 --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1 @@ +generated \ No newline at end of file