Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Add events for #11982
James Colea27642024d0e
diff --git a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.php b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.phpindex 4d9623627d..631657a9ed 100644--- a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.php+++ b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.php@@ -28,6 +28,7 @@ use Carbon\Carbon;use FireflyIII\Api\V1\Controllers\Controller;use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\DestroyRequest;use FireflyIII\Enums\UserRoleEnum;+use FireflyIII\Events\Model\CurrencyExchangeRate\DestroyedCurrencyExchangeRate;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\CurrencyExchangeRate;use FireflyIII\Models\TransactionCurrency;@@ -42,7 +43,7 @@ final class DestroyController extends Controllerpublic const string RESOURCE_KEY = 'exchange-rates';- protected array $acceptedRoles = [UserRoleEnum::OWNER];+ protected array $acceptedRoles = [UserRoleEnum::OWNER];private ExchangeRateRepositoryInterface $repository;public function __construct()@@ -59,11 +60,12 @@ final class DestroyController extends Controllerpublic function destroy(DestroyRequest $request, TransactionCurrency $from, TransactionCurrency $to): JsonResponse{$this->repository->deleteRates($from, $to);+ event(new DestroyedCurrencyExchangeRate($from, $to, $this->validateUserGroup($request)));return response()->json([], 204);}- public function destroySingleByDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): JsonResponse+ public function destroySingleByDate(Request $request, TransactionCurrency $from, TransactionCurrency $to, Carbon $date): JsonResponse{$exchangeRate = $this->repository->getSpecificRateOnDate($from, $to, $date);if ($exchangeRate instanceof CurrencyExchangeRate) {@@ -72,14 +74,19 @@ final class DestroyController extends Controllerif (!$exchangeRate instanceof CurrencyExchangeRate) {throw new FireflyException('Bla');}+ event(new DestroyedCurrencyExchangeRate($from, $to, $this->validateUserGroup($request)));return response()->json([], 204);}- public function destroySingleById(CurrencyExchangeRate $exchangeRate): JsonResponse+ public function destroySingleById(Request $request, CurrencyExchangeRate $exchangeRate): JsonResponse{+ $from = $exchangeRate->fromCurrency;+ $to = $exchangeRate->toCurrency;$this->repository->deleteRate($exchangeRate);+ event(new DestroyedCurrencyExchangeRate($from, $to, $this->validateUserGroup($request)));+return response()->json([], 204);}}diff --git a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.php b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.phpindex 9d8308def6..eea84c3760 100644--- a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.php+++ b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.php@@ -30,6 +30,8 @@ use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreByCurrenciesRequuse FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreByDateRequest;use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreRequest;use FireflyIII\Enums\UserRoleEnum;+use FireflyIII\Events\Model\CurrencyExchangeRate\CreatedCurrencyExchangeRate;+use FireflyIII\Events\Model\CurrencyExchangeRate\UpdatedCurrencyExchangeRate;use FireflyIII\Models\CurrencyExchangeRate;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface;@@ -73,10 +75,12 @@ final class StoreController extends Controllerif ($object instanceof CurrencyExchangeRate) {// just update it, no matter.$rate = $this->repository->updateExchangeRate($object, $rate, $date);+ event(new UpdatedCurrencyExchangeRate($rate));}if (!$object instanceof CurrencyExchangeRate) {// store new$rate = $this->repository->storeExchangeRate($from, $to, $rate, $date);+ event(new CreatedCurrencyExchangeRate($rate));}$transformer = new ExchangeRateTransformer();@@ -97,10 +101,11 @@ final class StoreController extends Controller// update existing rate.$existing = $this->repository->updateExchangeRate($existing, $rate);$collection->push($existing);-+ event(new UpdatedCurrencyExchangeRate($existing));continue;}$new = $this->repository->storeExchangeRate($from, $to, $rate, $date);+ event(new CreatedCurrencyExchangeRate($new));$collection->push($new);}@@ -124,11 +129,13 @@ final class StoreController extends Controller// update existing rate.$existing = $this->repository->updateExchangeRate($existing, $rate);$collection->push($existing);+ event(new UpdatedCurrencyExchangeRate($existing));continue;}$new = $this->repository->storeExchangeRate($from, $to, $rate, $date);$collection->push($new);+ event(new CreatedCurrencyExchangeRate($new));}$count = $collection->count();diff --git a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/UpdateController.php b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/UpdateController.phpindex 939160ebc0..f85876095e 100644--- a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/UpdateController.php+++ b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/UpdateController.php@@ -28,6 +28,7 @@ use Carbon\Carbon;use FireflyIII\Api\V1\Controllers\Controller;use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\UpdateRequest;use FireflyIII\Enums\UserRoleEnum;+use FireflyIII\Events\Model\CurrencyExchangeRate\UpdatedCurrencyExchangeRate;use FireflyIII\Models\CurrencyExchangeRate;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface;@@ -43,7 +44,7 @@ final class UpdateController extends Controllerpublic const string RESOURCE_KEY = 'exchange-rates';- protected array $acceptedRoles = [UserRoleEnum::OWNER];+ protected array $acceptedRoles = [UserRoleEnum::OWNER];private ExchangeRateRepositoryInterface $repository;public function __construct()@@ -66,8 +67,8 @@ final class UpdateController extends Controller$date = $request->getDate();$rate = $request->getRate();$exchangeRate = $this->repository->updateExchangeRate($exchangeRate, $rate, $date);-- $transformer = new ExchangeRateTransformer();+ event(new UpdatedCurrencyExchangeRate($exchangeRate));+ $transformer = new ExchangeRateTransformer();return response()->api($this->jsonApiObject(self::RESOURCE_KEY, $exchangeRate, $transformer))->header('Content-Type', self::CONTENT_TYPE);}@@ -77,6 +78,7 @@ final class UpdateController extends Controller$date = $request->getDate();$rate = $request->getRate();$exchangeRate = $this->repository->updateExchangeRate($exchangeRate, $rate, $date);+ event(new UpdatedCurrencyExchangeRate($exchangeRate));$transformer = new ExchangeRateTransformer();$transformer->setParameters($this->parameters);diff --git a/app/Events/Model/CurrencyExchangeRate/UpdatedCurrencyExchangeRate.php b/app/Events/Model/CurrencyExchangeRate/UpdatedCurrencyExchangeRate.phpindex 11ebe07ae0..a0abd436bb 100644--- a/app/Events/Model/CurrencyExchangeRate/UpdatedCurrencyExchangeRate.php+++ b/app/Events/Model/CurrencyExchangeRate/UpdatedCurrencyExchangeRate.php@@ -30,7 +30,7 @@ class UpdatedCurrencyExchangeRate extends Event{use SerializesModels;- public function __construct(public CurrencyExchangeRate $rate,) {+ public function __construct(public CurrencyExchangeRate $rate) {Log::debug(sprintf('UpdatedCurrencyExchangeRate(#%d) Event', $rate->id));}}