diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 85b16c7dc0..cc736a793e 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -217,26 +217,17 @@ class TagController extends Controller } /** - * @param Tag $tag + * @param Tag $tag + * @param TagRepositoryInterface $repository * * @return View */ - public function show(Tag $tag) + public function show(Tag $tag, TagRepositoryInterface $repository) { $subTitle = $tag->tag; $subTitleIcon = 'fa-tag'; - - - - /** @var Collection $journals */ - $journals = $tag - ->transactionJournals() - ->sortCorrectly() - ->expanded() - ->groupBy(['tag_transaction_journal.tag_id']) - ->get(TransactionJournal::queryFields()); - - $sum = $journals->sum( + $journals = $repository->getJournals($tag); + $sum = $journals->sum( function (TransactionJournal $journal) { return TransactionJournal::amount($journal); } diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 605f5b6924..3366b68cfc 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -131,6 +131,24 @@ class TagRepository implements TagRepositoryInterface return $tags; } + /** + * @param Tag $tag + * + * @return Collection + */ + public function getJournals(Tag $tag) : Collection + { + /** @var Collection $journals */ + $journals = $tag + ->transactionJournals() + ->sortCorrectly() + ->expanded() + ->groupBy(['tag_transaction_journal.tag_id']) + ->get(TransactionJournal::queryFields()); + + return $journals; + } + /** * @param array $data * diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php index ca6e33fa1e..e0613d7cd1 100644 --- a/app/Repositories/Tag/TagRepositoryInterface.php +++ b/app/Repositories/Tag/TagRepositoryInterface.php @@ -33,6 +33,13 @@ interface TagRepositoryInterface */ public function connect(TransactionJournal $journal, Tag $tag): bool; + /** + * @param Tag $tag + * + * @return Collection + */ + public function getJournals(Tag $tag) : Collection; + /** * This method destroys a tag. *