mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
working on product API
This commit is contained in:
parent
020e428677
commit
cc40f51f84
83
app/Http/Controllers/ProductApiController.php
Normal file
83
app/Http/Controllers/ProductApiController.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Str;
|
||||
use DB;
|
||||
use Datatable;
|
||||
use Utils;
|
||||
use URL;
|
||||
use View;
|
||||
use Input;
|
||||
use Session;
|
||||
use Redirect;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\TaxRate;
|
||||
use App\Services\ProductService;
|
||||
|
||||
class ProductApiController extends BaseAPIController
|
||||
{
|
||||
protected $productService;
|
||||
|
||||
public function __construct(ProductService $productService)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->productService = $productService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
//stub
|
||||
}
|
||||
|
||||
public function getDatatable()
|
||||
{
|
||||
return $this->productService->getDatatable(Auth::user()->account_id);
|
||||
}
|
||||
|
||||
public function edit($publicId)
|
||||
{
|
||||
//stub
|
||||
}
|
||||
|
||||
|
||||
public function store()
|
||||
{
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
public function update($publicId)
|
||||
{
|
||||
return $this->save($publicId);
|
||||
}
|
||||
|
||||
public function destroy()
|
||||
{
|
||||
//stub
|
||||
}
|
||||
|
||||
private function save($productPublicId = false)
|
||||
{
|
||||
if ($productPublicId) {
|
||||
$product = Product::scope($productPublicId)->firstOrFail();
|
||||
} else {
|
||||
$product = Product::createNew();
|
||||
}
|
||||
|
||||
$product->product_key = trim(Input::get('product_key'));
|
||||
$product->notes = trim(Input::get('notes'));
|
||||
$product->cost = trim(Input::get('cost'));
|
||||
//$product->default_tax_rate_id = Input::get('default_tax_rate_id');
|
||||
|
||||
$product->save();
|
||||
|
||||
$transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
|
||||
$data = $this->createItem($product, $transformer, 'products');
|
||||
|
||||
return $this->response($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -232,6 +232,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
|
||||
Route::post('email_invoice', 'InvoiceApiController@emailInvoice');
|
||||
Route::post('email_invoicev2', 'InvoiceApiController@emailInvoicev2');
|
||||
Route::get('user_accounts','AccountApiController@getUserAccounts');
|
||||
Route::resource('products', 'ProductApiController');
|
||||
|
||||
// Vendor
|
||||
Route::resource('vendors', 'VendorApiController');
|
||||
|
Loading…
Reference in New Issue
Block a user