-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract logic from Reactant Listeners to Reactant Jobs (#146)
Extract logic from Reactant Listeners to Reactant Jobs
- Loading branch information
1 parent
9c0c058
commit be15cae
Showing
5 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Love. | ||
* | ||
* (c) Anton Komarev <anton@komarev.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Love\Reactant\Jobs; | ||
|
||
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantContract; | ||
use Cog\Contracts\Love\Reaction\Models\Reaction as ReactionContract; | ||
use Cog\Laravel\Love\Reactant\ReactionCounter\Services\ReactionCounterService; | ||
use Cog\Laravel\Love\Reactant\ReactionTotal\Services\ReactionTotalService; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
final class DecrementAggregatesJob implements | ||
ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use Queueable; | ||
|
||
/** | ||
* @var \Cog\Contracts\Love\Reactant\Models\Reactant | ||
*/ | ||
private $reactant; | ||
|
||
/** | ||
* @var \Cog\Contracts\Love\Reaction\Models\Reaction | ||
*/ | ||
private $reaction; | ||
|
||
/** | ||
* @param \Cog\Contracts\Love\Reactant\Models\Reactant $reactant | ||
* @param \Cog\Contracts\Love\Reaction\Models\Reaction $reaction | ||
*/ | ||
public function __construct( | ||
ReactantContract $reactant, | ||
ReactionContract $reaction | ||
) { | ||
$this->reactant = $reactant; | ||
$this->reaction = $reaction; | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
(new ReactionCounterService($this->reactant)) | ||
->removeReaction($this->reaction); | ||
|
||
(new ReactionTotalService($this->reactant)) | ||
->removeReaction($this->reaction); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Love. | ||
* | ||
* (c) Anton Komarev <anton@komarev.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Love\Reactant\Jobs; | ||
|
||
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantContract; | ||
use Cog\Contracts\Love\Reaction\Models\Reaction as ReactionContract; | ||
use Cog\Laravel\Love\Reactant\ReactionCounter\Services\ReactionCounterService; | ||
use Cog\Laravel\Love\Reactant\ReactionTotal\Services\ReactionTotalService; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
final class IncrementAggregatesJob implements | ||
ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use Queueable; | ||
|
||
/** | ||
* @var \Cog\Contracts\Love\Reactant\Models\Reactant | ||
*/ | ||
private $reactant; | ||
|
||
/** | ||
* @var \Cog\Contracts\Love\Reaction\Models\Reaction | ||
*/ | ||
private $reaction; | ||
|
||
/** | ||
* @param \Cog\Contracts\Love\Reactant\Models\Reactant $reactant | ||
* @param \Cog\Contracts\Love\Reaction\Models\Reaction $reaction | ||
*/ | ||
public function __construct( | ||
ReactantContract $reactant, | ||
ReactionContract $reaction | ||
) { | ||
$this->reactant = $reactant; | ||
$this->reaction = $reaction; | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
(new ReactionCounterService($this->reactant)) | ||
->addReaction($this->reaction); | ||
|
||
(new ReactionTotalService($this->reactant)) | ||
->addReaction($this->reaction); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters