1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Shop routes

This commit is contained in:
David Bomba 2020-07-28 21:30:11 +10:00
parent d5b777206e
commit a8a0c7695c
3 changed files with 82 additions and 7 deletions

View File

@ -0,0 +1,77 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers\Shop;
use App\Events\Client\ClientWasCreated;
use App\Factory\ClientFactory;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Client\StoreClientRequest;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\CompanyToken;
use App\Repositories\ClientRepository;
use App\Transformers\ClientTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
class ClientController extends BaseController
{
use MakesHash;
protected $entity_type = Client::class;
protected $entity_transformer = ClientTransformer::class;
/**
* @var ClientRepository
*/
protected $client_repo;
/**
* ClientController constructor.
* @param ClientRepository $clientRepo
*/
public function __construct(ClientRepository $client_repo)
{
parent::__construct();
$this->client_repo = $client_repo;
}
public function show(string $contact_key)
{
$company_token = CompanyToken::with(['company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first();
$contact = ClientContact::with('client')
->where('company_id', $company_token->company->id)
->where('contact_key', $contact_key)
->firstOrFail();
return $this->itemResponse($contact->client);
}
public function store(StoreClientRequest $request)
{
$company_token = CompanyToken::with(['company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first();
$client = $this->client_repo->save($request->all(), ClientFactory::create($company_token->company_id, $company_token->user_id));
$client->load('contacts', 'primary_contact');
$this->uploadLogo($request->file('company_logo'), $client->company, $client);
event(new ClientWasCreated($client, $client->company, Ninja::eventVars()));
return $this->itemResponse($client);
}
}

View File

@ -11,6 +11,7 @@
namespace App\Http\Controllers\Shop;
use App\Events\Invoice\InvoiceWasCreated;
use App\Factory\InvoiceFactory;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Invoice\StoreInvoiceRequest;
@ -20,6 +21,7 @@ use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Repositories\InvoiceRepository;
use App\Transformers\InvoiceTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
@ -60,11 +62,7 @@ class InvoiceController extends BaseController
return $this->itemResponse($invitation->invoice);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function store(StoreInvoiceRequest $request)
{
$company_token = CompanyToken::with(['company'])->whereRaw("BINARY `token`= ?", [$request->header('X-API-TOKEN')])->first();

View File

@ -136,8 +136,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::post('emails', 'EmailController@send')->name('email.send');
/*Subscription and Webhook routes */
Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe');
Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe');
// Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe');
// Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe');
Route::resource('webhooks', 'WebhookController');
Route::post('webhooks/bulk', 'WebhookController@bulk')->name('webhooks.bulk');