mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 16:31:33 +02:00
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php namespace App\Http\Controllers;
|
|
|
|
use Utils;
|
|
use Response;
|
|
use Input;
|
|
use App\Models\Client;
|
|
use App\Ninja\Repositories\ClientRepository;
|
|
use App\Http\Requests\CreateClientRequest;
|
|
|
|
class ClientApiController extends Controller
|
|
{
|
|
protected $clientRepo;
|
|
|
|
public function __construct(ClientRepository $clientRepo)
|
|
{
|
|
$this->clientRepo = $clientRepo;
|
|
}
|
|
|
|
public function ping()
|
|
{
|
|
$headers = Utils::getApiHeaders();
|
|
|
|
return Response::make('', 200, $headers);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$clients = Client::scope()
|
|
->with('country', 'contacts', 'industry', 'size', 'currency')
|
|
->orderBy('created_at', 'desc')
|
|
->get();
|
|
$clients = Utils::remapPublicIds($clients);
|
|
|
|
$response = json_encode($clients, JSON_PRETTY_PRINT);
|
|
$headers = Utils::getApiHeaders(count($clients));
|
|
|
|
return Response::make($response, 200, $headers);
|
|
}
|
|
|
|
public function store(CreateClientRequest $request)
|
|
{
|
|
$client = $this->clientRepo->save($request->input());
|
|
|
|
$client = Client::scope($client->public_id)->with('country', 'contacts', 'industry', 'size', 'currency')->first();
|
|
$client = Utils::remapPublicIds([$client]);
|
|
$response = json_encode($client, JSON_PRETTY_PRINT);
|
|
$headers = Utils::getApiHeaders();
|
|
|
|
return Response::make($response, 200, $headers);
|
|
}
|
|
}
|