From 4ca4498b24951dfc902b786cd878a7d7dbd02ff9 Mon Sep 17 00:00:00 2001 From: JakubKermes Date: Wed, 8 May 2024 16:42:00 +0200 Subject: [PATCH 1/2] Add count for cities without country or coordinates --- .../Controllers/Api/Admin/CityController.php | 8 +++++++ ...ityWithoutAssignedCoordinatesResources.php | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 app/Http/Resources/CityWithoutAssignedCoordinatesResources.php diff --git a/app/Http/Controllers/Api/Admin/CityController.php b/app/Http/Controllers/Api/Admin/CityController.php index d12cf59f..21ab27e2 100644 --- a/app/Http/Controllers/Api/Admin/CityController.php +++ b/app/Http/Controllers/Api/Admin/CityController.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\CityRequest; use App\Http\Resources\CityResource; +use App\Http\Resources\CityWithoutAssignedCoordinatesResources; use App\Http\Resources\CityWithoutAssignedCountryResource; use App\Http\Resources\CountryResource; use App\Http\Resources\ProviderResource; @@ -35,12 +36,19 @@ public function index(): JsonResponse $countries = Country::all(); $citiesWithoutAssignedCountry = CityWithoutAssignedCountry::all(); + $citiesWithoutAssignedCoordinates = City::query() + ->whereNull("latitude") + ->orWhereNull("longitude") + ->get(); return response()->json([ "cities" => CityResource::collection($cities), "providers" => ProviderResource::collection($providers), "countries" => CountryResource::collection($countries), "citiesWithoutAssignedCountry" => CityWithoutAssignedCountryResource::collection($citiesWithoutAssignedCountry), + "citiesWithoutAssignedCountryCount" => $citiesWithoutAssignedCountry->count(), + "citiesWithoutAssignedCoordinates" => CityWithoutAssignedCoordinatesResources::collection($citiesWithoutAssignedCoordinates), + "citiesWithoutAssignedCoordinatesCount" => $citiesWithoutAssignedCoordinates->count(), ]); } diff --git a/app/Http/Resources/CityWithoutAssignedCoordinatesResources.php b/app/Http/Resources/CityWithoutAssignedCoordinatesResources.php new file mode 100644 index 00000000..266b893b --- /dev/null +++ b/app/Http/Resources/CityWithoutAssignedCoordinatesResources.php @@ -0,0 +1,22 @@ + $this->id, + "city_name" => $this->city_name, + "country_name" => $this->country_name, + "latitude" => $this->latitude, + "longitude" => $this->longitude, + ]; + } +} From b40c258925666c1c0728cac107ec2bb3b7a59676 Mon Sep 17 00:00:00 2001 From: Aleksandra Kozubal Date: Mon, 13 May 2024 09:21:33 +0200 Subject: [PATCH 2/2] cr changes --- app/Http/Controllers/Api/Admin/CityController.php | 4 ++-- ...sources.php => CityWithoutAssignedCoordinatesResource.php} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename app/Http/Resources/{CityWithoutAssignedCoordinatesResources.php => CityWithoutAssignedCoordinatesResource.php} (87%) diff --git a/app/Http/Controllers/Api/Admin/CityController.php b/app/Http/Controllers/Api/Admin/CityController.php index 21ab27e2..689b4815 100644 --- a/app/Http/Controllers/Api/Admin/CityController.php +++ b/app/Http/Controllers/Api/Admin/CityController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\CityRequest; use App\Http\Resources\CityResource; -use App\Http\Resources\CityWithoutAssignedCoordinatesResources; +use App\Http\Resources\CityWithoutAssignedCoordinatesResource; use App\Http\Resources\CityWithoutAssignedCountryResource; use App\Http\Resources\CountryResource; use App\Http\Resources\ProviderResource; @@ -47,7 +47,7 @@ public function index(): JsonResponse "countries" => CountryResource::collection($countries), "citiesWithoutAssignedCountry" => CityWithoutAssignedCountryResource::collection($citiesWithoutAssignedCountry), "citiesWithoutAssignedCountryCount" => $citiesWithoutAssignedCountry->count(), - "citiesWithoutAssignedCoordinates" => CityWithoutAssignedCoordinatesResources::collection($citiesWithoutAssignedCoordinates), + "citiesWithoutAssignedCoordinates" => CityWithoutAssignedCoordinatesResource::collection($citiesWithoutAssignedCoordinates), "citiesWithoutAssignedCoordinatesCount" => $citiesWithoutAssignedCoordinates->count(), ]); } diff --git a/app/Http/Resources/CityWithoutAssignedCoordinatesResources.php b/app/Http/Resources/CityWithoutAssignedCoordinatesResource.php similarity index 87% rename from app/Http/Resources/CityWithoutAssignedCoordinatesResources.php rename to app/Http/Resources/CityWithoutAssignedCoordinatesResource.php index 266b893b..1f8025cd 100644 --- a/app/Http/Resources/CityWithoutAssignedCoordinatesResources.php +++ b/app/Http/Resources/CityWithoutAssignedCoordinatesResource.php @@ -7,7 +7,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class CityWithoutAssignedCoordinatesResources extends JsonResource +class CityWithoutAssignedCoordinatesResource extends JsonResource { public function toArray(Request $request): array {