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()
|
2016-01-06 15:23:58 +01:00
|
|
|
->with($this->getIncluded())
|
2016-02-17 04:32:20 +01:00
|
|
|
->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', 'vendorcontacts', 'industry', 'size', 'currency')
|
|
|
|
->first();
|
|
|
|
|
|
|
|
$transformer = new VendorTransformer(Auth::user()->account, Input::get('serializer'));
|
|
|
|
$data = $this->createItem($vendor, $transformer, ENTITY_VENDOR);
|
|
|
|
return $this->response($data);
|
|
|
|
}
|
|
|
|
}
|