diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index bbe0f9fde298..cf93c68c9915 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -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() @@ -48,8 +52,19 @@ class ClientApiController extends BaseAPIController { $clients = Client::scope() ->with($this->getIncluded()) - ->orderBy('created_at', 'desc') - ->paginate(); + ->orderBy('created_at', 'desc'); + + // Filter by email + if (Input::has('email')) { + + $email = Input::get('email'); + $clients = $clients->whereHas('contacts', function ($query) use ($email) { + $query->where('email', $email); + }); + + } + + $clients = $clients->paginate(); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $paginator = Client::scope()->paginate(); @@ -83,7 +98,7 @@ class ClientApiController extends BaseAPIController public function store(CreateClientRequest $request) { $client = $this->clientRepo->save($request->input()); - + $client = Client::scope($client->public_id) ->with('country', 'contacts', 'industry', 'size', 'currency') ->first(); @@ -93,4 +108,40 @@ class ClientApiController extends BaseAPIController return $this->response($data); } + + /** + * @SWG\Put( + * 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); + } } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index e1cd17f5dd37..8c159e39ea74 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -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', diff --git a/app/Http/routes.php b/app/Http/routes.php index 44a968acab65..f8f3c7526698 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -211,7 +211,7 @@ Route::group(['middleware' => 'auth'], function() { // Route groups for API Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function() { - Route::resource('ping', 'ClientApiController@ping'); + Route::get('ping', 'ClientApiController@ping'); Route::post('login', 'AccountApiController@login'); Route::get('static', 'AccountApiController@getStaticData'); Route::get('accounts', 'AccountApiController@show'); diff --git a/app/Ninja/Transformers/InvitationTransformer.php b/app/Ninja/Transformers/InvitationTransformer.php new file mode 100644 index 000000000000..3fa15eb776c0 --- /dev/null +++ b/app/Ninja/Transformers/InvitationTransformer.php @@ -0,0 +1,21 @@ + (int) $invitation->public_id, + 'key' => $invitation->getName(), + 'status' => $invitation->getStatus(), + 'link' => $invitation->getLink(), + 'sent_date' => $invitation->sent_date, + 'viewed_date' => $invitation->sent_date, + ]; + } +} \ No newline at end of file diff --git a/app/Ninja/Transformers/InvoiceTransformer.php b/app/Ninja/Transformers/InvoiceTransformer.php index 8108115b2f01..432e65a2876e 100644 --- a/app/Ninja/Transformers/InvoiceTransformer.php +++ b/app/Ninja/Transformers/InvoiceTransformer.php @@ -25,12 +25,22 @@ class InvoiceTransformer extends EntityTransformer 'payments' ]; + protected $availableIncludes = [ + 'invitations', + ]; + public function includeInvoiceItems(Invoice $invoice) { $transformer = new InvoiceItemTransformer($this->account, $this->serializer); return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEMS); } + public function includeInvitations(Invoice $invoice) + { + $transformer = new InvitationTransformer($this->account, $this->serializer); + return $this->includeCollection($invoice->invitations, $transformer, ENTITY_INVITATION); + } + public function includePayments(Invoice $invoice) { $transformer = new PaymentTransformer($this->account, $this->serializer); diff --git a/app/Ninja/Transformers/TaxRateTransformer.php b/app/Ninja/Transformers/TaxRateTransformer.php index 8f4a375c7a72..f7d307bf7bb4 100644 --- a/app/Ninja/Transformers/TaxRateTransformer.php +++ b/app/Ninja/Transformers/TaxRateTransformer.php @@ -13,7 +13,7 @@ class TaxRateTransformer extends EntityTransformer /** * @SWG\Property(property="id", type="integer", example=1, readOnly=true) * @SWG\Property(property="name", type="string", example="GST") - * @SWG\Property(property="account_key", type="string", example="34erfdf33fdff" readOnly=true) + * @SWG\Property(property="account_key", type="string", example="asimplestring", readOnly=true) * @SWG\Property(property="rate", type="float", example=17.5) * @SWG\Property(property="updated_at", type="date-time", example="2016-01-01 12:10:00") * @SWG\Property(property="archived_at", type="date-time", example="2016-01-01 12:10:00") diff --git a/database/seeds/PaymentLibrariesSeeder.php b/database/seeds/PaymentLibrariesSeeder.php index 7fd66881ba05..7dd5d126436c 100644 --- a/database/seeds/PaymentLibrariesSeeder.php +++ b/database/seeds/PaymentLibrariesSeeder.php @@ -152,7 +152,7 @@ class PaymentLibrariesSeeder extends Seeder ['format' => 'M j, Y', 'picker_format' => 'M d, yyyy', 'label' => 'Mar 10, 2013'], ['format' => 'F j, Y', 'picker_format' => 'MM d, yyyy', 'label' => 'March 10, 2013'], ['format' => 'D M j, Y', 'picker_format' => 'D MM d, yyyy', 'label' => 'Mon March 10, 2013'], - ['format' => 'Y-M-d', 'picker_format' => 'yyyy-M-dd', 'label' => '2013-03-10'], + ['format' => 'Y-M-d', 'picker_format' => 'yyyy-mm-dd', 'label' => '2013-03-10'], ['format' => 'd-m-Y', 'picker_format' => 'dd-mm-yyyy', 'label' => '20-03-2013'], ['format' => 'm/d/Y', 'picker_format' => 'mm/dd/yyyy', 'label' => '03/20/2013'] ];