Skip to content

Commit

Permalink
fix: handle airports without a subregion and region
Browse files Browse the repository at this point in the history
  • Loading branch information
amvid committed Jul 21, 2024
1 parent 4a1e9c1 commit f917424
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/Airport/Action/Query/QueryAirportsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function run(QueryAirportsActionRequest $request): QueryAirportsActionRes
$city = $airport->getCity();
$country = $city->getCountry();
$subregion = $country->getSubregion();
$region = $subregion->getRegion();
$region = $subregion?->getRegion();
$cityIata = $city->getIata() ?? $airport->getIata();

$regions[$country->getTitle()] = $region->getTitle();
$subregions[$country->getTitle()] = $subregion->getTitle();
$regions[$country->getTitle()] = $region?->getTitle();
$subregions[$country->getTitle()] = $subregion?->getTitle();

if (!isset($map[$country->getTitle()])) {
$map[$country->getTitle()] = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Airport/Controller/Response/QueryAirportResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class QueryAirportResponse
public string $title;
public string $iata;
public string $country;
public string $region;
public string $subregion;
public ?string $region = null;
public ?string $subregion = null;

public function __construct(string $title, string $iata, string $country, string $region, string $subregion)
public function __construct(string $title, string $iata, string $country, ?string $region = null, ?string $subregion = null)
{

$this->title = $title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class QueryChildrenAirportResponse
public string $title;
public string $iata;
public string $country;
public string $subregion;
public string $region;
public ?string $subregion = null;
public ?string $region = null;

/** @var array<QueryAirportResponse> */
public array $children = [];

public function __construct(string $title, string $iata, string $country, string $region, string $subregion, array $children = [])
public function __construct(string $title, string $iata, string $country, ?string $region = null, ?string $subregion = null, array $children = [])
{
$this->title = $title;
$this->iata = $iata;
Expand Down
4 changes: 2 additions & 2 deletions src/Airport/Entity/Airport.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class Airport
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private UuidInterface $id;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false)]
private City $city;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false)]
private Timezone $timezone;

Expand Down
3 changes: 1 addition & 2 deletions src/Application/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
public function __construct(
private LoggerInterface $logger,
private KernelInterface $kernel,
) {
}
) {}

public function onKernelException(ExceptionEvent $event): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/City/Entity/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class City
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private UuidInterface $id;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false)]
private Country $country;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: true)]
private ?State $state = null;

Expand Down
8 changes: 4 additions & 4 deletions src/Country/Entity/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ class Country
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private UuidInterface $id;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: true)]
private ?SubRegion $subRegion = null;

#[ORM\ManyToMany(targetEntity: Timezone::class, orphanRemoval: true)]
#[ORM\ManyToMany(targetEntity: Timezone::class, orphanRemoval: true, fetch: 'EAGER')]
private Collection $timezones;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false)]
private Currency $currency;

#[ORM\OneToOne]
#[ORM\OneToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: true)]
private ?City $capital = null;

Expand Down
3 changes: 1 addition & 2 deletions src/State/Entity/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Ramsey\Uuid\UuidInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

#[ORM\Entity(repositoryClass: StateRepository::class)]
#[ORM\HasLifecycleCallbacks]
Expand All @@ -36,7 +35,7 @@ class State
#[ORM\Column(length: 50, nullable: true)]
private ?string $type = null;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false)]
private Country $country;

Expand Down
2 changes: 1 addition & 1 deletion src/SubRegion/Entity/SubRegion.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SubRegion
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private UuidInterface $id;

#[ORM\ManyToOne]
#[ORM\ManyToOne(fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false)]
private Region $region;

Expand Down

0 comments on commit f917424

Please sign in to comment.