Skip to content

Commit

Permalink
#120 - fix load() in DataImporter.php (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandraKozubal authored Aug 21, 2023
1 parent 3b50785 commit 4686ed3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions app/Importers/DataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,26 @@ protected function createImportInfoDetails(string $code, string $providerName):

protected function load(string $cityName, string $countryName, string $lat = "", string $long = ""): string
{
$city = City::query()->where("name", $cityName)->first();
$alternativeCityName = CityAlternativeName::query()->where("name", $cityName)->first();
$country = Country::query()->where("name", $countryName)->orWhere("alternative_name", $countryName)->first();

if ($city || $alternativeCityName) {
$cityId = $city ? $city->id : $alternativeCityName->city_id;
if ($country) {
$city = City::query()->where("name", $cityName)->where("country_id", $country->id)->first();
$alternativeCityName = CityAlternativeName::query()->where("name", $cityName)->first();

$this->createProvider($cityId, self::getProviderName());
if ($city) {
$cityId = $city->id;
$this->createProvider($cityId, self::getProviderName());

return strval($cityId);
}
$country = Country::query()->where("name", $countryName)->orWhere("alternative_name", $countryName)->first();
return strval($cityId);
} elseif ($alternativeCityName) {
$cityId = $alternativeCityName->city_id;
$city = City::query()->where("id", $cityId)->first();

if ($city->country_id === $country->id){
$this->createProvider($cityId, self::getProviderName());
}
}

if ($country) {
$coordinates = $this->mapboxService->getCoordinatesFromApi($cityName, $countryName);
$countCoordinates = count($coordinates);

Expand All @@ -128,7 +135,7 @@ protected function load(string $cityName, string $countryName, string $lat = "",
$this->createProvider($city->id, self::getProviderName());

return strval($city->id);
}
}
$this->countryNotFound($cityName, $countryName);
$this->createImportInfoDetails("420", self::getProviderName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up(): void
->on("countries")
->onDelete("cascade");

$table->string("name")->unique();
$table->string("name");
$table->string("latitude")->nullable();
$table->string("longitude")->nullable();
$table->timestamps();
Expand Down
Binary file added public/providers/binbin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4686ed3

Please sign in to comment.