Merge pull request #677 from turbo124/master

Archive Product via API
This commit is contained in:
David Bomba 2016-02-01 13:33:27 +11:00
commit eef8ad22d0
2 changed files with 20 additions and 4 deletions

View File

@ -1,5 +1,6 @@
<?php namespace App\Http\Controllers; <?php namespace App\Http\Controllers;
use App\Ninja\Repositories\ProductRepository;
use App\Ninja\Transformers\ProductTransformer; use App\Ninja\Transformers\ProductTransformer;
use Auth; use Auth;
use Str; use Str;
@ -20,11 +21,14 @@ class ProductApiController extends BaseAPIController
{ {
protected $productService; protected $productService;
public function __construct(ProductService $productService) protected $productRepo;
public function __construct(ProductService $productService, ProductRepository $productRepo)
{ {
parent::__construct(); parent::__construct();
$this->productService = $productService; $this->productService = $productService;
$this->productRepo = $productRepo;
} }
public function index() public function index()
@ -52,14 +56,25 @@ class ProductApiController extends BaseAPIController
return $this->save(); return $this->save();
} }
public function update($publicId) public function update(\Illuminate\Http\Request $request, $publicId)
{ {
return $this->save($publicId);
if ($request->action == ACTION_ARCHIVE) {
$product = Product::scope($publicId)->withTrashed()->firstOrFail();
$this->productRepo->archive($product);
$transformer = new ProductTransformer(\Auth::user()->account, Input::get('serializer'));
$data = $this->createItem($product, $transformer, 'products');
return $this->response($data);
}
else
return $this->save($publicId);
} }
public function destroy($publicId) public function destroy($publicId)
{ {
//stub //stub
} }
private function save($productPublicId = false) private function save($productPublicId = false)

View File

@ -16,6 +16,7 @@ class ProductTransformer extends EntityTransformer
'account_key' =>$this->account->account_key, 'account_key' =>$this->account->account_key,
'default_tax_rate_id' =>$product->default_tax_rate_id, 'default_tax_rate_id' =>$product->default_tax_rate_id,
'updated_at' =>$this->getTimestamp($product->updated_at), 'updated_at' =>$this->getTimestamp($product->updated_at),
'archived_at' => $this->getTimestamp($product->deleted_at),
]; ];
} }
} }