v2 first commit
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Banking;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Banking\Account as Request;
|
||||
use App\Jobs\Banking\CreateAccount;
|
||||
use App\Jobs\Banking\DeleteAccount;
|
||||
use App\Jobs\Banking\UpdateAccount;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Transformers\Banking\Account as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Accounts extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@@ -27,11 +27,18 @@ class Accounts extends ApiController
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Account $account)
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or number
|
||||
if (is_numeric($id)) {
|
||||
$account = Account::find($id);
|
||||
} else {
|
||||
$account = Account::where('number', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($account, new Transformer());
|
||||
}
|
||||
|
||||
@@ -43,9 +50,9 @@ class Accounts extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$account = Account::create($request->all());
|
||||
$account = $this->dispatch(new CreateAccount($request));
|
||||
|
||||
return $this->response->created(url('api/accounts/'.$account->id));
|
||||
return $this->response->created(url('api/accounts/' . $account->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,9 +64,43 @@ class Accounts extends ApiController
|
||||
*/
|
||||
public function update(Account $account, Request $request)
|
||||
{
|
||||
$account->update($request->all());
|
||||
try {
|
||||
$account = $this->dispatch(new UpdateAccount($account, $request));
|
||||
|
||||
return $this->response->item($account->fresh(), new Transformer());
|
||||
return $this->item($account->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Account $account
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Account $account)
|
||||
{
|
||||
$account = $this->dispatch(new UpdateAccount($account, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($account->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Account $account
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Account $account)
|
||||
{
|
||||
try {
|
||||
$account = $this->dispatch(new UpdateAccount($account, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($account->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,8 +111,12 @@ class Accounts extends ApiController
|
||||
*/
|
||||
public function destroy(Account $account)
|
||||
{
|
||||
$account->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteAccount($account));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user