1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 18:01:35 +02:00
invoiceninja/app/controllers/ClientApiController.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2014-05-13 21:20:54 +02:00
<?php
use ninja\repositories\ClientRepository;
use Client;
2014-07-27 22:31:41 +02:00
class ClientApiController extends Controller {
2014-05-13 21:20:54 +02:00
protected $clientRepo;
public function __construct(ClientRepository $clientRepo)
{
$this->clientRepo = $clientRepo;
}
2014-07-27 22:31:41 +02:00
public function ping()
{
$headers = Utils::getApiHeaders();
return Response::make('', 200, $headers);
}
2014-05-13 21:20:54 +02:00
public function index()
{
2014-07-27 22:31:41 +02:00
if (!Utils::isPro()) {
Redirect::to('/');
}
$clients = Client::scope()->with('contacts')->orderBy('created_at', 'desc')->get();
$clients = Utils::remapPublicIds($clients->toArray());
$response = json_encode($clients, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders(count($clients));
return Response::make($response, 200, $headers);
}
public function store()
{
if (!Utils::isPro()) {
Redirect::to('/');
}
$data = Input::all();
$client = $this->clientRepo->save(false, $data, false);
2014-05-13 23:04:42 +02:00
2014-07-27 22:31:41 +02:00
$response = json_encode($client, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
2014-05-13 22:24:40 +02:00
return Response::make($response, 200, $headers);
2014-05-13 21:20:54 +02:00
}
}