From 0d2025c834665bfba2f23ba857a0c32878ea5601 Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Fri, 22 Jan 2016 10:33:38 +0000 Subject: [PATCH 1/9] Fixed ping route & added a way to find client by email address or if not exist - create a new --- app/Http/Controllers/ClientApiController.php | 17 +++++++++++++++-- app/Http/routes.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index bbe0f9fde2..816ce9b9ea 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -82,8 +82,21 @@ class ClientApiController extends BaseAPIController */ public function store(CreateClientRequest $request) { - $client = $this->clientRepo->save($request->input()); - + if ($request->has('filter_by_email')) { + + $email = $request->get('filter_by_email'); + $client = Client::whereHas('contacts', function ($query) use ($email) { + $query->where('email', $email); + })->with('contacts')->first(); + + if (is_null($client)) { + $client = $this->clientRepo->save($request->input()); + } + + } else { + $client = $this->clientRepo->save($request->input()); + } + $client = Client::scope($client->public_id) ->with('country', 'contacts', 'industry', 'size', 'currency') ->first(); diff --git a/app/Http/routes.php b/app/Http/routes.php index e0ded5dd46..4bd84629f0 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -209,7 +209,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'); From 68665d2972582978bdea6880f8493656f468514b Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Sun, 24 Jan 2016 16:59:01 +0000 Subject: [PATCH 2/9] Added filtering by email --- app/Http/Controllers/ClientApiController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index 816ce9b9ea..95445be61b 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -48,8 +48,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(); From 2478ec59a4471865b0e2f7c898fa79a792125c7b Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Sun, 24 Jan 2016 17:06:34 +0000 Subject: [PATCH 3/9] Revert store() method --- app/Http/Controllers/ClientApiController.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index 95445be61b..b94b7479b1 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -93,20 +93,7 @@ class ClientApiController extends BaseAPIController */ public function store(CreateClientRequest $request) { - if ($request->has('filter_by_email')) { - - $email = $request->get('filter_by_email'); - $client = Client::whereHas('contacts', function ($query) use ($email) { - $query->where('email', $email); - })->with('contacts')->first(); - - if (is_null($client)) { - $client = $this->clientRepo->save($request->input()); - } - - } else { - $client = $this->clientRepo->save($request->input()); - } + $client = $this->clientRepo->save($request->input()); $client = Client::scope($client->public_id) ->with('country', 'contacts', 'industry', 'size', 'currency') From 91d44dd301b47cbef447243ec44bc5232fa19d9a Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Sun, 24 Jan 2016 18:37:24 +0000 Subject: [PATCH 4/9] Add ability to include invoice invitations via API --- app/Ninja/Transformers/InvoiceTransformer.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Ninja/Transformers/InvoiceTransformer.php b/app/Ninja/Transformers/InvoiceTransformer.php index 8108115b2f..f13b081260 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 InvoiceItemTransformer($this->account, $this->serializer); + return $this->includeCollection($invoice->invitations, $transformer, ENTITY_INVITATION); + } + public function includePayments(Invoice $invoice) { $transformer = new PaymentTransformer($this->account, $this->serializer); From cfe183677020da964c0de58bdb01babd532a9f89 Mon Sep 17 00:00:00 2001 From: Laurynas Sakalauskas Date: Sun, 24 Jan 2016 18:55:36 +0000 Subject: [PATCH 5/9] Added invitation transformer --- .../Transformers/InvitationTransformer.php | 21 +++++++++++++++++++ app/Ninja/Transformers/InvoiceTransformer.php | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 app/Ninja/Transformers/InvitationTransformer.php diff --git a/app/Ninja/Transformers/InvitationTransformer.php b/app/Ninja/Transformers/InvitationTransformer.php new file mode 100644 index 0000000000..3fa15eb776 --- /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 f13b081260..432e65a287 100644 --- a/app/Ninja/Transformers/InvoiceTransformer.php +++ b/app/Ninja/Transformers/InvoiceTransformer.php @@ -37,7 +37,7 @@ class InvoiceTransformer extends EntityTransformer public function includeInvitations(Invoice $invoice) { - $transformer = new InvoiceItemTransformer($this->account, $this->serializer); + $transformer = new InvitationTransformer($this->account, $this->serializer); return $this->includeCollection($invoice->invitations, $transformer, ENTITY_INVITATION); } From 7278905bb2858bf13be5251d24c1a49b5388db7a Mon Sep 17 00:00:00 2001 From: trigras Date: Sun, 24 Jan 2016 23:08:27 +0200 Subject: [PATCH 6/9] date picker format fixed --- database/seeds/PaymentLibrariesSeeder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/seeds/PaymentLibrariesSeeder.php b/database/seeds/PaymentLibrariesSeeder.php index 7fd66881ba..7dd5d12643 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'] ]; From a4df265d09386b4df722d61bcc9c22174a05d390 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 26 Jan 2016 22:36:00 +1100 Subject: [PATCH 7/9] Update client via API --- app/Http/Controllers/ClientApiController.php | 42 +++++++++++++++++++- app/Http/Middleware/VerifyCsrfToken.php | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index b94b7479b1..e9f5daf4e0 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() @@ -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); + } } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index e1cd17f5dd..8c159e39ea 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', From e57f8f3c2e6a9ff9807f4ccaa03578df73ce50fb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 26 Jan 2016 22:37:16 +1100 Subject: [PATCH 8/9] Swagger Typo fix --- app/Http/Controllers/ClientApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index e9f5daf4e0..cf93c68c99 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -110,7 +110,7 @@ class ClientApiController extends BaseAPIController } /** - * @SWG\Putt( + * @SWG\Put( * path="/clients/{client_id}", * tags={"client"}, * summary="Update a client", From f80e73888247aa2852da444e5c9399aff4d93d02 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 26 Jan 2016 22:47:19 +1100 Subject: [PATCH 9/9] Bug Fix in taxrate transformer --- app/Ninja/Transformers/TaxRateTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Ninja/Transformers/TaxRateTransformer.php b/app/Ninja/Transformers/TaxRateTransformer.php index 8f4a375c7a..f7d307bf7b 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")