1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Http/Controllers/TaxRateApiController.php

188 lines
4.7 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Http\Controllers;
use App\Http\Requests\TaxRateRequest;
use App\Http\Requests\CreateTaxRateRequest;
use App\Http\Requests\UpdateTaxRateRequest;
2017-01-30 20:40:43 +01:00
use App\Models\TaxRate;
use App\Ninja\Repositories\TaxRateRepository;
class TaxRateApiController extends BaseAPIController
{
/**
* @var TaxRateRepository
*/
protected $taxRateRepo;
/**
* @var string
*/
2016-05-01 22:55:13 +02:00
protected $entityType = ENTITY_TAX_RATE;
/**
* TaxRateApiController constructor.
2017-01-30 20:40:43 +01:00
*
* @param TaxRateRepository $taxRateRepo
*/
2016-05-02 15:12:37 +02:00
public function __construct(TaxRateRepository $taxRateRepo)
{
2016-03-02 15:36:46 +01:00
parent::__construct();
$this->taxRateRepo = $taxRateRepo;
}
2016-12-29 17:17:17 +01:00
/**
* @SWG\Get(
* path="/tax_rates",
* summary="List of tax rates",
* tags={"tax_rate"},
* @SWG\Response(
* response=200,
* description="A list of tax rates",
2016-12-29 17:17:17 +01:00
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/TaxRate"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function index()
{
2016-05-01 22:55:13 +02:00
$taxRates = TaxRate::scope()
->withTrashed()
->orderBy('created_at', 'desc');
2016-05-02 15:12:37 +02:00
2016-05-02 10:38:01 +02:00
return $this->listResponse($taxRates);
}
/**
* @SWG\Get(
* path="/tax_rates/{tax_rate_id}",
* tags={"tax_rate"},
* summary="Retrieve a tax rate",
* @SWG\Parameter(
* in="path",
* name="tax_rate_id",
* type="integer",
* required="true"
* ),
* @SWG\Response(
* response=200,
* description="A single tax rate",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function show(TaxRateRequest $request)
{
return $this->itemResponse($request->entity());
}
2016-12-29 17:17:17 +01:00
/**
* @SWG\Post(
* path="/tax_rates",
* tags={"tax_rate"},
* summary="Create a tax rate",
* @SWG\Parameter(
* in="body",
* name="tax_rate",
2016-12-29 17:17:17 +01:00
* @SWG\Schema(ref="#/definitions/TaxRate")
* ),
* @SWG\Response(
* response=200,
* description="New tax rate",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function store(CreateTaxRateRequest $request)
{
2016-05-02 15:12:37 +02:00
$taxRate = $this->taxRateRepo->save($request->input());
return $this->itemResponse($taxRate);
}
/**
2016-12-29 17:17:17 +01:00
* @SWG\Put(
* path="/tax_rates/{tax_rate_id}",
* tags={"tax_rate"},
* summary="Update a tax rate",
* @SWG\Parameter(
* in="path",
* name="tax_rate_id",
* type="integer",
* required="true"
* ),
* @SWG\Parameter(
2016-12-29 17:17:17 +01:00
* in="body",
* name="tax_rate",
2016-12-29 17:17:17 +01:00
* @SWG\Schema(ref="#/definitions/TaxRate")
* ),
* @SWG\Response(
* response=200,
* description="Updated tax rate",
2016-12-29 17:17:17 +01:00
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
2017-01-30 20:54:09 +01:00
*
2017-01-30 20:49:42 +01:00
* @param mixed $publicId
*/
2016-05-02 15:12:37 +02:00
public function update(UpdateTaxRateRequest $request, $publicId)
{
2016-05-02 15:12:37 +02:00
if ($request->action) {
return $this->handleAction($request);
}
2016-12-29 17:17:17 +01:00
2016-05-02 15:12:37 +02:00
$data = $request->input();
$data['public_id'] = $publicId;
$taxRate = $this->taxRateRepo->save($data, $request->entity());
2016-05-02 15:12:37 +02:00
return $this->itemResponse($taxRate);
}
/**
* @SWG\Delete(
* path="/tax_rates/{tax_rate_id}",
* tags={"tax_rate"},
* summary="Delete a tax rate",
* @SWG\Parameter(
* in="path",
* name="tax_rate_id",
* type="integer",
* required="true"
* ),
* @SWG\Response(
* response=200,
* description="Deleted tax rate",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/TaxRate"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function destroy(TaxRateRequest $request)
{
$entity = $request->entity();
$this->taxRateRepo->delete($entity);
return $this->itemResponse($entity);
}
}