Skip to content

Commit

Permalink
Hotfix (#2098)
Browse files Browse the repository at this point in the history
**3.1.8 Hotfix update**
- API developments
-- Fix bug associated with displaying all media. Previous output was limited to first 200 records only
-- Add limit and offset variables to display all media
-- Add filters to display all media endpoint: tid filter, includeSynonyms, includeChildren
- Out of bounds hyperlink within occurrence editor. Resolves #2099

Co-authored-by: Greg Post <[email protected]>
Co-authored-by: Mark <[email protected]>
  • Loading branch information
3 people authored Jan 24, 2025
1 parent 97f8a9c commit 3d8bd42
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 41 deletions.
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
4 changes: 2 additions & 2 deletions api/app/Http/Controllers/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -111,7 +111,7 @@ public function showOneInventory($id, Request $request){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
88 changes: 81 additions & 7 deletions api/app/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Http\Controllers;

use App\Models\Media;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Http\Controllers\TaxonomyController;

class MediaController extends Controller{

Expand Down Expand Up @@ -34,9 +36,44 @@ public function __construct(){
* path="/api/v2/media",
* operationId="showAllMedia",
* tags={""},
* @OA\Parameter(
* name="tid",
* in="query",
* description="Display media filtered by target taxon ID (PK key of taxon)",
* required=false,
* @OA\Schema(type="integer")
* ),
* @OA\Parameter(
* name="includeSynonyms",
* in="query",
* description="Include media linked to synonyms of target taxon (0 = false, 1 = true)",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
* @OA\Parameter(
* name="includeChildren",
* in="query",
* description="Include media linked to direct children of target taxon (0 = false, 1 = true)",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
* @OA\Parameter(
* name="limit",
* in="query",
* description="Controls the number of results in the page.",
* required=false,
* @OA\Schema(type="integer", default=100)
* ),
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
* @OA\Response(
* response="200",
* description="Returns list of media records",
* description="Success: Returns list of media records",
* @OA\JsonContent()
* ),
* @OA\Response(
Expand All @@ -45,8 +82,44 @@ public function __construct(){
* ),
* )
*/
public function showAllMedia(){
return response()->json(Media::skip(0)->take(100)->get());
public function showAllMedia(Request $request){

$this->validate($request, [
'tid' => 'integer',
'includeSynonyms' => 'integer',
'includeChildren' => 'integer',
'limit' => 'integer',
'offset' => 'integer'
]);
$tid = $request->input('tid');
$includeSynonyms = $request->input('includeSynonyms');
$includeChildren = $request->input('includeChildren');
$limit = $request->input('limit',100);
$offset = $request->input('offset',0);

$mediaModel = Media::query();
if($tid){
$tidArr = array($tid);
if($includeSynonyms){
$tidArr = TaxonomyController::getSynonyms($tid);
}
if($includeChildren){
$tidArr = array_merge($tidArr, TaxonomyController::getChildren($tid));
}
$mediaModel->whereIn('tid', $tidArr);
}
$fullCnt = $mediaModel->count();
$result = $mediaModel->skip($offset)->take($limit)->get();

$eor = false;
$retObj = [
'offset' => (int)$offset,
'limit' => (int)$limit,
'endOfRecords' => $eor,
'count' => $fullCnt,
'results' => $result
];
return response()->json($retObj);
}

/**
Expand All @@ -63,7 +136,7 @@ public function showAllMedia(){
* ),
* @OA\Response(
* response="200",
* description="Returns single media record",
* description="Success: Returns single media record",
* @OA\JsonContent(type="application/json")
* ),
* @OA\Response(
Expand Down Expand Up @@ -233,7 +306,7 @@ public function showOneMedia($id){
* ),
* @OA\Response(
* response="201",
* description="Returns JSON object of the of media record that was created"
* description="Success: Returns JSON object of the of media record that was created"
* ),
* @OA\Response(
* response="400",
Expand Down Expand Up @@ -424,7 +497,7 @@ public function insert(Request $request){
* ),
* @OA\Response(
* response="200",
* description="Returns full JSON object of the of media record that was edited"
* description="Success: Returns full JSON object of the of media record that was edited"
* ),
* @OA\Response(
* response="400",
Expand Down Expand Up @@ -472,7 +545,7 @@ public function update($id, Request $request){
* ),
* @OA\Response(
* response="204",
* description="Record deleted successfully"
* description="Success: Record deleted successfully"
* ),
* @OA\Response(
* response="400",
Expand All @@ -496,6 +569,7 @@ public function delete($id, Request $request){
return response()->json(['status' => 'failure', 'error' => 'Unauthorized'], 401);
}

//Support functions
private function adjustInputData(&$data){
if(!empty($data['mediumUrl'])){
//remap mediumUrl to url field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/OccurrenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
28 changes: 24 additions & 4 deletions api/app/Http/Controllers/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -76,7 +76,7 @@ public function showAllTaxa(Request $request){
* @OA\Parameter(
* name="taxon",
* in="query",
* description="Taxon searh term",
* description="Taxon search term",
* required=true,
* @OA\Schema(type="string")
* ),
Expand All @@ -101,7 +101,7 @@ public function showAllTaxa(Request $request){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -241,7 +241,7 @@ public function showOneTaxon($id, Request $request){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -282,4 +282,24 @@ public function showAllDescriptions($id, Request $request){
return response()->json($retObj);
}

//Support functions
public static function getSynonyms(Int $tid){
$synonymResult = DB::table('taxstatus as ts')
->join('taxstatus as s', 'ts.tidaccepted', '=', 's.tidaccepted')
->where('ts.tid', $tid)->where('ts.taxauthid', 1)->where('s.taxauthid', 1)->pluck('s.tid');
return $synonymResult->toArray();
}

public static function getChildren(Int $tid){
//Direct accepted children only
$childrenResult = DB::table('taxstatus as c')
->join('taxstatus as a', 'c.parenttid', '=', 'a.tidaccepted')
->where('a.tid', $tid)->where('c.taxauthid', 1)->where('a.taxauthid', 1)->whereColumn('c.tid', 'c.tidaccepted')->pluck('c.tid');
/*
SELECT c.tid
FROM taxstatus c INNER JOIN taxstatus a ON c.parenttid = a.tidaccepted
WHERE a.tid = 61943 AND c.taxauthid = 1 AND a.taxauthid = 1 AND c.tid = c.tidaccepted;
*/
return $childrenResult->toArray();
}
}
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/TaxonomyDescriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
4 changes: 4 additions & 0 deletions api/app/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function occurrence() {
return $this->belongsTo(Occurrence::class, 'occid', 'occid');
}

public function Taxonomy() {
return $this->belongsTo(Taxonomy::class, 'tid', 'tid');
}

//Accessor functions
public function getUrlAttribute($value){
if(substr($value, 0, 1) == '/') $value = $this->serverDomain . $value;
Expand Down
Loading

0 comments on commit 3d8bd42

Please sign in to comment.