Skip to content

Firefly III: a personal finances manager

Add enrichment to recurring

James Cole292908048c17
diff --git a/app/Api/V1/Controllers/Models/Recurrence/StoreController.php b/app/Api/V1/Controllers/Models/Recurrence/StoreController.php
index 11fe66da15..25ed24b44c 100644
--- a/app/Api/V1/Controllers/Models/Recurrence/StoreController.php
+++ b/app/Api/V1/Controllers/Models/Recurrence/StoreController.php
@@ -28,7 +28,9 @@ use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Recurrence\StoreRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
+use FireflyIII\Support\JsonApi\Enrichments\RecurringEnrichment;
use FireflyIII\Transformers\RecurrenceTransformer;
+use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
@@ -69,6 +71,13 @@ class StoreController extends Controller
$recurrence = $this->repository->store($data);
$manager = $this->getManager();
+ // enrich
+ /** @var User $admin */
+ $admin = auth()->user();
+ $enrichment = new RecurringEnrichment();
+ $enrichment->setUser($admin);
+ $recurrence = $enrichment->enrichSingle($recurrence);
+
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters($this->parameters);
diff --git a/app/Api/V1/Controllers/Models/Recurrence/UpdateController.php b/app/Api/V1/Controllers/Models/Recurrence/UpdateController.php
index 5a977c1930..903d0dddd7 100644
--- a/app/Api/V1/Controllers/Models/Recurrence/UpdateController.php
+++ b/app/Api/V1/Controllers/Models/Recurrence/UpdateController.php
@@ -28,7 +28,9 @@ use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\Recurrence\UpdateRequest;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
+use FireflyIII\Support\JsonApi\Enrichments\RecurringEnrichment;
use FireflyIII\Transformers\RecurrenceTransformer;
+use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
@@ -67,6 +69,13 @@ class UpdateController extends Controller
$recurrence = $this->repository->update($recurrence, $data);
$manager = $this->getManager();
+ // enrich
+ /** @var User $admin */
+ $admin = auth()->user();
+ $enrichment = new RecurringEnrichment();
+ $enrichment->setUser($admin);
+ $recurrence = $enrichment->enrichSingle($recurrence);
+
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters($this->parameters);
diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php
index fe2c34ba8e..e206a1f39e 100644
--- a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php
+++ b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php
@@ -44,6 +44,7 @@ use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Support\JsonApi\Enrichments\AccountEnrichment;
use FireflyIII\Support\JsonApi\Enrichments\BudgetLimitEnrichment;
+use FireflyIII\Support\JsonApi\Enrichments\RecurringEnrichment;
use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;
use FireflyIII\Support\JsonApi\Enrichments\TransactionGroupEnrichment;
use FireflyIII\Transformers\AccountTransformer;
@@ -276,17 +277,24 @@ class ListController extends Controller
}
);
$count = $collection->count();
- $piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
+ $recurrences = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
+
+ // enrich
+ /** @var User $admin */
+ $admin = auth()->user();
+ $enrichment = new RecurringEnrichment();
+ $enrichment->setUser($admin);
+ $recurrences = $enrichment->enrich($recurrences);
// make paginator:
- $paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
+ $paginator = new LengthAwarePaginator($recurrences, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.currencies.recurrences', [$currency->code]).$this->buildParams());
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters($this->parameters);
- $resource = new FractalCollection($piggyBanks, $transformer, 'recurrences');
+ $resource = new FractalCollection($recurrences, $transformer, 'recurrences');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php
index f6d203b0e8..3de9eb7781 100644
--- a/app/Http/Controllers/Recurring/EditController.php
+++ b/app/Http/Controllers/Recurring/EditController.php
@@ -34,7 +34,9 @@ use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
+use FireflyIII\Support\JsonApi\Enrichments\RecurringEnrichment;
use FireflyIII\Transformers\RecurrenceTransformer;
+use FireflyIII\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@@ -92,6 +94,13 @@ class EditController extends Controller
throw new FireflyException('This recurring transaction has no meta-data. You will have to delete it and recreate it. Sorry!');
}
+ // enrich
+ /** @var User $admin */
+ $admin = auth()->user();
+ $enrichment = new RecurringEnrichment();
+ $enrichment->setUser($admin);
+ $recurrence = $enrichment->enrichSingle($recurrence);
+
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag());
diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php
index 982e35e878..773c36f916 100644
--- a/app/Http/Controllers/Recurring/IndexController.php
+++ b/app/Http/Controllers/Recurring/IndexController.php
@@ -29,7 +29,9 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
+use FireflyIII\Support\JsonApi\Enrichments\RecurringEnrichment;
use FireflyIII\Transformers\RecurrenceTransformer;
+use FireflyIII\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -85,6 +87,13 @@ class IndexController extends Controller
$total = $collection->count();
$recurrences = $collection->slice(($page - 1) * $pageSize, $pageSize);
+ // enrich
+ /** @var User $admin */
+ $admin = auth()->user();
+ $enrichment = new RecurringEnrichment();
+ $enrichment->setUser($admin);
+ $recurrences = $enrichment->enrich($recurrences);
+
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag());
diff --git a/app/Http/Controllers/Recurring/ShowController.php b/app/Http/Controllers/Recurring/ShowController.php
index 6e6da1518d..15c339f6a3 100644
--- a/app/Http/Controllers/Recurring/ShowController.php
+++ b/app/Http/Controllers/Recurring/ShowController.php
@@ -32,8 +32,10 @@ use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
+use FireflyIII\Support\JsonApi\Enrichments\RecurringEnrichment;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\RecurrenceTransformer;
+use FireflyIII\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\ParameterBag;
@@ -80,6 +82,13 @@ class ShowController extends Controller
{
$repos = app(AttachmentRepositoryInterface::class);
+ // enrich
+ /** @var User $admin */
+ $admin = auth()->user();
+ $enrichment = new RecurringEnrichment();
+ $enrichment->setUser($admin);
+ $recurrence = $enrichment->enrichSingle($recurrence);
+
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag());