Skip to content
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
23 changes: 23 additions & 0 deletions api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -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:
8 changes: 7 additions & 1 deletion api/src/Entity/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
)
]
)]
Expand All @@ -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<int, Answer> $answers
*/
#[ORM\OneToMany(mappedBy: 'question', targetEntity: Answer::class)]
#[Groups(['question:item'])]
private Collection $answers;

public function __construct()
Expand Down
12 changes: 10 additions & 2 deletions api/src/Entity/Quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
)
]
)]
Expand All @@ -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;

/**
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated