mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Merge branch 'master' of github.com:hillelcoren/invoice-ninja
This commit is contained in:
commit
9c96f09fc0
@ -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();
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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');
|
||||
|
21
app/Ninja/Transformers/InvitationTransformer.php
Normal file
21
app/Ninja/Transformers/InvitationTransformer.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php namespace App\Ninja\Transformers;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Invitation;
|
||||
use League\Fractal;
|
||||
|
||||
class InvitationTransformer extends EntityTransformer
|
||||
{
|
||||
public function transform(Invitation $invitation)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $invitation->public_id,
|
||||
'key' => $invitation->getName(),
|
||||
'status' => $invitation->getStatus(),
|
||||
'link' => $invitation->getLink(),
|
||||
'sent_date' => $invitation->sent_date,
|
||||
'viewed_date' => $invitation->sent_date,
|
||||
];
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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")
|
||||
|
@ -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']
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user