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

76 lines
1.7 KiB
PHP
Raw Normal View History

2016-01-30 10:56:27 +01:00
<?php namespace App\Http\Controllers;
use App\Models\Product;
2016-05-02 15:12:37 +02:00
use App\Ninja\Repositories\ProductRepository;
use App\Http\Requests\CreateProductRequest;
use App\Http\Requests\UpdateProductRequest;
2016-01-30 10:56:27 +01:00
/**
* Class ProductApiController
*/
2016-01-30 10:56:27 +01:00
class ProductApiController extends BaseAPIController
{
/**
* @var string
*/
2016-05-01 22:55:13 +02:00
protected $entityType = ENTITY_PRODUCT;
2016-02-01 03:32:12 +01:00
/**
* @var ProductRepository
*/
protected $productRepo;
/**
* ProductApiController constructor.
*
* @param ProductRepository $productRepo
*/
2016-05-02 15:12:37 +02:00
public function __construct(ProductRepository $productRepo)
2016-01-30 10:56:27 +01:00
{
2016-03-02 15:36:46 +01:00
parent::__construct();
2016-01-30 10:56:27 +01:00
2016-02-01 03:32:12 +01:00
$this->productRepo = $productRepo;
2016-01-30 10:56:27 +01:00
}
/**
* @return \Illuminate\Http\Response
*/
2016-01-30 10:56:27 +01:00
public function index()
{
2016-05-01 22:55:13 +02:00
$products = Product::scope()
->withTrashed()
->orderBy('created_at', 'desc');
2016-01-30 11:51:52 +01:00
2016-05-02 10:38:01 +02:00
return $this->listResponse($products);
2016-01-30 10:56:27 +01:00
}
/**
* @param CreateProductRequest $request
* @return \Illuminate\Http\Response
*/
2016-05-02 15:12:37 +02:00
public function store(CreateProductRequest $request)
2016-01-30 10:56:27 +01:00
{
2016-05-02 15:12:37 +02:00
$product = $this->productRepo->save($request->input());
2016-01-30 10:56:27 +01:00
2016-05-02 15:12:37 +02:00
return $this->itemResponse($product);
2016-01-30 10:56:27 +01:00
}
/**
* @param UpdateProductRequest $request
* @param $publicId
* @return \Illuminate\Http\Response
*/
2016-05-02 15:12:37 +02:00
public function update(UpdateProductRequest $request, $publicId)
2016-01-30 10:56:27 +01:00
{
2016-05-02 15:12:37 +02:00
if ($request->action) {
return $this->handleAction($request);
2016-02-01 03:32:12 +01:00
}
2016-05-02 15:12:37 +02:00
$data = $request->input();
$data['public_id'] = $publicId;
$product = $this->productRepo->save($data, $request->entity());
2016-05-02 15:12:37 +02:00
return $this->itemResponse($product);
2016-01-30 10:56:27 +01:00
}
}