From 8a0dc461599adc1e1c181dc04edd4be7af9f7dfb Mon Sep 17 00:00:00 2001 From: Limber Mamani <154026979+LimberHope@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:45:18 -0400 Subject: [PATCH] [TM-1425] sort categories and add validation to missing slug (#608) * [TM-1425] sort categories and add validation to missing slug * lint fix --- app/Helpers/RestorationByEcoregionHelper.php | 49 +++++++++++++++---- ...GetPolygonsIndicatorAnalysisController.php | 3 ++ ...ygonsIndicatorAnalysisVerifyController.php | 3 ++ .../IndicatorEntitySlugExportController.php | 4 ++ .../RunIndicatorAnalysisController.php | 1 - 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/Helpers/RestorationByEcoregionHelper.php b/app/Helpers/RestorationByEcoregionHelper.php index db82ded7..26b25e9b 100755 --- a/app/Helpers/RestorationByEcoregionHelper.php +++ b/app/Helpers/RestorationByEcoregionHelper.php @@ -9,23 +9,16 @@ public static function getCategoryEcoRegion($value, ?bool $isExport = false) $categoriesFromEcoRegion = [ 'australasian' => [ 'Southeast Australia temperate forests', - 'Madeira-Tapajós moist forests', 'Tocantins/Pindare moist forests', 'Tapajós-Xingu moist forests', 'Mato Grosso seasonal forests', 'Mato Grosso seasonal forests, Xingu-Tocantins-Araguaia moist forests', 'Bahia coastal forests', - 'Tonle Sap freshwater swamp forests', + 'Southern Miombo woodlands', + 'Palawan rain forests', ], 'afrotropical' => [ - 'Sinú Valley dry forests', - 'Santa Marta montane forests', 'Atlantic mixed forests', - 'Petén-Veracruz moist forests', - 'Central American Atlantic moist forests', - 'Petén-Veracruz moist forests, Central American Atlantic moist forests', - 'Central American montane forests', - 'Central American Atlantic moist forests, Central American montane forests', 'Northern Acacia-Commiphora bushlands and thickets', 'Southern Rift montane forest-grassland mosaic', 'Sierra Madre de Chiapas moist forests', @@ -45,10 +38,46 @@ public static function getCategoryEcoRegion($value, ?bool $isExport = false) 'Central Zambezian Miombo woodlands', 'Ethiopian montane grasslands and woodlands', 'Central African mangroves', + 'Southern Acacia-Commiphora bushlands and thickets', + 'East African montane forests', + 'Eastern Arc forests', + 'Guinean mangroves', + 'Eastern Zimbabwe montane forest-grassland mosaic', + 'Somali Acacia-Commiphora bushlands and thickets', + 'Ethiopian montane forests', + 'Inner Niger Delta flooded savanna', + 'Western Guinean lowland forests', + 'Eastern Miombo woodlands', + 'Ethiopian montane forests, Ethiopian montane grasslands and woodlands', + 'Cross-Sanaga-Bioko coastal forests', + 'Zambezian and Mopane woodlands', + 'Madagascar lowland forests', + 'Madagascar subhumid forests', + 'Southern Congolian forest-savanna mosaic', + 'East African montane forests', + 'East African montane forests, Northern Acacia-Commiphora bushlands and thickets', + 'Albertine Rift montane forests, Lake', ], 'paleartic' => [ - 'southern-zanzibar-inhambane-coastal-forest-mosaic', + 'Southwest Iberian Mediterranean sclerophyllous and mixed forests', + 'Narmada Valley dry deciduous forests', + 'East African montane moorlands', + 'Cameroonian Highlands forests', + 'Celtic broadleaf forests', + 'Atlantic Coast restingas', + ], + 'neotropical' => [ + 'Sinú Valley dry forests', + 'Santa Marta montane forests', + 'Petén-Veracruz moist forests', + 'Central American Atlantic moist forests', + 'Petén-Veracruz moist forests, Central American Atlantic moist forests', + 'Central American montane forests', + 'Central American Atlantic moist forests, Central American montane forests', + 'Cross-Niger transition forests', + 'Atlantic Coast restingas', ], + ]; $formatedValue = []; foreach ($categoriesFromEcoRegion as $category => $values) { diff --git a/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisController.php b/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisController.php index 1fa19c41..d062bf55 100644 --- a/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisController.php +++ b/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisController.php @@ -32,6 +32,9 @@ public function __invoke(EntityModel $entity, string $slug) 'relation_name' => 'hectaresIndicator', ], ]; + if (! isset($slugMappings[$slug])) { + return response()->json([]); + } try { return SitePolygon::whereHas($slugMappings[$slug]['relation_name'], function ($query) use ($slug) { diff --git a/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisVerifyController.php b/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisVerifyController.php index 8cffc4a4..bc5f0cf9 100644 --- a/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisVerifyController.php +++ b/app/Http/Controllers/V2/MonitoredData/GetPolygonsIndicatorAnalysisVerifyController.php @@ -35,6 +35,9 @@ public function __invoke(EntityModel $entity, string $slug) 'indicator_title' => 'Hectares Under Restoration By WWF EcoRegion', ], ]; + if (! isset($slugMappings[$slug])) { + return response()->json([]); + } try { $polygonUuids = SitePolygon::whereHas('site', function ($query) use ($entity) { diff --git a/app/Http/Controllers/V2/MonitoredData/IndicatorEntitySlugExportController.php b/app/Http/Controllers/V2/MonitoredData/IndicatorEntitySlugExportController.php index 88a1301d..8c28aba5 100644 --- a/app/Http/Controllers/V2/MonitoredData/IndicatorEntitySlugExportController.php +++ b/app/Http/Controllers/V2/MonitoredData/IndicatorEntitySlugExportController.php @@ -14,6 +14,10 @@ class IndicatorEntitySlugExportController extends Controller { public function __invoke(EntityModel $entity, string $slug) { + if (! isset($slugMappings[$slug])) { + return response()->json(['message' => 'Indicator not found'], 404); + } + return $this->exportCsv($entity, $slug); } diff --git a/app/Http/Controllers/V2/MonitoredData/RunIndicatorAnalysisController.php b/app/Http/Controllers/V2/MonitoredData/RunIndicatorAnalysisController.php index 8fa5669c..2a55ba64 100644 --- a/app/Http/Controllers/V2/MonitoredData/RunIndicatorAnalysisController.php +++ b/app/Http/Controllers/V2/MonitoredData/RunIndicatorAnalysisController.php @@ -17,7 +17,6 @@ public function __invoke(Request $request, string $slug) try { $requestData = $request->all(); $binary_data = Redis::get('run:indicator|'.$slug.'|'.json_encode($requestData['uuids'])); - Log::info($binary_data); if (! $binary_data) { $delayedJob = DelayedJob::create(); $job = new RunIndicatorAnalysisJob(