Merge branch 'master' of github.com:hillelcoren/invoice-ninja

This commit is contained in:
Hillel Coren 2016-01-26 22:22:40 +02:00
commit 9c96f09fc0
7 changed files with 90 additions and 7 deletions

View File

@ -9,16 +9,20 @@ use App\Ninja\Repositories\ClientRepository;
use App\Http\Requests\CreateClientRequest; use App\Http\Requests\CreateClientRequest;
use App\Http\Controllers\BaseAPIController; use App\Http\Controllers\BaseAPIController;
use App\Ninja\Transformers\ClientTransformer; use App\Ninja\Transformers\ClientTransformer;
use App\Services\ClientService;
use App\Http\Requests\UpdateClientRequest;
class ClientApiController extends BaseAPIController class ClientApiController extends BaseAPIController
{ {
protected $clientRepo; protected $clientRepo;
protected $clientService;
public function __construct(ClientRepository $clientRepo) public function __construct(ClientRepository $clientRepo, ClientService $clientService)
{ {
parent::__construct(); parent::__construct();
$this->clientRepo = $clientRepo; $this->clientRepo = $clientRepo;
$this->clientService = $clientService;
} }
public function ping() public function ping()
@ -48,8 +52,19 @@ class ClientApiController extends BaseAPIController
{ {
$clients = Client::scope() $clients = Client::scope()
->with($this->getIncluded()) ->with($this->getIncluded())
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc');
->paginate();
// 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')); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer'));
$paginator = Client::scope()->paginate(); $paginator = Client::scope()->paginate();
@ -83,7 +98,7 @@ class ClientApiController extends BaseAPIController
public function store(CreateClientRequest $request) public function store(CreateClientRequest $request)
{ {
$client = $this->clientRepo->save($request->input()); $client = $this->clientRepo->save($request->input());
$client = Client::scope($client->public_id) $client = Client::scope($client->public_id)
->with('country', 'contacts', 'industry', 'size', 'currency') ->with('country', 'contacts', 'industry', 'size', 'currency')
->first(); ->first();
@ -93,4 +108,40 @@ class ClientApiController extends BaseAPIController
return $this->response($data); 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);
}
} }

View File

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

View File

@ -211,7 +211,7 @@ Route::group(['middleware' => 'auth'], function() {
// Route groups for API // Route groups for API
Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function() Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
{ {
Route::resource('ping', 'ClientApiController@ping'); Route::get('ping', 'ClientApiController@ping');
Route::post('login', 'AccountApiController@login'); Route::post('login', 'AccountApiController@login');
Route::get('static', 'AccountApiController@getStaticData'); Route::get('static', 'AccountApiController@getStaticData');
Route::get('accounts', 'AccountApiController@show'); Route::get('accounts', 'AccountApiController@show');

View 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,
];
}
}

View File

@ -25,12 +25,22 @@ class InvoiceTransformer extends EntityTransformer
'payments' 'payments'
]; ];
protected $availableIncludes = [
'invitations',
];
public function includeInvoiceItems(Invoice $invoice) public function includeInvoiceItems(Invoice $invoice)
{ {
$transformer = new InvoiceItemTransformer($this->account, $this->serializer); $transformer = new InvoiceItemTransformer($this->account, $this->serializer);
return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEMS); 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) public function includePayments(Invoice $invoice)
{ {
$transformer = new PaymentTransformer($this->account, $this->serializer); $transformer = new PaymentTransformer($this->account, $this->serializer);

View File

@ -13,7 +13,7 @@ class TaxRateTransformer extends EntityTransformer
/** /**
* @SWG\Property(property="id", type="integer", example=1, readOnly=true) * @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="name", type="string", example="GST") * @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="rate", type="float", example=17.5)
* @SWG\Property(property="updated_at", type="date-time", example="2016-01-01 12:10:00") * @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") * @SWG\Property(property="archived_at", type="date-time", example="2016-01-01 12:10:00")

View File

@ -152,7 +152,7 @@ class PaymentLibrariesSeeder extends Seeder
['format' => 'M j, Y', 'picker_format' => 'M d, yyyy', 'label' => 'Mar 10, 2013'], ['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' => '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' => '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' => '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'] ['format' => 'm/d/Y', 'picker_format' => 'mm/dd/yyyy', 'label' => '03/20/2013']
]; ];