2018-02-04 13:41:42 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* BillController.php
|
|
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Api\V1\Controllers;
|
|
|
|
|
2018-02-04 15:57:35 +01:00
|
|
|
use Auth;
|
2018-02-06 07:49:56 +01:00
|
|
|
use Carbon\Carbon;
|
2018-02-04 13:41:42 +01:00
|
|
|
use FireflyIII\Models\Bill;
|
2018-02-06 07:49:56 +01:00
|
|
|
use FireflyIII\Transformers\Bill\BillTransformer;
|
2018-02-04 13:41:42 +01:00
|
|
|
use Illuminate\Http\Request;
|
2018-02-06 07:49:56 +01:00
|
|
|
use Illuminate\Support\Collection;
|
2018-02-04 15:57:35 +01:00
|
|
|
use League\Fractal\Manager;
|
|
|
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
|
use League\Fractal\Resource\Collection as FractalCollection;
|
|
|
|
use League\Fractal\Serializer\JsonApiSerializer;
|
|
|
|
use Preferences;
|
|
|
|
use Response;
|
2018-02-04 13:41:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BillController
|
|
|
|
*/
|
|
|
|
class BillController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param \FireflyIII\Models\Bill $bill
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy(Bill $bill)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2018-02-04 15:57:35 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2018-02-04 13:41:42 +01:00
|
|
|
*/
|
2018-02-04 15:57:35 +01:00
|
|
|
public function index(Request $request)
|
2018-02-04 13:41:42 +01:00
|
|
|
{
|
2018-02-06 07:49:56 +01:00
|
|
|
$user = Auth::guard('api')->user();
|
|
|
|
$pageSize = intval(Preferences::getForUser($user, 'listPageSize', 50)->data);
|
|
|
|
$start = null;
|
|
|
|
$end = null;
|
|
|
|
if (null !== $request->get('start')) {
|
|
|
|
$start = new Carbon($request->get('start'));
|
|
|
|
}
|
|
|
|
if (null !== $request->get('end')) {
|
|
|
|
$end = new Carbon($request->get('end'));
|
|
|
|
}
|
2018-02-04 15:57:35 +01:00
|
|
|
$paginator = $user->bills()->paginate($pageSize);
|
2018-02-06 07:49:56 +01:00
|
|
|
/** @var Collection $bills */
|
|
|
|
$bills = $paginator->getCollection();
|
2018-02-04 15:57:35 +01:00
|
|
|
|
|
|
|
$manager = new Manager();
|
|
|
|
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
|
|
|
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
|
|
|
|
2018-02-06 07:49:56 +01:00
|
|
|
$resource = new FractalCollection($bills, new BillTransformer($start, $end), 'bills');
|
2018-02-04 15:57:35 +01:00
|
|
|
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
|
|
|
|
|
|
|
|
|
|
|
return Response::json($manager->createData($resource)->toArray());
|
2018-02-04 13:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param \FireflyIII\Models\Bill $bill
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show(Bill $bill)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \FireflyIII\Models\Bill $bill
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, Bill $bill)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|