1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Http/Controllers/ExpenseCategoryApiController.php

172 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\ExpenseCategoryRequest;
use App\Http\Requests\CreateExpenseCategoryRequest;
use App\Http\Requests\UpdateExpenseCategoryRequest;
use App\Models\ExpenseCategory;
use App\Ninja\Repositories\ExpenseCategoryRepository;
2017-01-30 20:40:43 +01:00
use App\Services\ExpenseCategoryService;
use Input;
class ExpenseCategoryApiController extends BaseAPIController
{
protected $categoryRepo;
protected $categoryService;
protected $entityType = ENTITY_EXPENSE_CATEGORY;
public function __construct(ExpenseCategoryRepository $categoryRepo, ExpenseCategoryService $categoryService)
{
2016-10-28 11:01:35 +02:00
parent::__construct();
2016-12-29 17:17:17 +01:00
$this->categoryRepo = $categoryRepo;
$this->categoryService = $categoryService;
}
/**
* @SWG\Get(
* path="/expense_categories",
* summary="List of expense categories",
* tags={"expense_category"},
* @SWG\Response(
* response=200,
* description="A list of expense categories",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/ExpenseCategory"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function index()
{
$clients = ExpenseCategory::scope()
->orderBy('created_at', 'desc')
->withTrashed();
return $this->listResponse($clients);
}
/**
* @SWG\Get(
* path="/expense_categories/{expense_category_id}",
* summary="Individual Expense Category",
* tags={"expense_category"},
* @SWG\Parameter(
* in="path",
* name="expense_category_id",
* type="integer",
* required="true"
* ),
* @SWG\Response(
* response=200,
* description="A single expense categroy",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/ExpenseCategory"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function show(ExpenseCategory $request)
{
return $this->itemResponse($request->entity());
}
2016-12-29 17:17:17 +01:00
/**
* @SWG\Post(
* path="/expense_categories",
* tags={"expense_category"},
* summary="Create an expense category",
* @SWG\Parameter(
* in="body",
* name="expense_category",
2016-12-29 17:17:17 +01:00
* @SWG\Schema(ref="#/definitions/ExpenseCategory")
* ),
* @SWG\Response(
* response=200,
* description="New expense category",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/ExpenseCategory"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function store(CreateExpenseCategoryRequest $request)
{
2016-12-29 17:17:17 +01:00
$category = $this->categoryRepo->save($request->input());
return $this->itemResponse($category);
}
2016-12-29 17:17:17 +01:00
/**
* @SWG\Put(
* path="/expense_categories/{expense_category_id}",
* tags={"expense_category"},
* summary="Update an expense category",
* @SWG\Parameter(
* in="path",
* name="expense_category_id",
* type="integer",
* required="true"
* ),
* @SWG\Parameter(
2016-12-29 17:17:17 +01:00
* in="body",
* name="expense_category",
2016-12-29 17:17:17 +01:00
* @SWG\Schema(ref="#/definitions/ExpenseCategory")
* ),
* @SWG\Response(
* response=200,
* description="Updated expense category",
2016-12-29 17:17:17 +01:00
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/ExpenseCategory"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function update(UpdateExpenseCategoryRequest $request)
{
2016-12-29 17:17:17 +01:00
$category = $this->categoryRepo->save($request->input(), $request->entity());
return $this->itemResponse($category);
}
/**
* @SWG\Delete(
* path="/expense_categories/{expense_category_id}",
* tags={"expense_category"},
* summary="Delete an expense category",
* @SWG\Parameter(
* in="path",
* name="expense_category_id",
* type="integer",
* required="true"
* ),
* @SWG\Response(
* response=200,
* description="Deleted expense category",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/ExpenseCategory"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function destroy(ExpenseCategoryRequest $request)
{
$entity = $request->entity();
$this->expenseCategoryRepo->delete($entity);
return $this->itemResponse($entity);
}
}