|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @Author Asim Sarwar |
| 4 | + * Description Handle Smithsonian Institution Open Access API's Client |
| 5 | + * ClassName SmithsonianIOAAPIClientController |
| 6 | + */ |
| 7 | +namespace App\Http\Controllers\Api\V1\Integration; |
| 8 | + |
| 9 | +use App\Http\Controllers\Controller; |
| 10 | +use Illuminate\Http\Request; |
| 11 | +use App\CurrikiGo\Smithsonian\Client; |
| 12 | +use App\CurrikiGo\Smithsonian\Contents\GetContentList; |
| 13 | +use App\CurrikiGo\Smithsonian\Contents\GetContentDetail; |
| 14 | +use App\Exceptions\GeneralException; |
| 15 | + |
| 16 | +class SmithsonianIOAAPIClientController extends Controller |
| 17 | +{ |
| 18 | + protected $client; |
| 19 | + /** |
| 20 | + * SmithsonianIOAAPIClientController constructor. |
| 21 | + * Create a new Client instance. |
| 22 | + * @return object $client |
| 23 | + */ |
| 24 | + public function __construct() |
| 25 | + { |
| 26 | + $this->client = new Client(); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Get Smithsonian Contents List |
| 31 | + * @param Request $request |
| 32 | + * @bodyParam start int like page number Example: 1 |
| 33 | + * @bodyParam rows int like page size or number of record per page Example: 10 |
| 34 | + * @bodyParam sort string Sort list by id, newest, updated and random field |
| 35 | + * @bodyParam type string get list by type = edanmdm or ead_collection or ead_component or all |
| 36 | + * @bodyParam row_group string The designated set of row types you are filtering it may be objects, archives |
| 37 | + * @return object $response |
| 38 | + * @throws GeneralException |
| 39 | + */ |
| 40 | + public function getContentList(Request $request) |
| 41 | + { |
| 42 | + $getParam = $request->only([ |
| 43 | + 'start', |
| 44 | + 'rows', |
| 45 | + 'sort', |
| 46 | + 'type', |
| 47 | + 'row_group' |
| 48 | + ]); |
| 49 | + $auth = \Auth::user(); |
| 50 | + if ( $auth && $auth->id ) { |
| 51 | + $instance = new GetContentList($this->client); |
| 52 | + $response = $instance->fetch($getParam); |
| 53 | + return $response; |
| 54 | + } |
| 55 | + throw new GeneralException('Unauthorized!'); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Get Smithsonian Content Detail |
| 60 | + * @param Request $request |
| 61 | + * @bodyParam id string Example: con-1620124231687-1620150333404-0 |
| 62 | + * @return object $response |
| 63 | + * @throws GeneralException |
| 64 | + */ |
| 65 | + public function getContentDetail(Request $request) |
| 66 | + { |
| 67 | + $getParam = $request->only([ |
| 68 | + 'id' |
| 69 | + ]); |
| 70 | + $auth = \Auth::user(); |
| 71 | + if ( $auth && $auth->id && isset($getParam['id']) && $getParam['id'] != '') { |
| 72 | + $instance = new GetContentDetail($this->client); |
| 73 | + $response = $instance->fetch($getParam); |
| 74 | + return $response; |
| 75 | + } |
| 76 | + throw new GeneralException('Please check you payload data. id field is require!'); |
| 77 | + } |
| 78 | +} |
0 commit comments