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\Company as Request;
|
||||
use App\Http\Resources\Common\Company as Resource;
|
||||
use App\Jobs\Common\CreateCompany;
|
||||
use App\Jobs\Common\DeleteCompany;
|
||||
use App\Jobs\Common\UpdateCompany;
|
||||
use App\Models\Common\Company;
|
||||
use App\Transformers\Common\Company as Transformer;
|
||||
use App\Traits\Users;
|
||||
use Dingo\Api\Http\Response;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class Companies extends ApiController
|
||||
{
|
||||
@ -19,20 +19,20 @@ class Companies extends ApiController
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$companies = user()->companies()->collect();
|
||||
|
||||
return $this->response->paginator($companies, new Transformer());
|
||||
return Resource::collection($companies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Company $company
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Company $company)
|
||||
{
|
||||
@ -40,9 +40,9 @@ class Companies extends ApiController
|
||||
// Check if user can access company
|
||||
$this->canAccess($company);
|
||||
|
||||
return $this->item($company, new Transformer());
|
||||
return new Resource($company);
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,13 +50,13 @@ class Companies 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)
|
||||
{
|
||||
$company = $this->dispatch(new CreateCompany($request));
|
||||
|
||||
return $this->response->created(route('api.companies.show', $company->id), $this->item($company, new Transformer()));
|
||||
return $this->created(route('api.companies.show', $company->id), new Resource($company));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,16 +64,16 @@ class Companies extends ApiController
|
||||
*
|
||||
* @param $company
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Company $company, Request $request)
|
||||
{
|
||||
try {
|
||||
$company = $this->dispatch(new UpdateCompany($company, $request));
|
||||
|
||||
return $this->item($company->fresh(), new Transformer());
|
||||
return new Resource($company->fresh());
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,16 +81,16 @@ class Companies extends ApiController
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Company $company
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function enable(Company $company)
|
||||
{
|
||||
try {
|
||||
$company = $this->dispatch(new UpdateCompany($company, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($company->fresh(), new Transformer());
|
||||
return new Resource($company->fresh());
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,16 +98,16 @@ class Companies extends ApiController
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Company $company
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function disable(Company $company)
|
||||
{
|
||||
try {
|
||||
$company = $this->dispatch(new UpdateCompany($company, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($company->fresh(), new Transformer());
|
||||
return new Resource($company->fresh());
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,16 +115,16 @@ class Companies extends ApiController
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Company $company
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Company $company)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteCompany($company));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->noContent();
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,16 +133,16 @@ class Companies extends ApiController
|
||||
*
|
||||
* @param Company $company
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function canAccess(Company $company)
|
||||
{
|
||||
if (!empty($company) && $this->isUserCompany($company->id)) {
|
||||
if (! empty($company) && $this->isUserCompany($company->id)) {
|
||||
return new Response('');
|
||||
}
|
||||
|
||||
$message = trans('companies.error.not_user_company');
|
||||
|
||||
$this->response->errorUnauthorized($message);
|
||||
$this->errorUnauthorized($message);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user