akaunting 3.0 (the last dance)
This commit is contained in:
@@ -4,13 +4,13 @@ namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Common\Dashboard as Request;
|
||||
use App\Http\Resources\Common\Dashboard as Resource;
|
||||
use App\Jobs\Common\CreateDashboard;
|
||||
use App\Jobs\Common\DeleteDashboard;
|
||||
use App\Jobs\Common\UpdateDashboard;
|
||||
use App\Models\Common\Dashboard;
|
||||
use App\Transformers\Common\Dashboard as Transformer;
|
||||
use App\Traits\Users;
|
||||
use Dingo\Api\Http\Response;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class Dashboards extends ApiController
|
||||
{
|
||||
@@ -19,20 +19,20 @@ class Dashboards extends ApiController
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$dashboards = user()->dashboards()->with('widgets')->collect();
|
||||
|
||||
return $this->response->paginator($dashboards, new Transformer());
|
||||
return Resource::collection($dashboards);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
@@ -42,9 +42,9 @@ class Dashboards extends ApiController
|
||||
// Check if user can access dashboard
|
||||
$this->canAccess($dashboard);
|
||||
|
||||
return $this->item($dashboard, new Transformer());
|
||||
return new Resource($dashboard);
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ class Dashboards extends ApiController
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$dashboard = $this->dispatch(new CreateDashboard($request));
|
||||
|
||||
return $this->response->created(route('api.dashboards.show', $dashboard->id), $this->item($dashboard, new Transformer()));
|
||||
return $this->created(route('api.dashboards.show', $dashboard->id), new Resource($dashboard));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,16 +66,16 @@ class Dashboards extends ApiController
|
||||
*
|
||||
* @param $dashboard
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Dashboard $dashboard, Request $request)
|
||||
{
|
||||
try {
|
||||
$dashboard = $this->dispatch(new UpdateDashboard($dashboard, $request));
|
||||
|
||||
return $this->item($dashboard->fresh(), new Transformer());
|
||||
return new Resource($dashboard->fresh());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,16 +83,16 @@ class Dashboards extends ApiController
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Dashboard $dashboard
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function enable(Dashboard $dashboard)
|
||||
{
|
||||
try {
|
||||
$dashboard = $this->dispatch(new UpdateDashboard($dashboard, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($dashboard->fresh(), new Transformer());
|
||||
return new Resource($dashboard->fresh());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,16 +100,16 @@ class Dashboards extends ApiController
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Dashboard $dashboard
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function disable(Dashboard $dashboard)
|
||||
{
|
||||
try {
|
||||
$dashboard = $this->dispatch(new UpdateDashboard($dashboard, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($dashboard->fresh(), new Transformer());
|
||||
return new Resource($dashboard->fresh());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,16 +117,16 @@ class Dashboards extends ApiController
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Dashboard $dashboard
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Dashboard $dashboard)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteDashboard($dashboard));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class Dashboards extends ApiController
|
||||
*
|
||||
* @param Dashboard $dashboard
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function canAccess($dashboard)
|
||||
{
|
||||
@@ -145,6 +145,6 @@ class Dashboards extends ApiController
|
||||
|
||||
$message = trans('dashboards.error.not_user_dashboard');
|
||||
|
||||
$this->response->errorUnauthorized($message);
|
||||
$this->errorUnauthorized($message);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user