Skip to content

Commit

Permalink
update service assigning
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes committed Apr 27, 2024
1 parent 744921d commit 1dc6b0f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
3 changes: 3 additions & 0 deletions app/Exceptions/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function register(): void
});
}

/**
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
*/
public function render($request, Throwable $exception)
{
if ($exception instanceof ValidationException) {
Expand Down
6 changes: 3 additions & 3 deletions app/Importers/BirdDataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ protected function parseData(string $html): array
return array_map("trim", $coordinates);
}

protected function load(string $cityName, string $countryName, string $lat = "", string $long = ""): string
protected function load(string $cityName, string $countryName, string $lat = "", string $long = "", array $services = ["escooter"]): string
{
$city = City::query()->where("name", $cityName)->first();
$alternativeCityName = CityAlternativeName::query()->where("name", $cityName)->first();

if ($city || $alternativeCityName) {
$cityId = $city ? $city->id : $alternativeCityName->city_id;

$this->createProvider($cityId, self::getProviderName());
$this->createProvider($cityId, self::getProviderName(), $services);

return strval($cityId);
}
Expand All @@ -97,7 +97,7 @@ protected function load(string $cityName, string $countryName, string $lat = "",
"country_id" => $country->id,
]);

$this->createProvider($city->id, self::getProviderName());
$this->createProvider($city->id, self::getProviderName(), $services);

return strval($city->id);
}
Expand Down
19 changes: 10 additions & 9 deletions app/Importers/DataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ protected function countryNotFound(string $cityName, string $countryName): void
}
}

protected function createProvider(int $cityId, string $providerName, array $services = ["escooter"]): void
protected function createProvider(int $cityId, string $providerName, array $services): void
{
foreach ($services as $service) {
$serviceId = Service::query()->where("type", $service)->first()->id;
$service = Service::query()->where("type", $service)->first();

CityProvider::query()->updateOrCreate([
"city_id" => $cityId,
"provider_name" => $providerName,
"service_id" => $serviceId,
"created_by" => "scrapper",
"city_id" => $cityId,
"created_by" => "scraper",
"service_id" => $service->id,
]);
}
}
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function createImportInfoDetails(string $code, string $providerName):
);
}

protected function load(string $cityName, string $countryName, string $lat = "", string $long = ""): string
protected function load(string $cityName, string $countryName, string $lat = "", string $long = "", array $services = ["escooter"]): string
{
$country = Country::query()->where("name", $countryName)->orWhere("alternative_name", $countryName)->first();

Expand All @@ -125,15 +126,15 @@ protected function load(string $cityName, string $countryName, string $lat = "",

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

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());
$this->createProvider($cityId, self::getProviderName(), $services);
}
}

Expand All @@ -151,7 +152,7 @@ protected function load(string $cityName, string $countryName, string $lat = "",
"country_id" => $country->id,
]);

$this->createProvider($city->id, self::getProviderName());
$this->createProvider($city->id, self::getProviderName(), $services);

return strval($city->id);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Importers/LimeDataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public function transform(): void
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
}

protected function load(string $cityName, string $countryName, string $lat = "", string $long = ""): string
protected function load(string $cityName, string $countryName, string $lat = "", string $long = "", array $services = ["escooter"]): string
{
$city = City::query()->where("name", $cityName)->first();
$alternativeCityName = CityAlternativeName::query()->where("name", $cityName)->first();

if ($city || $alternativeCityName) {
$cityId = $city ? $city->id : $alternativeCityName->city_id;

$this->createProvider($cityId, self::getProviderName());
$this->createProvider($cityId, self::getProviderName(), $services);

return strval($cityId);
}
Expand Down Expand Up @@ -98,7 +98,7 @@ protected function load(string $cityName, string $countryName, string $lat = "",
"country_id" => $country->id,
]);

$this->createProvider($city->id, self::getProviderName());
$this->createProvider($city->id, self::getProviderName(), $services);

return strval($city->id);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Importers/SpinDataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public function transform(): void
$this->deleteMissingProviders(self::getProviderName(), $existingCityProviders);
}

protected function load(string $cityName, string $countryName, string $lat = "", string $long = ""): string
protected function load(string $cityName, string $countryName, string $lat = "", string $long = "", array $services = ["escooter"]): string
{
$city = City::query()->where("name", $cityName)->first();
$alternativeCityName = CityAlternativeName::query()->where("name", $cityName)->first();

if ($city || $alternativeCityName) {
$cityId = $city ? $city->id : $alternativeCityName->city_id;

$this->createProvider($cityId, self::getProviderName());
$this->createProvider($cityId, self::getProviderName(), $services);

return strval($cityId);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ protected function load(string $cityName, string $countryName, string $lat = "",
"country_id" => $country->id,
]);

$this->createProvider($city->id, self::getProviderName());
$this->createProvider($city->id, self::getProviderName(), $services);

return strval($city->id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public function up(): void
->onDelete("cascade");
});
}

public function down(): void
{
Schema::table("city_providers", function (Blueprint $table): void {
$table->dropForeign(["service_id"]);
$table->dropColumn("service_id");
});
}
};

0 comments on commit 1dc6b0f

Please sign in to comment.