Skip to content

Commit

Permalink
Added a report api
Browse files Browse the repository at this point in the history
  • Loading branch information
ohtarr committed Jul 24, 2020
1 parent 83072bd commit b20e887
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
62 changes: 62 additions & 0 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Asset;
use App\Http\Resources\Asset as AssetResource;
use App\Http\Resources\AssetCollection;
use Spatie\QueryBuilder\QueryBuilder;
use Spatie\QueryBuilder\Filter;

class ReportController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
if($request->paginate)
{
$paginate = $request->paginate;
} else {
$paginate = env("ASSETS_PAGINATION");
}

$filters = [
'id',
'serial',
'part_id',
'vendor_id',
'warranty_id',
'location_id',
];

$includes = [
'part',
'part.manufacturer',
'vendor',
'warranty',
];

$query = QueryBuilder::for(Asset::class);
$query->allowedFilters($filters);
$query->allowedIncludes($includes);

if ($request->get('type')) {
$query->join('parts', 'parts.id', '=', 'assets.part_id');
$query->where('parts.type', $request->get('type'));
}

if ($request->get('manufacturer_id')) {
$query->join('parts', 'parts.id', '=', 'assets.part_id');
$query->where('parts.manufacturer_id', $request->get('manufacturer_id'));
}

$assets = $query->paginate($paginate);

return new AssetCollection($assets);
}
}
23 changes: 22 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1159,4 +1159,25 @@
* }
* )
*/
Route::apiResource('locations', 'LocationController');
Route::apiResource('locations', 'LocationController');

/**
* @SWG\Get(
* path="/api/report",
* tags={"Report"},
* summary="Get Report",
* description="",
* operationId="",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Response(
* response=200,
* description="successful operation",
* ),
* security={
* {"AzureAD": {}},
* }
* )
**/

Route::get('report', 'ReportController@index');
26 changes: 26 additions & 0 deletions storage/api-docs/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,32 @@
]
}
},
"/api/report": {
"get": {
"tags": [
"Report"
],
"summary": "Get Report",
"description": "",
"operationId": "",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "successful operation"
}
},
"security": [
{
"AzureAD": []
}
]
}
},
"/api/me": {
"get": {
"tags": [
Expand Down

0 comments on commit b20e887

Please sign in to comment.