Files
firefly-iii/app/Api/V1/Controllers/Insight/Transfer/AccountController.php

78 lines
2.3 KiB
PHP
Raw Normal View History

2021-03-07 15:26:42 +01:00
<?php
/*
* AccountController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-03-28 11:39:26 +02:00
declare(strict_types=1);
2021-03-07 15:26:42 +01:00
2021-03-28 11:39:26 +02:00
namespace FireflyIII\Api\V1\Controllers\Insight\Transfer;
2021-03-07 15:26:42 +01:00
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
use FireflyIII\Repositories\Account\OperationsRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport;
use Illuminate\Http\JsonResponse;
/**
* Class AccountController
*/
class AccountController extends Controller
{
use ApiSupport;
private OperationsRepositoryInterface $opsRepository;
/**
* AccountController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->opsRepository->setUser($user);
return $next($request);
}
);
}
/**
2021-09-18 05:58:22 +02:00
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/#/insight/insightTransfers
2021-04-03 07:16:43 +02:00
*
2021-03-07 15:26:42 +01:00
* @param GenericRequest $request
*
* @return JsonResponse
*/
public function asset(GenericRequest $request): JsonResponse
{
$start = $request->getStart();
$end = $request->getEnd();
$assetAccounts = $request->getAssetAccounts();
2021-04-03 07:16:43 +02:00
$transfers = $this->opsRepository->sumTransfers($start, $end, $assetAccounts);
2021-04-03 07:16:43 +02:00
return response()->json($transfers);
2021-03-07 15:26:42 +01:00
}
2021-03-28 11:39:26 +02:00
}