Skip to content

Commit

Permalink
[TM-1425] sort categories and add validation to missing slug (#608)
Browse files Browse the repository at this point in the history
* [TM-1425] sort categories and add validation to missing slug

* lint fix
  • Loading branch information
LimberHope authored Dec 12, 2024
1 parent 5a47a49 commit 8a0dc46
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
49 changes: 39 additions & 10 deletions app/Helpers/RestorationByEcoregionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8a0dc46

Please sign in to comment.