mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup
This commit is contained in:
@@ -27,6 +27,9 @@ namespace FireflyIII\Api\V2\Controllers\Summary;
|
||||
use FireflyIII\Api\V2\Controllers\Controller;
|
||||
use FireflyIII\Api\V2\Request\Generic\SingleDateRequest;
|
||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Api\ConvertsExchangeRates;
|
||||
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -39,7 +42,8 @@ class NetWorthController extends Controller
|
||||
use ValidatesUserGroupTrait;
|
||||
use ConvertsExchangeRates;
|
||||
|
||||
private NetWorthInterface $netWorth;
|
||||
private NetWorthInterface $netWorth;
|
||||
private AccountRepositoryInterface $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -49,12 +53,13 @@ class NetWorthController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->netWorth = app(NetWorthInterface::class);
|
||||
|
||||
$this->netWorth = app(NetWorthInterface::class);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
// new way of user group validation
|
||||
$userGroup = $this->validateUserGroup($request);
|
||||
if (null !== $userGroup) {
|
||||
$this->netWorth->setUserGroup($userGroup);
|
||||
$this->repository->setUserGroup($userGroup);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
@@ -72,10 +77,21 @@ class NetWorthController extends Controller
|
||||
*/
|
||||
public function get(SingleDateRequest $request): JsonResponse
|
||||
{
|
||||
$date = $request->getDate();
|
||||
$result = $this->netWorth->sumNetWorthByCurrency($date);
|
||||
$converted = $this->cerSum($result);
|
||||
$date = $request->getDate();
|
||||
$accounts = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
|
||||
return response()->api($converted);
|
||||
// filter list on preference of being included.
|
||||
$filtered = $accounts->filter(
|
||||
function (Account $account) {
|
||||
$includeNetWorth = $this->repository->getMetaValue($account, 'include_net_worth');
|
||||
|
||||
return null === $includeNetWorth || '1' === $includeNetWorth;
|
||||
}
|
||||
);
|
||||
|
||||
// skip accounts that should not be in the net worth
|
||||
$result = $this->netWorth->byAccounts($filtered, $date);
|
||||
|
||||
return response()->api($result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user