mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Consistent use of links in transformers.
This commit is contained in:
@@ -25,12 +25,14 @@ namespace FireflyIII\Api\V1\Controllers;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Transformers\BillTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Manager;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\Serializer\JsonApiSerializer;
|
||||
use Preferences;
|
||||
use Response;
|
||||
@@ -40,6 +42,24 @@ use Response;
|
||||
*/
|
||||
class BillController extends Controller
|
||||
{
|
||||
/** @var BillRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* BillController constructor.
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
/** @var BillRepositoryInterface repository */
|
||||
$this->repository = app(BillRepositoryInterface::class);
|
||||
$user = Auth::guard('api')->user();
|
||||
$this->repository->setUser($user);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
@@ -49,7 +69,8 @@ class BillController extends Controller
|
||||
*/
|
||||
public function destroy(Bill $bill)
|
||||
{
|
||||
//
|
||||
$this->repository->destroy($bill);
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +90,7 @@ class BillController extends Controller
|
||||
if (null !== $request->get('end')) {
|
||||
$end = new Carbon($request->get('end'));
|
||||
}
|
||||
$paginator = $user->bills()->paginate($pageSize);
|
||||
$paginator = $this->repository->getPaginator($pageSize);
|
||||
/** @var Collection $bills */
|
||||
$bills = $paginator->getCollection();
|
||||
|
||||
@@ -80,7 +101,6 @@ class BillController extends Controller
|
||||
$resource = new FractalCollection($bills, new BillTransformer($start, $end), 'bills');
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
|
||||
return Response::json($manager->createData($resource)->toArray());
|
||||
}
|
||||
|
||||
@@ -89,11 +109,28 @@ class BillController extends Controller
|
||||
*
|
||||
* @param \FireflyIII\Models\Bill $bill
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Bill $bill)
|
||||
public function show(Request $request, Bill $bill)
|
||||
{
|
||||
//
|
||||
$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'));
|
||||
}
|
||||
|
||||
|
||||
$manager = new Manager();
|
||||
$manager->parseIncludes(['attachments']);
|
||||
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$resource = new Item($bill, new BillTransformer($start, $end), 'bill');
|
||||
|
||||
return Response::json($manager->createData($resource)->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user