1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/controllers/ClientApiController.php

58 lines
1.3 KiB
PHP
Raw Normal View History

2014-05-13 21:20:54 +02:00
<?php
use ninja\repositories\ClientRepository;
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()) {
2014-07-30 09:08:01 +02:00
return Redirect::to('/');
2014-07-27 22:31:41 +02:00
}
$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()) {
2014-07-30 09:08:01 +02:00
return Redirect::to('/');
2014-07-27 22:31:41 +02:00
}
$data = Input::all();
2014-07-30 09:08:01 +02:00
$error = $this->clientRepo->getErrors($data);
if ($error)
{
$headers = Utils::getApiHeaders();
return Response::make($error, 500, $headers);
}
else
{
$client = $this->clientRepo->save(false, $data, false);
$response = json_encode($client, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
return Response::make($response, 200, $headers);
}
2014-05-13 23:04:42 +02:00
2014-05-13 21:20:54 +02:00
}
}