From 271b61808b1eed2139d9e3420053098c30dc4a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:51:34 +0300 Subject: [PATCH] added account events --- app/Events/Banking/AccountCreated.php | 21 +++++++++++++++++++++ app/Events/Banking/AccountCreating.php | 20 ++++++++++++++++++++ app/Events/Banking/AccountDeleted.php | 20 ++++++++++++++++++++ app/Events/Banking/AccountDeleting.php | 20 ++++++++++++++++++++ app/Events/Banking/AccountUpdated.php | 25 +++++++++++++++++++++++++ app/Events/Banking/AccountUpdating.php | 25 +++++++++++++++++++++++++ app/Jobs/Banking/CreateAccount.php | 6 ++++++ app/Jobs/Banking/DeleteAccount.php | 6 ++++++ app/Jobs/Banking/UpdateAccount.php | 6 ++++++ 9 files changed, 149 insertions(+) create mode 100644 app/Events/Banking/AccountCreated.php create mode 100644 app/Events/Banking/AccountCreating.php create mode 100644 app/Events/Banking/AccountDeleted.php create mode 100644 app/Events/Banking/AccountDeleting.php create mode 100644 app/Events/Banking/AccountUpdated.php create mode 100644 app/Events/Banking/AccountUpdating.php diff --git a/app/Events/Banking/AccountCreated.php b/app/Events/Banking/AccountCreated.php new file mode 100644 index 000000000..78570ca85 --- /dev/null +++ b/app/Events/Banking/AccountCreated.php @@ -0,0 +1,21 @@ +account = $account; + } +} \ No newline at end of file diff --git a/app/Events/Banking/AccountCreating.php b/app/Events/Banking/AccountCreating.php new file mode 100644 index 000000000..e6c500b05 --- /dev/null +++ b/app/Events/Banking/AccountCreating.php @@ -0,0 +1,20 @@ +request = $request; + } +} \ No newline at end of file diff --git a/app/Events/Banking/AccountDeleted.php b/app/Events/Banking/AccountDeleted.php new file mode 100644 index 000000000..22bf63d4a --- /dev/null +++ b/app/Events/Banking/AccountDeleted.php @@ -0,0 +1,20 @@ +account = $account; + } +} \ No newline at end of file diff --git a/app/Events/Banking/AccountDeleting.php b/app/Events/Banking/AccountDeleting.php new file mode 100644 index 000000000..016e6a618 --- /dev/null +++ b/app/Events/Banking/AccountDeleting.php @@ -0,0 +1,20 @@ +account = $account; + } +} \ No newline at end of file diff --git a/app/Events/Banking/AccountUpdated.php b/app/Events/Banking/AccountUpdated.php new file mode 100644 index 000000000..80746fa08 --- /dev/null +++ b/app/Events/Banking/AccountUpdated.php @@ -0,0 +1,25 @@ +account = $account; + $this->request = $request; + } +} \ No newline at end of file diff --git a/app/Events/Banking/AccountUpdating.php b/app/Events/Banking/AccountUpdating.php new file mode 100644 index 000000000..9949dd5b8 --- /dev/null +++ b/app/Events/Banking/AccountUpdating.php @@ -0,0 +1,25 @@ +account = $account; + $this->request = $request; + } +} \ No newline at end of file diff --git a/app/Jobs/Banking/CreateAccount.php b/app/Jobs/Banking/CreateAccount.php index 57f24383d..cca2e136c 100644 --- a/app/Jobs/Banking/CreateAccount.php +++ b/app/Jobs/Banking/CreateAccount.php @@ -3,6 +3,8 @@ namespace App\Jobs\Banking; use App\Abstracts\Job; +use App\Events\Banking\AccountCreating; +use App\Events\Banking\AccountCreated; use App\Interfaces\Job\HasOwner; use App\Interfaces\Job\HasSource; use App\Interfaces\Job\ShouldCreate; @@ -12,6 +14,8 @@ class CreateAccount extends Job implements HasOwner, HasSource, ShouldCreate { public function handle(): Account { + event(new AccountCreating($this->request)); + \DB::transaction(function () { $this->model = Account::create($this->request->all()); @@ -22,6 +26,8 @@ class CreateAccount extends Job implements HasOwner, HasSource, ShouldCreate } }); + event(new AccountCreated($this->model, $this->request)); + return $this->model; } } diff --git a/app/Jobs/Banking/DeleteAccount.php b/app/Jobs/Banking/DeleteAccount.php index 5a86a9692..c24d88e86 100644 --- a/app/Jobs/Banking/DeleteAccount.php +++ b/app/Jobs/Banking/DeleteAccount.php @@ -3,6 +3,8 @@ namespace App\Jobs\Banking; use App\Abstracts\Job; +use App\Events\Banking\AccountDeleting; +use App\Events\Banking\AccountDeleted; use App\Interfaces\Job\ShouldDelete; class DeleteAccount extends Job implements ShouldDelete @@ -11,10 +13,14 @@ class DeleteAccount extends Job implements ShouldDelete { $this->authorize(); + event(new AccountDeleting($this->model)); + \DB::transaction(function () { $this->model->delete(); }); + event(new AccountDeleted($this->model)); + return true; } diff --git a/app/Jobs/Banking/UpdateAccount.php b/app/Jobs/Banking/UpdateAccount.php index b37a7b512..de661fccb 100644 --- a/app/Jobs/Banking/UpdateAccount.php +++ b/app/Jobs/Banking/UpdateAccount.php @@ -3,6 +3,8 @@ namespace App\Jobs\Banking; use App\Abstracts\Job; +use App\Events\Banking\AccountUpdating; +use App\Events\Banking\AccountUpdated; use App\Interfaces\Job\ShouldUpdate; use App\Models\Banking\Account; @@ -12,6 +14,8 @@ class UpdateAccount extends Job implements ShouldUpdate { $this->authorize(); + event(new AccountUpdating($this->model, $this->request)); + \DB::transaction(function () { $this->model->update($this->request->all()); @@ -22,6 +26,8 @@ class UpdateAccount extends Job implements ShouldUpdate } }); + event(new AccountUpdated($this->model, $this->request)); + return $this->model; }