diff --git a/app/Api/V2/Controllers/Autocomplete/AccountController.php b/app/Api/V2/Controllers/Autocomplete/AccountController.php new file mode 100644 index 0000000000..1e35e7463a --- /dev/null +++ b/app/Api/V2/Controllers/Autocomplete/AccountController.php @@ -0,0 +1,32 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\Autocomplete; + +use FireflyIII\Api\V2\Controllers\Controller; + +/** + * Class AccountController + */ +class AccountController extends Controller +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.php index 8d8ab59805..9a85614137 100644 --- a/app/Api/V2/Controllers/Controller.php +++ b/app/Api/V2/Controllers/Controller.php @@ -21,10 +21,13 @@ namespace FireflyIII\Api\V2\Controllers; -use FireflyIII\Transformers\AbstractTransformer; +use FireflyIII\Transformers\V2\AbstractTransformer; use Illuminate\Database\Eloquent\Model; +use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Routing\Controller as BaseController; 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; @@ -34,6 +37,19 @@ use League\Fractal\Serializer\JsonApiSerializer; class Controller extends BaseController { protected const CONTENT_TYPE = 'application/vnd.api+json'; + protected int $pageSize; + + /** + * + */ + public function __construct() + { + $this->pageSize = 50; + if (auth()->check()) { + $this->pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + } + } + /** * Returns a JSON API object and returns it. * @@ -53,4 +69,23 @@ class Controller extends BaseController return $manager->createData($resource)->toArray(); } + /** + * @param string $key + * @param LengthAwarePaginator $paginator + * @param AbstractTransformer $transformer + * @return array + */ + final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array + { + $manager = new Manager; + $baseUrl = request()->getSchemeAndHttpHost() . '/api/v2'; + $manager->setSerializer(new JsonApiSerializer($baseUrl)); + + $objects = $paginator->getCollection(); + $resource = new FractalCollection($objects, $transformer, $key); + $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); + + return $manager->createData($resource)->toArray(); + } + } diff --git a/app/Api/V2/Controllers/Data/Bulk/AccountController.php b/app/Api/V2/Controllers/Data/Bulk/AccountController.php new file mode 100644 index 0000000000..2307ab3856 --- /dev/null +++ b/app/Api/V2/Controllers/Data/Bulk/AccountController.php @@ -0,0 +1,32 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\Data\Bulk; + +use FireflyIII\Api\V2\Controllers\Controller; + +/** + * Class AccountController + */ +class AccountController extends Controller +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Controllers/Data/Export/AccountController.php b/app/Api/V2/Controllers/Data/Export/AccountController.php new file mode 100644 index 0000000000..1c9472958b --- /dev/null +++ b/app/Api/V2/Controllers/Data/Export/AccountController.php @@ -0,0 +1,32 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\Data\Export; + +use FireflyIII\Api\V2\Controllers\Controller; + +/** + * Class AccountController + */ +class AccountController extends Controller +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Controllers/Data/MassDestroy/AccountController.php b/app/Api/V2/Controllers/Data/MassDestroy/AccountController.php new file mode 100644 index 0000000000..00425f2a61 --- /dev/null +++ b/app/Api/V2/Controllers/Data/MassDestroy/AccountController.php @@ -0,0 +1,32 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\Data\MassDestroy; + +use FireflyIII\Api\V2\Controllers\Controller; + +/** + * Class AccountController + */ +class AccountController extends Controller +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Controllers/Model/Account/ShowController.php b/app/Api/V2/Controllers/Model/Account/ShowController.php new file mode 100644 index 0000000000..e58a686885 --- /dev/null +++ b/app/Api/V2/Controllers/Model/Account/ShowController.php @@ -0,0 +1,44 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\Model\Account; + +use FireflyIII\Api\V2\Controllers\Controller; +use FireflyIII\Models\Account; +use FireflyIII\Transformers\V2\AccountTransformer; +use Illuminate\Http\JsonResponse; + +/** + * Class ShowController + */ +class ShowController extends Controller +{ + + /** + * @param Account $account + * @return JsonResponse + */ + public function show(Account $account): JsonResponse + { + $transformer = new AccountTransformer; + return response()->json($this->jsonApiObject('accounts', $account, $transformer)); + } +} diff --git a/app/Api/V2/Controllers/Search/AccountController.php b/app/Api/V2/Controllers/Search/AccountController.php new file mode 100644 index 0000000000..b5596e6b73 --- /dev/null +++ b/app/Api/V2/Controllers/Search/AccountController.php @@ -0,0 +1,32 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\Search; + +use FireflyIII\Api\V2\Controllers\Controller; + +/** + * Class AccountController + */ +class AccountController extends Controller +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Controllers/System/ConfigurationController.php b/app/Api/V2/Controllers/System/ConfigurationController.php new file mode 100644 index 0000000000..04679c004c --- /dev/null +++ b/app/Api/V2/Controllers/System/ConfigurationController.php @@ -0,0 +1,27 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\System; + +class ConfigurationController +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Controllers/System/DebugController.php b/app/Api/V2/Controllers/System/DebugController.php new file mode 100644 index 0000000000..0e84bb1fc4 --- /dev/null +++ b/app/Api/V2/Controllers/System/DebugController.php @@ -0,0 +1,29 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\System; + +use FireflyIII\Api\V2\Controllers\Controller; + +class DebugController extends Controller +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Controllers/System/PreferencesController.php b/app/Api/V2/Controllers/System/PreferencesController.php index acead47381..989550d3ba 100644 --- a/app/Api/V2/Controllers/System/PreferencesController.php +++ b/app/Api/V2/Controllers/System/PreferencesController.php @@ -23,7 +23,7 @@ namespace FireflyIII\Api\V2\Controllers\System; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Models\Preference; -use FireflyIII\Transformers\PreferenceTransformer; +use FireflyIII\Transformers\V2\PreferenceTransformer; use Illuminate\Http\JsonResponse; /** diff --git a/app/Api/V2/Controllers/Transaction/List/AccountController.php b/app/Api/V2/Controllers/Transaction/List/AccountController.php new file mode 100644 index 0000000000..9b0e10fe00 --- /dev/null +++ b/app/Api/V2/Controllers/Transaction/List/AccountController.php @@ -0,0 +1,81 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers\Transaction\List; + +use FireflyIII\Api\V2\Controllers\Controller; +use FireflyIII\Api\V2\Request\Transaction\ListRequest; +use FireflyIII\Helpers\Collector\GroupCollectorInterface; +use FireflyIII\Models\Account; +use FireflyIII\Support\Http\Api\TransactionFilter; +use FireflyIII\Transformers\V2\PreferenceTransformer; +use FireflyIII\Transformers\V2\TransactionGroupTransformer; +use Illuminate\Http\JsonResponse; +use Illuminate\Support\Collection; + +/** + * Class AccountController + */ +class AccountController extends Controller +{ + use TransactionFilter; + + /** + * @param ListRequest $request + * @param Account $account + * @return JsonResponse + */ + public function listTransactions(ListRequest $request, Account $account): JsonResponse + { + // collect transactions: + $type = $request->get('type') ?? 'default'; + $limit = (int) $request->get('limit'); + $page = (int) $request->get('page'); + $page = max($page, 1); + + if ($limit > 0 && $limit <= $this->pageSize) { + $this->pageSize = $limit; + } + + $types = $this->mapTransactionTypes($type); + + /** @var GroupCollectorInterface $collector */ + $collector = app(GroupCollectorInterface::class); + $collector->setAccounts(new Collection([$account])) + ->withAPIInformation() + ->setLimit($this->pageSize) + ->setPage($page) + ->setTypes($types); + + // TODO date filter + //if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { + // $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + //} + + $paginator = $collector->getPaginatedGroups(); + $paginator->setPath(route('api.v2.accounts.transactions', [$account->id])); // TODO . $this->buildParams() + + return response() + ->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer)) + ->header('Content-Type', self::CONTENT_TYPE); + } + +} diff --git a/app/Api/V2/Controllers/VersionUpdateController.php b/app/Api/V2/Controllers/VersionUpdateController.php new file mode 100644 index 0000000000..8951e0658e --- /dev/null +++ b/app/Api/V2/Controllers/VersionUpdateController.php @@ -0,0 +1,30 @@ +. + */ + +namespace FireflyIII\Api\V2\Controllers; + +/** + * Class VersionUpdateController + */ +class VersionUpdateController extends Controller +{ + +} \ No newline at end of file diff --git a/app/Api/V2/Request/Transaction/ListRequest.php b/app/Api/V2/Request/Transaction/ListRequest.php new file mode 100644 index 0000000000..30075489e8 --- /dev/null +++ b/app/Api/V2/Request/Transaction/ListRequest.php @@ -0,0 +1,44 @@ +. + */ + +namespace FireflyIII\Api\V2\Request\Transaction; + +use FireflyIII\Support\Request\ChecksLogin; +use Illuminate\Foundation\Http\FormRequest; + +/** + * Class ListRequest + */ +class ListRequest extends FormRequest +{ + use ChecksLogin; + + /** + * @return array + */ + public function rules(): array + { + return [ + 'start' => 'date', + 'end' => 'date|after:start', + ]; + } +} diff --git a/app/Api/V2/Response/Sum/AutoSum.php b/app/Api/V2/Response/Sum/AutoSum.php new file mode 100644 index 0000000000..d0e7e520a6 --- /dev/null +++ b/app/Api/V2/Response/Sum/AutoSum.php @@ -0,0 +1,68 @@ +. + */ + +namespace FireflyIII\Api\V2\Response\Sum; + +use Closure; +use FireflyIII\Models\TransactionCurrency; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; + +/** + * Class AutoSum + * @deprecated + */ +class AutoSum +{ + /** + * @param Collection $objects + * @param Closure $getCurrency + * @param Closure $getSum + * @return array + */ + public function autoSum(Collection $objects, Closure $getCurrency, Closure $getSum): array + { + $return = []; + /** @var Model $object */ + foreach ($objects as $object) { + /** @var TransactionCurrency $currency */ + $currency = $getCurrency($object); + /** @var string $amount */ + $amount = $getSum($object); + + $return[$currency->id] = $return[$currency->id] ?? [ + 'id' => (string) $currency->id, + 'name' => $currency->name, + 'symbol' => $currency->symbol, + 'code' => $currency->code, + 'decimal_places' => $currency->decimal_places, + 'sum' => '0', + ]; + + $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount); + } + + var_dump(array_values($return)); + exit; + + } + +} diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.php index df695cda2a..ec2a434f13 100644 --- a/app/Helpers/Report/NetWorth.php +++ b/app/Helpers/Report/NetWorth.php @@ -42,10 +42,8 @@ class NetWorth implements NetWorthInterface { private AccountRepositoryInterface $accountRepository; - /** @var CurrencyRepositoryInterface */ - private $currencyRepos; - /** @var User */ - private $user; + private CurrencyRepositoryInterface $currencyRepos; + private User $user; /** * Returns the user's net worth in an array with the following layout: diff --git a/app/Models/Account.php b/app/Models/Account.php index 652ef27de7..e695be2575 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -123,9 +123,8 @@ class Account extends Model /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban']; /** @var array Hidden from view */ - protected $hidden = ['encrypted']; - /** @var bool */ - private $joinedAccountTypes; + protected $hidden = ['encrypted']; + private bool $joinedAccountTypes = false; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). @@ -142,7 +141,7 @@ class Account extends Model /** @var User $user */ $user = auth()->user(); /** @var Account $account */ - $account = $user->accounts()->find($accountId); + $account = $user->accounts()->with(['accountType'])->find($accountId); if (null !== $account) { return $account; } @@ -250,7 +249,7 @@ class Account extends Model */ public function scopeAccountTypeIn(EloquentBuilder $query, array $types): void { - if (null === $this->joinedAccountTypes) { + if (false === $this->joinedAccountTypes) { $query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id'); $this->joinedAccountTypes = true; } diff --git a/app/Transformers/TransactionGroupTransformer.php b/app/Transformers/TransactionGroupTransformer.php index 895e348dda..7d7dbe3637 100644 --- a/app/Transformers/TransactionGroupTransformer.php +++ b/app/Transformers/TransactionGroupTransformer.php @@ -116,7 +116,6 @@ class TransactionGroupTransformer extends AbstractTransformer $row = new NullArrayObject($transaction); // amount: - $type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL); $amount = app('steam')->positive((string)($row['amount'] ?? '0')); $foreignAmount = null; if (null !== $row['foreign_amount']) { diff --git a/app/Transformers/V2/AbstractTransformer.php b/app/Transformers/V2/AbstractTransformer.php new file mode 100644 index 0000000000..1e3ba0b920 --- /dev/null +++ b/app/Transformers/V2/AbstractTransformer.php @@ -0,0 +1,32 @@ +. + */ + +namespace FireflyIII\Transformers\V2; + +use League\Fractal\TransformerAbstract; + +/** + * Class AbstractTransformer + */ +abstract class AbstractTransformer extends TransformerAbstract +{ + +} diff --git a/app/Transformers/V2/AccountTransformer.php b/app/Transformers/V2/AccountTransformer.php new file mode 100644 index 0000000000..fa350871de --- /dev/null +++ b/app/Transformers/V2/AccountTransformer.php @@ -0,0 +1,85 @@ +. + */ + +namespace FireflyIII\Transformers\V2; + +use FireflyIII\Models\Account; + +/** + * Class AccountTransformer + */ +class AccountTransformer extends AbstractTransformer +{ + /** + * Transform the account. + * + * @param Account $account + * + * @return array + */ + public function transform(Account $account): array + { + $fullType = $account->accountType->type; + $accountType = (string) config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); + + return [ + 'id' => (string) $account->id, + 'created_at' => $account->created_at->toAtomString(), + 'updated_at' => $account->updated_at->toAtomString(), + 'active' => $account->active, + //'order' => $order, + 'name' => $account->name, + 'type' => strtolower($accountType), +// 'account_role' => $accountRole, +// 'currency_id' => $currencyId, +// 'currency_code' => $currencyCode, +// 'currency_symbol' => $currencySymbol, +// 'currency_decimal_places' => $decimalPlaces, +// 'current_balance' => number_format((float) app('steam')->balance($account, $date), $decimalPlaces, '.', ''), +// 'current_balance_date' => $date->toAtomString(), +// 'notes' => $this->repository->getNoteText($account), +// 'monthly_payment_date' => $monthlyPaymentDate, +// 'credit_card_type' => $creditCardType, +// 'account_number' => $this->repository->getMetaValue($account, 'account_number'), + 'iban' => '' === $account->iban ? null : $account->iban, +// 'bic' => $this->repository->getMetaValue($account, 'BIC'), +// 'virtual_balance' => number_format((float) $account->virtual_balance, $decimalPlaces, '.', ''), +// 'opening_balance' => $openingBalance, +// 'opening_balance_date' => $openingBalanceDate, +// 'liability_type' => $liabilityType, +// 'liability_direction' => $liabilityDirection, +// 'interest' => $interest, +// 'interest_period' => $interestPeriod, +// 'current_debt' => $this->repository->getMetaValue($account, 'current_debt'), +// 'include_net_worth' => $includeNetWorth, +// 'longitude' => $longitude, +// 'latitude' => $latitude, +// 'zoom_level' => $zoomLevel, + 'links' => [ + [ + 'rel' => 'self', + 'uri' => '/accounts/' . $account->id, + ], + ], + ]; + } + +} diff --git a/app/Transformers/V2/PreferenceTransformer.php b/app/Transformers/V2/PreferenceTransformer.php new file mode 100644 index 0000000000..4a2fae8dfa --- /dev/null +++ b/app/Transformers/V2/PreferenceTransformer.php @@ -0,0 +1,52 @@ +. + */ + +declare(strict_types=1); + +namespace FireflyIII\Transformers\V2; + +use FireflyIII\Models\Preference; + +/** + * Class PreferenceTransformer + */ +class PreferenceTransformer extends AbstractTransformer +{ + /** + * Transform the preference + * + * @param Preference $preference + * + * @return array + */ + public function transform(Preference $preference): array + { + return [ + 'id' => (int) $preference->id, + 'created_at' => $preference->created_at->toAtomString(), + 'updated_at' => $preference->updated_at->toAtomString(), + 'name' => $preference->name, + 'data' => $preference->data, + ]; + + } + +} diff --git a/app/Transformers/V2/TransactionGroupTransformer.php b/app/Transformers/V2/TransactionGroupTransformer.php new file mode 100644 index 0000000000..abe2b4b8e0 --- /dev/null +++ b/app/Transformers/V2/TransactionGroupTransformer.php @@ -0,0 +1,179 @@ +. + */ + +namespace FireflyIII\Transformers\V2; + +use FireflyIII\Models\TransactionType; + +/** + * Class TransactionGroupTransformer + */ +class TransactionGroupTransformer extends AbstractTransformer +{ + /** + * @param array $group + * + * @return array + */ + public function transform(array $group): array + { + //$data = new NullArrayObject($group); + $first = reset($group['transactions']); + + return [ + 'id' => (string) $group['id'], + 'created_at' => $first['created_at']->toAtomString(), + 'updated_at' => $first['updated_at']->toAtomString(), + 'user' => (string) $first['user_id'], + 'group_title' => $group['group_title'] ?? null, + 'transactions' => $this->transformTransactions($group['transactions'] ?? []), + 'links' => [ + [ + 'rel' => 'self', + 'uri' => '/transactions/' . 1, + ], + ], + ]; + } + + /** + * @param array $transactions + * @return array + */ + private function transformTransactions(array $transactions): array + { + $return = []; + /** @var array $transaction */ + foreach ($transactions as $transaction) { + $return[] = $this->transformTransaction($transaction); + } + return $return; + } + + private function transformTransaction(array $transaction): array + { + $type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL); + + // amount: + $amount = app('steam')->positive((string) ($row['amount'] ?? '0')); + $foreignAmount = null; + if (null !== $row['foreign_amount']) { + $foreignAmount = app('steam')->positive($row['foreign_amount']); + } + + return [ + 'user' => (string) $transaction['user_id'], + 'transaction_journal_id' => (string) $transaction['transaction_journal_id'], + 'type' => strtolower($type), + 'date' => $transaction['date']->toAtomString(), + 'order' => $transaction['order'], + 'currency_id' => (string) $transaction['currency_id'], + 'currency_code' => $transaction['currency_code'], + 'currency_name' => $transaction['currency_name'], + 'currency_symbol' => $transaction['currency_symbol'], + 'currency_decimal_places' => (int) $transaction['currency_decimal_places'], + 'foreign_currency_id' => $this->stringFromArray($transaction, 'foreign_currency_id', null), + 'foreign_currency_code' => $transaction['foreign_currency_code'], + 'foreign_currency_symbol' => $transaction['foreign_currency_symbol'], + 'foreign_currency_decimal_places' => $transaction['foreign_currency_decimal_places'], + 'amount' => $amount, + 'foreign_amount' => $foreignAmount, + 'description' => $transaction['description'], + 'source_id' => (string) $transaction['source_account_id'], + 'source_name' => $transaction['source_account_name'], + 'source_iban' => $transaction['source_account_iban'], + 'source_type' => $transaction['source_account_type'], + 'destination_id' => (string) $transaction['destination_account_id'], + 'destination_name' => $transaction['destination_account_name'], + 'destination_iban' => $transaction['destination_account_iban'], + 'destination_type' => $transaction['destination_account_type'], + 'budget_id' => $this->stringFromArray($transaction, 'budget_id', null), + 'budget_name' => $transaction['budget_name'], + 'category_id' => $this->stringFromArray($transaction, 'category_id', null), + 'category_name' => $transaction['category_name'], + 'bill_id' => $this->stringFromArray($transaction, 'bill_id', null), + 'bill_name' => $transaction['bill_name'], + 'reconciled' => $transaction['reconciled'], + + //'notes' => $this->groupRepos->getNoteText((int) $row['transaction_journal_id']), + //'tags' => $this->groupRepos->getTags((int) $row['transaction_journal_id']), + + // 'internal_reference' => $metaFieldData['internal_reference'], + // 'external_id' => $metaFieldData['external_id'], + // 'original_source' => $metaFieldData['original_source'], + // 'recurrence_id' => $this->stringFromArray($metaFieldData->getArrayCopy(), 'recurrence_id', null), + // 'recurrence_total' => $this->integerFromArray($metaFieldData->getArrayCopy(), 'recurrence_total'), + // 'recurrence_count' => $this->integerFromArray($metaFieldData->getArrayCopy(), 'recurrence_count'), + // 'bunq_payment_id' => $metaFieldData['bunq_payment_id'], + // 'external_url' => $metaFieldData['external_url'], + // 'import_hash_v2' => $metaFieldData['import_hash_v2'], + + // 'sepa_cc' => $metaFieldData['sepa_cc'], + // 'sepa_ct_op' => $metaFieldData['sepa_ct_op'], + // 'sepa_ct_id' => $metaFieldData['sepa_ct_id'], + // 'sepa_db' => $metaFieldData['sepa_db'], + // 'sepa_country' => $metaFieldData['sepa_country'], + // 'sepa_ep' => $metaFieldData['sepa_ep'], + // 'sepa_ci' => $metaFieldData['sepa_ci'], + // 'sepa_batch_id' => $metaFieldData['sepa_batch_id'], + + // 'interest_date' => $this->dateFromArray($metaDateData, 'interest_date'), + // 'book_date' => $this->dateFromArray($metaDateData, 'book_date'), + // 'process_date' => $this->dateFromArray($metaDateData, 'process_date'), + // 'due_date' => $this->dateFromArray($metaDateData, 'due_date'), + // 'payment_date' => $this->dateFromArray($metaDateData, 'payment_date'), + // 'invoice_date' => $this->dateFromArray($metaDateData, 'invoice_date'), + + // location data + // 'longitude' => $longitude, + // 'latitude' => $latitude, + // 'zoom_level' => $zoomLevel, + // + // 'has_attachments' => $this->hasAttachments((int) $row['transaction_journal_id']), + ]; + } + + /** + * TODO also in the old transformer. + * + * @param array $array + * @param string $key + * @param string|null $default + * + * @return string|null + */ + private function stringFromArray(array $array, string $key, ?string $default): ?string + { + if (array_key_exists($key, $array) && null === $array[$key]) { + return null; + } + if (array_key_exists($key, $array) && null !== $array[$key]) { + return (string) $array[$key]; + } + + if (null !== $default) { + return (string) $default; + } + + return null; + } + +} diff --git a/frontend/src/api/v2/accounts/get.js b/frontend/src/api/v2/accounts/get.js new file mode 100644 index 0000000000..fe0600d9c6 --- /dev/null +++ b/frontend/src/api/v2/accounts/get.js @@ -0,0 +1,47 @@ +/* + * get.js + * Copyright (c) 2022 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 . + */ + +import Api from "src/api/v2/root/api"; + +export default class Get extends Api { + constructor() { + super('accounts'); // call the super class constructor and pass in the name parameter + } + + /** + * + * @param identifier + * @param date + * @returns {Promise>} + */ + get(identifier, date) { + let params = {date: date}; + if(!date) { + return this.apiGet(identifier); + } + return this.apiGet(identifier, params); + } + transactions(identifier, params) { + if(!params) { + return this.apiGetTransactions(identifier); + } + return this.apiGetTransactions(identifier, params); + } +} diff --git a/frontend/src/api/v2/root/api.js b/frontend/src/api/v2/root/api.js new file mode 100644 index 0000000000..19587122d0 --- /dev/null +++ b/frontend/src/api/v2/root/api.js @@ -0,0 +1,68 @@ +/* + * api.js + * Copyright (c) 2022 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 . + */ + +import {api} from "boot/axios"; + +/** + * + */ +export default class Api { + root = '/api/v2/'; + path = ''; + + constructor(path) { + this.path = path; + } + + apiPath() { + return this.root + this.path; + } + + apiPathWithObject(object) { + return this.root + this.path + '/' + object; + } + + /** + * + * @param object + * @param params + * @returns {Promise>} + */ + apiGet(object, params) { + let url = this.apiPathWithObject(object); + if (params) { + return api.get(url, {params: params}); + } + return api.get(url); + } + /** + * + * @param object + * @param params + * @returns {Promise>} + */ + apiGetTransactions(object, params) { + let url = this.apiPathWithObject(object) + '/transactions'; + if (params) { + return api.get(url, {params: params}); + } + return api.get(url); + } +} diff --git a/frontend/src/components/dashboard/TransactionList.vue b/frontend/src/components/dashboard/TransactionList.vue new file mode 100644 index 0000000000..7fbad01b35 --- /dev/null +++ b/frontend/src/components/dashboard/TransactionList.vue @@ -0,0 +1,105 @@ + + + + + + + diff --git a/frontend/src/components/dashboard/TransactionLists.vue b/frontend/src/components/dashboard/TransactionLists.vue index 575d9c4276..ab7cb8e700 100644 --- a/frontend/src/components/dashboard/TransactionLists.vue +++ b/frontend/src/components/dashboard/TransactionLists.vue @@ -19,15 +19,42 @@ --> - - diff --git a/frontend/src/pages/dashboard/Dashboard.vue b/frontend/src/pages/dashboard/Dashboard.vue index cddce57e14..943d4db1b4 100644 --- a/frontend/src/pages/dashboard/Dashboard.vue +++ b/frontend/src/pages/dashboard/Dashboard.vue @@ -89,12 +89,11 @@