Skip to content

Commit

Permalink
added contact events
Browse files Browse the repository at this point in the history
  • Loading branch information
CihanSenturk committed Oct 31, 2023
1 parent 1ab7fec commit 67969d0
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/Events/Common/ContactCreated.php
@@ -0,0 +1,21 @@
<?php

namespace App\Events\Common;

use App\Abstracts\Event;
use App\Models\Common\Contact;

class ContactCreated extends Event
{
public $contact;

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

namespace App\Events\Common;

use App\Abstracts\Event;

class ContactCreating 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/Common/ContactDeleted.php
@@ -0,0 +1,20 @@
<?php

namespace App\Events\Common;

use App\Abstracts\Event;

class ContactDeleted extends Event
{
public $contact;

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

namespace App\Events\Common;

use App\Abstracts\Event;

class ContactDeleting extends Event
{
public $contact;

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

namespace App\Events\Common;

use App\Abstracts\Event;
use App\Models\Common\Contact;

class ContactUpdated extends Event
{
public $contact;

public $request;

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

namespace App\Events\Common;

use App\Abstracts\Event;
use App\Models\Common\Contact;

class ContactUpdating extends Event
{
public $contact;

public $request;

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

use App\Abstracts\Job;
use App\Events\Common\ContactCreated;
use App\Events\Common\ContactCreating;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
Expand All @@ -15,6 +17,8 @@ class CreateContact extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Contact
{
event(new ContactCreating($this->request));

\DB::transaction(function () {
if ($this->request->get('create_user', 'false') === 'true') {
$this->createUser();
Expand All @@ -32,6 +36,8 @@ public function handle(): Contact
$this->dispatch(new CreateContactPersons($this->model, $this->request));
});

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

return $this->model;
}

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

use App\Abstracts\Job;
use App\Events\Common\ContactDeleted;
use App\Events\Common\ContactDeleting;
use App\Interfaces\Job\ShouldDelete;
use App\Jobs\Auth\DeleteUser;
use App\Traits\Contacts;
Expand All @@ -15,6 +17,8 @@ public function handle() :bool
{
$this->authorize();

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

\DB::transaction(function () {
$this->deleteRelationships($this->model, ['contact_persons']);

Expand All @@ -25,6 +29,8 @@ public function handle() :bool
$this->model->delete();
});

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

return true;
}

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

use App\Abstracts\Job;
use App\Events\Common\ContactUpdated;
use App\Events\Common\ContactUpdating;
use App\Interfaces\Job\ShouldUpdate;
use App\Jobs\Auth\CreateUser;
use App\Jobs\Common\CreateContactPersons;
Expand All @@ -15,6 +17,8 @@ public function handle(): Contact
{
$this->authorize();

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

\DB::transaction(function () {
if ($this->request->get('create_user', 'false') === 'true') {
$this->createUser();
Expand All @@ -40,6 +44,8 @@ public function handle(): Contact
$this->model->update($this->request->all());
});

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

return $this->model;
}

Expand Down

0 comments on commit 67969d0

Please sign in to comment.