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

193 lines
4.8 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 tax rates",
* operationId="listTaxRates",
2016-12-29 17:17:17 +01:00
* 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}",
* summary="Retrieve a tax rate",
* operationId="getTaxRate",
* tags={"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",
* summary="Create a tax rate",
* operationId="createTaxRate",
* tags={"tax_rate"},
2016-12-29 17:17:17 +01:00
* @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}",
* summary="Update a tax rate",
* operationId="updateTaxRate",
* tags={"tax_rate"},
2016-12-29 17:17:17 +01:00
* @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}",
* summary="Delete a tax rate",
* operationId="deleteTaxRate",
* tags={"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(UpdateTaxRateRequest $request)
{
$entity = $request->entity();
$this->taxRateRepo->delete($entity);
return $this->itemResponse($entity);
}
}