1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Merge pull request #1106 from turbo124/develop

Vendor API POST and PUT methods
This commit is contained in:
David Bomba 2016-10-18 20:36:40 +11:00 committed by GitHub
commit ce0662f7b3
3 changed files with 72 additions and 10666 deletions

View File

@ -1,5 +1,6 @@
<?php namespace App\Http\Controllers;
// vendor
use App\Http\Requests\UpdateVendorRequest;
use Utils;
use Response;
use Input;
@ -83,4 +84,73 @@ class VendorApiController extends BaseAPIController
return $this->itemResponse($vendor);
}
/**
* @SWG\Put(
* path="/vendors/{vendor_id}",
* tags={"vendor"},
* summary="Update a vendor",
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Vendor")
* ),
* @SWG\Response(
* response=200,
* description="Update vendor",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Vendor"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function update(UpdateVendorRequest $request, $publicId)
{
if ($request->action) {
return $this->handleAction($request);
}
$data = $request->input();
$data['public_id'] = $publicId;
$vendor = $this->vendorRepo->save($data, $request->entity());
$vendor->load(['vendor_contacts']);
return $this->itemResponse($vendor);
}
/**
* @SWG\Delete(
* path="/vendors/{vendor_id}",
* tags={"vendor"},
* summary="Delete a vendor",
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Vendor")
* ),
* @SWG\Response(
* response=200,
* description="Delete vendor",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Vendor"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function destroy(UpdateVendorRequest $request)
{
$vendor = $request->entity();
$this->vendorRepo->delete($vendor);
return $this->itemResponse($vendor);
}
}

View File

@ -211,7 +211,8 @@ class Vendor extends EntityModel
*/
public function addVendorContact($data, $isPrimary = false)
{
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
//$publicId = isset($data['public_id']) ? $data['public_id'] : false;
$publicId = isset($data['public_id']) ? $data['public_id'] : (isset($data['id']) ? $data['id'] : false);
if ($publicId && $publicId != '-1') {
$contact = VendorContact::scope($publicId)->firstOrFail();

10665
composer.lock generated

File diff suppressed because it is too large Load Diff