1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Http/Controllers/ProductApiController.php
Holger Lösken 0fbda85a59 Code Refactoring
- Removed unused uses
- Type hinting for method parameters
- Removed commented code
- Introduced comments for classes and methods
- Short array syntax
2016-07-03 16:19:22 +00:00

76 lines
1.7 KiB
PHP

<?php namespace App\Http\Controllers;
use App\Models\Product;
use App\Ninja\Repositories\ProductRepository;
use App\Http\Requests\CreateProductRequest;
use App\Http\Requests\UpdateProductRequest;
/**
* Class ProductApiController
*/
class ProductApiController extends BaseAPIController
{
/**
* @var string
*/
protected $entityType = ENTITY_PRODUCT;
/**
* @var ProductRepository
*/
protected $productRepo;
/**
* ProductApiController constructor.
*
* @param ProductRepository $productRepo
*/
public function __construct(ProductRepository $productRepo)
{
parent::__construct();
$this->productRepo = $productRepo;
}
/**
* @return \Illuminate\Http\Response
*/
public function index()
{
$products = Product::scope()
->withTrashed()
->orderBy('created_at', 'desc');
return $this->listResponse($products);
}
/**
* @param CreateProductRequest $request
* @return \Illuminate\Http\Response
*/
public function store(CreateProductRequest $request)
{
$product = $this->productRepo->save($request->input());
return $this->itemResponse($product);
}
/**
* @param UpdateProductRequest $request
* @param $publicId
* @return \Illuminate\Http\Response
*/
public function update(UpdateProductRequest $request, $publicId)
{
if ($request->action) {
return $this->handleAction($request);
}
$data = $request->input();
$data['public_id'] = $publicId;
$product = $this->productRepo->save($data, $request->entity());
return $this->itemResponse($product);
}
}