Skip to content

Commit

Permalink
added currency events
Browse files Browse the repository at this point in the history
  • Loading branch information
CihanSenturk committed Oct 31, 2023
1 parent 6af4c75 commit 9edf50f
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/Events/Setting/CurrencyCreated.php
@@ -0,0 +1,24 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class CurrencyCreated extends Event
{
public $currency;

public $request;

/**
* Create a new event instance.
*
* @param $currency
* @param $request
*/
public function __construct($currency, $request)
{
$this->currency = $currency;
$this->request = $request;
}
}
20 changes: 20 additions & 0 deletions app/Events/Setting/CurrencyCreating.php
@@ -0,0 +1,20 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class CurrencyCreating extends Event
{
public $request;

/**
* Create a new event instance.
*
* @param $request
*/
public function __construct($request)
{
$this->request = $request;
}
}
20 changes: 20 additions & 0 deletions app/Events/Setting/CurrencyDeleted.php
@@ -0,0 +1,20 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class CurrencyDeleted extends Event
{
public $currency;

/**
* Create a new event instance.
*
* @param $currency
*/
public function __construct($currency)
{
$this->currency = $currency;
}
}
20 changes: 20 additions & 0 deletions app/Events/Setting/CurrencyDeleting.php
@@ -0,0 +1,20 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class CurrencyDeleting extends Event
{
public $currency;

/**
* Create a new event instance.
*
* @param $currency
*/
public function __construct($currency)
{
$this->currency = $currency;
}
}
24 changes: 24 additions & 0 deletions app/Events/Setting/CurrencyUpdated.php
@@ -0,0 +1,24 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class CurrencyUpdated extends Event
{
public $currency;

public $request;

/**
* Create a new event instance.
*
* @param $currency
* @param $request
*/
public function __construct($currency, $request)
{
$this->currency = $currency;
$this->request = $request;
}
}
24 changes: 24 additions & 0 deletions app/Events/Setting/CurrencyUpdating.php
@@ -0,0 +1,24 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class CurrencyUpdating extends Event
{
public $currency;

public $request;

/**
* Create a new event instance.
*
* @param $currency
* @param $request
*/
public function __construct($currency, $request)
{
$this->currency = $currency;
$this->request = $request;
}
}
6 changes: 6 additions & 0 deletions app/Jobs/Setting/CreateCurrency.php
Expand Up @@ -3,6 +3,8 @@
namespace App\Jobs\Setting;

use App\Abstracts\Job;
use App\Events\Setting\CurrencyCreated;
use App\Events\Setting\CurrencyCreating;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
Expand All @@ -12,6 +14,8 @@ class CreateCurrency extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Currency
{
event(new CurrencyCreating($this->request));

// Force the rate to be 1 for default currency
if ($this->request->get('default_currency')) {
$this->request['rate'] = '1';
Expand All @@ -27,6 +31,8 @@ public function handle(): Currency
}
});

event(new CurrencyCreated($this->model, $this->request));

return $this->model;
}
}
6 changes: 6 additions & 0 deletions app/Jobs/Setting/DeleteCurrency.php
Expand Up @@ -3,6 +3,8 @@
namespace App\Jobs\Setting;

use App\Abstracts\Job;
use App\Events\Setting\CurrencyDeleted;
use App\Events\Setting\CurrencyDeleting;
use App\Interfaces\Job\ShouldDelete;

class DeleteCurrency extends Job implements ShouldDelete
Expand All @@ -11,10 +13,14 @@ public function handle(): bool
{
$this->authorize();

event(new CurrencyDeleting($this->model));

\DB::transaction(function () {
$this->model->delete();
});

event(new CurrencyDeleted($this->model));

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions app/Jobs/Setting/UpdateCurrency.php
Expand Up @@ -3,6 +3,8 @@
namespace App\Jobs\Setting;

use App\Abstracts\Job;
use App\Events\Setting\CurrencyUpdated;
use App\Events\Setting\CurrencyUpdating;
use App\Interfaces\Job\ShouldUpdate;
use App\Models\Setting\Currency;

Expand All @@ -12,6 +14,8 @@ public function handle(): Currency
{
$this->authorize();

event(new CurrencyUpdating($this->model, $this->request));

// Force the rate to be 1 for default currency
if ($this->request->get('default_currency')) {
$this->request['rate'] = '1';
Expand All @@ -27,6 +31,8 @@ public function handle(): Currency
}
});

event(new CurrencyUpdated($this->model, $this->request));

return $this->model;
}

Expand Down

0 comments on commit 9edf50f

Please sign in to comment.