From 8fb4ca5b828ed765147fdec06a9e76620e974aae Mon Sep 17 00:00:00 2001 From: Edward Gilbert Date: Tue, 16 Jul 2024 17:51:00 -0400 Subject: [PATCH 1/2] Add taxon code - Create a model for NeonTaxonomy table - Add taxonCode to Taxonomy model - Add taxon code to Taxonomy Controlled targeting output for single taxon API --- .../Http/Controllers/TaxonomyController.php | 2 ++ api/app/Models/NeonTaxonomy.php | 27 +++++++++++++++++++ api/app/Models/Taxonomy.php | 4 +++ 3 files changed, 33 insertions(+) create mode 100644 api/app/Models/NeonTaxonomy.php diff --git a/api/app/Http/Controllers/TaxonomyController.php b/api/app/Http/Controllers/TaxonomyController.php index 6556c9b8f2..be45749c0a 100644 --- a/api/app/Http/Controllers/TaxonomyController.php +++ b/api/app/Http/Controllers/TaxonomyController.php @@ -228,6 +228,8 @@ public function showOneTaxon($id, Request $request){ $parStatusResult = $parStatus->get(); $taxonObj->classification = $parStatusResult; + $taxonObj->taxonCodes; + if(!$taxonObj->count()) $taxonObj = ['status' =>false, 'error' => 'Unable to locate inventory based on identifier']; return response()->json($taxonObj); } diff --git a/api/app/Models/NeonTaxonomy.php b/api/app/Models/NeonTaxonomy.php new file mode 100644 index 0000000000..188871e97c --- /dev/null +++ b/api/app/Models/NeonTaxonomy.php @@ -0,0 +1,27 @@ +belongsTo(Taxonomy::class, 'tid', 'tid'); + } +} diff --git a/api/app/Models/Taxonomy.php b/api/app/Models/Taxonomy.php index f743e6d7d2..8ee7857d88 100644 --- a/api/app/Models/Taxonomy.php +++ b/api/app/Models/Taxonomy.php @@ -23,4 +23,8 @@ public function descriptions(){ public function media(){ return $this->hasMany(media::class, 'tid', 'tid'); } + + public function taxonCodes(){ + return $this->hasMany(NeonTaxonomy::class, 'tid', 'tid'); + } } From 1435351bef170a7fb686ddb3e5d62ee35576563f Mon Sep 17 00:00:00 2001 From: Edward Gilbert Date: Wed, 17 Jul 2024 13:02:59 -0400 Subject: [PATCH 2/2] Taxonomy API development - Add taxonCodes to output - Reduce complexity of taxonomy search endpoint --- .../Http/Controllers/TaxonomyController.php | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/api/app/Http/Controllers/TaxonomyController.php b/api/app/Http/Controllers/TaxonomyController.php index be45749c0a..5ea02d3481 100644 --- a/api/app/Http/Controllers/TaxonomyController.php +++ b/api/app/Http/Controllers/TaxonomyController.php @@ -55,7 +55,7 @@ public function showAllTaxa(Request $request){ $offset = $request->input('offset',0); $fullCnt = Taxonomy::count(); - $result = Taxonomy::skip($offset)->take($limit)->get(); + $result = Taxonomy::with('taxonCodes')->skip($offset)->take($limit)->get(); $eor = false; $retObj = [ @@ -134,32 +134,26 @@ public function showAllTaxaSearch(Request $request){ $type = $request->input('type', 'EXACT'); - $fullCnt = 0; - $result = []; + $taxaModel = Taxonomy::with('taxonCodes'); if($type == 'START'){ - $fullCnt = Taxonomy::where('sciname', 'like', $request->taxon . '%')->count(); - $result = Taxonomy::where('sciname', 'like', $request->taxon . '%')->skip($offset)->take($limit)->get(); + $taxaModel->where('sciname', 'like', $request->taxon . '%'); } elseif($type == 'WILD'){ - $fullCnt = Taxonomy::where('sciname', 'like', '%' . $request->taxon . '%')->count(); - $result = Taxonomy::where('sciname', 'like', '%' . $request->taxon . '%')->skip($offset)->take($limit)->get(); + $taxaModel->where('sciname', 'like', '%' . $request->taxon . '%'); } elseif($type == 'WHOLEWORD'){ - $fullCnt = Taxonomy::where('unitname1', $request->taxon) + $taxaModel->where('unitname1', $request->taxon) ->orWhere('unitname2', $request->taxon) - ->orWhere('unitname3', $request->taxon) - ->count(); - $result = Taxonomy::where('unitname1', $request->taxon) - ->orWhere('unitname2', $request->taxon) - ->orWhere('unitname3', $request->taxon) - ->skip($offset)->take($limit)->get(); + ->orWhere('unitname3', $request->taxon); } else{ //Exact match - $fullCnt = Taxonomy::where('sciname', $request->taxon)->count(); - $result = Taxonomy::where('sciname', $request->taxon)->skip($offset)->take($limit)->get(); + $taxaModel->where('sciname', $request->taxon); } + $fullCnt = $taxaModel->count(); + $result = $taxaModel->skip($offset)->take($limit)->get(); + $eor = false; $retObj = [ 'offset' => (int)$offset,