Skip to content

Commit

Permalink
Merge pull request #507 from BioKIC/add-NEON-taxonCodes-to-API
Browse files Browse the repository at this point in the history
Add taxon code
  • Loading branch information
egbot authored Jul 17, 2024
2 parents 9160c57 + 1435351 commit e9ce57f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
28 changes: 12 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 Expand Up @@ -228,6 +222,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);
}
Expand Down
27 changes: 27 additions & 0 deletions api/app/Models/NeonTaxonomy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;

class NeonTaxonomy extends Model implements AuthenticatableContract, AuthorizableContract{
use Authenticatable, Authorizable, HasFactory;

protected $table = 'neon_taxonomy';
protected $primaryKey = 'taxonPK';
public $timestamps = false;

protected $fillable = [ ];

protected $hidden = [ 'taxonPK', 'verbatimScientificName', 'tid', 'sciname', 'scientificNameAuthorship', 'family', 'acceptedTaxonCode', 'taxonProtocolCategory',
'vernacular', 'source', 'sourceReference', 'notes', 'initialTimestamp' ];

public function taxa() {
return $this->belongsTo(Taxonomy::class, 'tid', 'tid');
}
}
4 changes: 4 additions & 0 deletions api/app/Models/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit e9ce57f

Please sign in to comment.