Skip to content

Commit

Permalink
Taxonomy API development
Browse files Browse the repository at this point in the history
- Add taxonCodes to output
- Reduce complexity of taxonomy search endpoint
  • Loading branch information
egbot committed Jul 17, 2024
1 parent 8fb4ca5 commit 1435351
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions api/app/Http/Controllers/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1435351

Please sign in to comment.