1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Http/Controllers/VendorApiController.php

90 lines
2.2 KiB
PHP
Raw Normal View History

2016-01-06 15:23:58 +01:00
<?php namespace App\Http\Controllers;
2016-01-07 16:21:13 +01:00
// vendor
2016-01-06 15:23:58 +01:00
use Utils;
use Response;
use Input;
use Auth;
use App\Models\Vendor;
use App\Ninja\Repositories\VendorRepository;
use App\Http\Requests\CreateVendorRequest;
use App\Http\Controllers\BaseAPIController;
use App\Ninja\Transformers\VendorTransformer;
class VendorApiController extends BaseAPIController
{
protected $vendorRepo;
2016-05-01 22:55:13 +02:00
protected $entityType = ENTITY_VENDOR;
2016-01-06 15:23:58 +01:00
public function __construct(VendorRepository $vendorRepo)
{
2016-03-02 15:36:46 +01:00
parent::__construct();
2016-01-06 15:23:58 +01:00
$this->vendorRepo = $vendorRepo;
}
public function ping()
{
$headers = Utils::getApiHeaders();
return Response::make('', 200, $headers);
}
/**
* @SWG\Get(
* path="/vendors",
* summary="List of vendors",
* tags={"vendor"},
* @SWG\Response(
* response=200,
* description="A list with vendors",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Vendor"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function index()
{
2016-05-01 22:55:13 +02:00
$vendors = Vendor::scope()
->withTrashed()
2016-05-01 22:55:13 +02:00
->orderBy('created_at', 'desc');
2016-01-06 15:23:58 +01:00
2016-05-02 10:38:01 +02:00
return $this->listResponse($vendors);
2016-01-06 15:23:58 +01:00
}
/**
* @SWG\Post(
* path="/vendors",
* tags={"vendor"},
* summary="Create a vendor",
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Vendor")
* ),
* @SWG\Response(
* response=200,
* description="New vendor",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Vendor"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function store(CreateVendorRequest $request)
{
$vendor = $this->vendorRepo->save($request->input());
2016-03-02 14:36:42 +01:00
2016-01-06 15:23:58 +01:00
$vendor = Vendor::scope($vendor->public_id)
->with('country', 'vendor_contacts', 'industry', 'size', 'currency')
2016-01-06 15:23:58 +01:00
->first();
2016-05-02 15:12:37 +02:00
return $this->itemResponse($vendor);
2016-01-06 15:23:58 +01:00
}
}