Update client via API

This commit is contained in:
David Bomba 2016-01-26 22:36:00 +11:00
parent 4781c63689
commit a4df265d09
2 changed files with 42 additions and 1 deletions

View File

@ -9,16 +9,20 @@ use App\Ninja\Repositories\ClientRepository;
use App\Http\Requests\CreateClientRequest;
use App\Http\Controllers\BaseAPIController;
use App\Ninja\Transformers\ClientTransformer;
use App\Services\ClientService;
use App\Http\Requests\UpdateClientRequest;
class ClientApiController extends BaseAPIController
{
protected $clientRepo;
protected $clientService;
public function __construct(ClientRepository $clientRepo)
public function __construct(ClientRepository $clientRepo, ClientService $clientService)
{
parent::__construct();
$this->clientRepo = $clientRepo;
$this->clientService = $clientService;
}
public function ping()
@ -104,4 +108,40 @@ class ClientApiController extends BaseAPIController
return $this->response($data);
}
/**
* @SWG\Putt(
* path="/clients/{client_id}",
* tags={"client"},
* summary="Update a client",
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Client")
* ),
* @SWG\Response(
* response=200,
* description="Update client",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Client"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function update(UpdateClientRequest $request)
{
$client = $this->clientService->save($request->input());
$client = Client::scope($client->public_id)
->with('country', 'contacts', 'industry', 'size', 'currency')
->first();
$transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer'));
$data = $this->createItem($client, $transformer, ENTITY_CLIENT);
return $this->response($data);
}
}

View File

@ -8,6 +8,7 @@ class VerifyCsrfToken extends BaseVerifier {
private $openRoutes = [
'signup/register',
'api/v1/login',
'api/v1/clients/*',
'api/v1/clients',
'api/v1/invoices/*',
'api/v1/invoices',