mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Additional API methods for departments
This commit is contained in:
parent
659e60fd12
commit
6c623866c0
|
@ -6,6 +6,8 @@ use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use App\Http\Transformers\DepartmentsTransformer;
|
use App\Http\Transformers\DepartmentsTransformer;
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
use Auth;
|
||||||
|
|
||||||
class DepartmentsController extends Controller
|
class DepartmentsController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -25,7 +27,7 @@ class DepartmentsController extends Controller
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'location_id'
|
'location_id'
|
||||||
])->with('users')->withCount('assets')->withCount('users');
|
])->with('users')->withCount('users');
|
||||||
|
|
||||||
if ($request->has('search')) {
|
if ($request->has('search')) {
|
||||||
$departments = $departments->TextSearch($request->input('search'));
|
$departments = $departments->TextSearch($request->input('search'));
|
||||||
|
@ -42,4 +44,41 @@ class DepartmentsController extends Controller
|
||||||
return (new DepartmentsTransformer)->transformDepartments($departments, $total);
|
return (new DepartmentsTransformer)->transformDepartments($departments, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v4.0]
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$this->authorize('create', Department::class);
|
||||||
|
$department = new Department;
|
||||||
|
$department->fill($request->all());
|
||||||
|
$department->user_id = Auth::user()->id;
|
||||||
|
|
||||||
|
if ($department->save()) {
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $department, trans('admin/departments/message.create.success')));
|
||||||
|
}
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $department->getErrors()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v4.0]
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
$this->authorize('view', Department::class);
|
||||||
|
$department = Department::findOrFail($id);
|
||||||
|
return (new DepartmentsTransformer)->transformDepartment($department);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue