1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 17:31:35 +02:00
invoiceninja/app/Http/Controllers/ClientApiController.php

89 lines
2.4 KiB
PHP
Raw Normal View History

2015-03-17 02:30:56 +01:00
<?php namespace App\Http\Controllers;
2015-03-16 22:45:25 +01:00
2015-04-08 20:19:58 +02:00
use Utils;
use Response;
use Input;
use App\Models\Client;
use App\Ninja\Repositories\ClientRepository;
2015-10-28 20:22:07 +01:00
use App\Http\Requests\CreateClientRequest;
2015-03-16 22:45:25 +01:00
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);
}
2015-11-08 22:57:28 +01:00
/**
* @SWG\Get(
* path="/clients",
* summary="List of clients",
* tags={"client"},
* @SWG\Response(
* response=200,
* description="A list with clients",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Client"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2015-03-16 22:45:25 +01:00
public function index()
{
2015-07-02 22:21:29 +02:00
$clients = Client::scope()
->with('country', 'contacts', 'industry', 'size', 'currency')
->orderBy('created_at', 'desc')
->get();
$clients = Utils::remapPublicIds($clients);
2015-03-16 22:45:25 +01:00
$response = json_encode($clients, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders(count($clients));
return Response::make($response, 200, $headers);
}
2015-11-08 22:57:28 +01:00
/**
* @SWG\Post(
* path="/clients",
* tags={"client"},
* summary="Create a client",
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Client")
* ),
* @SWG\Response(
* response=200,
* description="New client",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Client"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2015-10-28 20:22:07 +01:00
public function store(CreateClientRequest $request)
2015-03-16 22:45:25 +01:00
{
2015-10-28 20:22:07 +01:00
$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);
2015-03-16 22:45:25 +01:00
}
}