Skip to content

Commit

Permalink
add swagger for bbox country from worldcountriesgenerated
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Apr 23, 2024
1 parent 02b34d4 commit e0b11a7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 30 deletions.
48 changes: 48 additions & 0 deletions app/Http/Controllers/V2/Dashboard/CountryDataController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Http\Controllers\V2\Dashboard;

use App\Http\Controllers\Controller;
use App\Models\V2\PolygonGeometry;
use App\Models\V2\Projects\Project;
use App\Models\V2\Sites\CriteriaSite;
use App\Models\V2\Sites\SitePolygon;
use App\Models\V2\WorldCountryGeneralized;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Symfony\Component\Process\Process;

class CountryDataController extends Controller
{
public function getCountryBbox(string $iso)
{
// Get the bbox of the country and the name
$countryData = WorldCountryGeneralized::where('iso', $iso)
->selectRaw('ST_AsGeoJSON(ST_Envelope(geometry)) AS bbox, country')
->first();

if (! $countryData) {
return response()->json(['error' => 'Country not found'], 404);
}

// Decode the GeoJSON bbox
$geoJson = json_decode($countryData->bbox);

// Extract the bounding box coordinates
$coordinates = $geoJson->coordinates[0];

// Get the country name
$countryName = $countryData->country;

// Construct the bbox data in the specified format
$countryBbox = [
$countryName,
[$coordinates[0][0], $coordinates[0][1], $coordinates[2][0], $coordinates[2][1]]
];

return response()->json(['bbox' => $countryBbox]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -727,33 +727,6 @@ public function getAllCountryNames()

return response()->json(['countries' => $countries]);
}
public function getCountryBbox(string $iso)
{
// Get the bbox of the country and the name
$countryData = WorldCountryGeneralized::where('iso', $iso)
->selectRaw('ST_AsGeoJSON(ST_Envelope(geometry)) AS bbox, country')
->first();

if (! $countryData) {
return response()->json(['error' => 'Country not found'], 404);
}

// Decode the GeoJSON bbox
$geoJson = json_decode($countryData->bbox);

// Extract the bounding box coordinates
$coordinates = $geoJson->coordinates[0];

// Get the country name
$countryName = $countryData->country;

// Construct the bbox data in the specified format
$countryBbox = [
$countryName,
[$coordinates[0][0], $coordinates[0][1], $coordinates[2][0], $coordinates[2][1]]
];

return response()->json(['bbox' => $countryBbox]);
}


}
25 changes: 24 additions & 1 deletion resources/docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9360,6 +9360,11 @@ definitions:
long:
type: number
format: double
DashboardBBOXCountry:
type: object
properties:
bbox:
type: array
paths:
'/organisations/{ID}/users':
get:
Expand Down Expand Up @@ -19540,4 +19545,22 @@ paths:
'400':
description: Bad request
'500':
description: Internal server error
description: Internal server error
'/v2/dashboard/country/{country}':
get:
summary: Get the bounding box of a country
tags:
- Country
parameters:
- in: path
name: country
type: string
description: ISO code of the country
required: true
responses:
'200':
description: Successful response
schema:
$ref: '#/definitions/DashboardBBOXCountry'
'404':
description: Country not found
4 changes: 3 additions & 1 deletion routes/api_v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Http\Controllers\V2\Dashboard\ActiveCountriesTableController;
use App\Http\Controllers\V2\Dashboard\ActiveProjectsTableController;
use App\Http\Controllers\V2\Dashboard\CountriesController;
use App\Http\Controllers\V2\Dashboard\CountryDataController;
use App\Http\Controllers\V2\Dashboard\GetJobsCreatedController;
use App\Http\Controllers\V2\Dashboard\ProjectListExportController;
use App\Http\Controllers\V2\Dashboard\GetProjectsController;
Expand Down Expand Up @@ -638,7 +639,7 @@
Route::put('/site-polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateSitePolygon']);
Route::post('/site-polygon/{uuid}', [TerrafundEditGeometryController::class, 'createSitePolygon']);

Route::get('/country/{country}', [TerrafundCreateGeometryController::class, 'getCountryBbox']);

});

Route::get('/funding-programme', [FundingProgrammeController::class, 'index'])->middleware('i18n');
Expand Down Expand Up @@ -671,4 +672,5 @@ function () {
Route::get('/project-details', ProjectProfileDetailsController::class);
Route::get('/project-list-export', ProjectListExportController::class);
Route::get('/get-projects', GetProjectsController::class);
Route::get('/country/{country}', [CountryDataController::class, 'getCountryBbox']);
});

0 comments on commit e0b11a7

Please sign in to comment.