From 21f98be3e7420c83b0eb584cf08a7d34c67a1a8c Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 26 Sep 2019 20:57:24 +0200 Subject: [PATCH] Fix #2637 --- .../V1/Controllers/TransactionController.php | 19 +++++++++++++------ .../views/v1/list/piggy-bank-events.twig | 2 +- routes/api.php | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/Api/V1/Controllers/TransactionController.php b/app/Api/V1/Controllers/TransactionController.php index 28ae3369fe..956388c5d0 100644 --- a/app/Api/V1/Controllers/TransactionController.php +++ b/app/Api/V1/Controllers/TransactionController.php @@ -41,6 +41,7 @@ use FireflyIII\Transformers\TransactionGroupTransformer; use FireflyIII\User; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Collection; use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Resource\Collection as FractalCollection; use League\Fractal\Resource\Item; @@ -87,15 +88,18 @@ class TransactionController extends Controller } /** - * @param TransactionJournal $transactionJournal + * @param TransactionGroup $transactionGroup * * @return JsonResponse * @codeCoverageIgnore */ - public function attachments(TransactionJournal $transactionJournal): JsonResponse + public function attachments(TransactionGroup $transactionGroup): JsonResponse { $manager = $this->getManager(); - $attachments = $this->journalAPIRepository->getAttachments($transactionJournal); + $attachments = new Collection; + foreach ($transactionGroup->transactionJournals as $transactionJournal) { + $attachments = $this->journalAPIRepository->getAttachments($transactionJournal)->merge($attachments); + } /** @var AttachmentTransformer $transformer */ $transformer = app(AttachmentTransformer::class); @@ -189,15 +193,18 @@ class TransactionController extends Controller } /** - * @param TransactionJournal $transactionJournal + * @param TransactionGroup $transactionGroup * * @return JsonResponse * @codeCoverageIgnore */ - public function piggyBankEvents(TransactionJournal $transactionJournal): JsonResponse + public function piggyBankEvents(TransactionGroup $transactionGroup): JsonResponse { $manager = $this->getManager(); - $events = $this->journalAPIRepository->getPiggyBankEvents($transactionJournal); + $events = new Collection; + foreach ($transactionGroup->transactionJournals as $transactionJournal) { + $events = $this->journalAPIRepository->getPiggyBankEvents($transactionJournal)->merge($events); + } /** @var PiggyBankEventTransformer $transformer */ $transformer = app(PiggyBankEventTransformer::class); diff --git a/resources/views/v1/list/piggy-bank-events.twig b/resources/views/v1/list/piggy-bank-events.twig index d5f76e195b..8dbcc326ba 100644 --- a/resources/views/v1/list/piggy-bank-events.twig +++ b/resources/views/v1/list/piggy-bank-events.twig @@ -15,7 +15,7 @@ {% endif %} {% if event.transaction_journal_id %} - {{ event.date.formatLocalized(monthAndDayFormat) }} {% else %} {{ event.date.formatLocalized(monthAndDayFormat) }} diff --git a/routes/api.php b/routes/api.php index 802290a612..6d5baef63e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -423,8 +423,8 @@ Route::group( Route::get('', ['uses' => 'TransactionController@index', 'as' => 'index']); Route::post('', ['uses' => 'TransactionController@store', 'as' => 'store']); Route::get('{transactionGroup}', ['uses' => 'TransactionController@show', 'as' => 'show']); - Route::get('{transactionJournal}/attachments', ['uses' => 'TransactionController@attachments', 'as' => 'attachments']); - Route::get('{transactionJournal}/piggy_bank_events', ['uses' => 'TransactionController@piggyBankEvents', 'as' => 'piggy_bank_events']); + Route::get('{transactionGroup}/attachments', ['uses' => 'TransactionController@attachments', 'as' => 'attachments']); + Route::get('{transactionGroup}/piggy_bank_events', ['uses' => 'TransactionController@piggyBankEvents', 'as' => 'piggy_bank_events']); Route::put('{transactionGroup}', ['uses' => 'TransactionController@update', 'as' => 'update']); Route::delete('{transactionGroup}/{transactionJournal}', ['uses' => 'TransactionController@deleteJournal', 'as' => 'delete-journal']); Route::delete('{transactionGroup}', ['uses' => 'TransactionController@delete', 'as' => 'delete']);