Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| StoreTeamUserService | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\User\Services; |
| 4 | |
| 5 | use Illuminate\Support\Facades\DB; |
| 6 | |
| 7 | use Carbon\Carbon; |
| 8 | |
| 9 | use App\Events\ServiceProcessed; |
| 10 | use App\Models\Team\Team; |
| 11 | use App\Models\User; |
| 12 | |
| 13 | use Domain\User\DTOs\UserDTO; |
| 14 | use Exception; |
| 15 | |
| 16 | readonly class StoreTeamUserService |
| 17 | { |
| 18 | private User $user; |
| 19 | private Team $team; |
| 20 | |
| 21 | /** |
| 22 | * @param UserDTO $userDTO |
| 23 | * @param User $user |
| 24 | */ |
| 25 | public function __construct(User $user, Team $team) |
| 26 | { |
| 27 | $this->user = $user; |
| 28 | $this->team = $team; |
| 29 | } |
| 30 | |
| 31 | public function store() |
| 32 | { |
| 33 | try { |
| 34 | DB::beginTransaction(); |
| 35 | |
| 36 | DB::insert( |
| 37 | 'insert into team_user (user_id, team_id, created_at, updated_at) values(?, ?, ?, ?)', |
| 38 | [ |
| 39 | $this->user->getKey(), |
| 40 | $this->team->getKey(), |
| 41 | Carbon::now(), |
| 42 | Carbon::now() |
| 43 | ]); |
| 44 | |
| 45 | DB::commit(); |
| 46 | } catch (Exception $exception) { |
| 47 | DB::rollBack(); |
| 48 | throw $exception; |
| 49 | } |
| 50 | |
| 51 | ServiceProcessed::dispatch(self::class, $this->user); |
| 52 | } |
| 53 | } |