Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| StorageStoreService | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| store | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Storage\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\Storage\Storage; |
| 7 | use App\Models\User; |
| 8 | use Domain\Storage\DTOs\StorageDTO; |
| 9 | use Domain\Transferable\Services\TransferableStoreService; |
| 10 | use Exception; |
| 11 | use Illuminate\Support\Facades\DB; |
| 12 | |
| 13 | readonly class StorageStoreService |
| 14 | { |
| 15 | /** |
| 16 | * @param StorageDTO $packDTO |
| 17 | * @param User $user |
| 18 | * |
| 19 | * @return Storage |
| 20 | * @throws Exception |
| 21 | */ |
| 22 | public function store(StorageDTO $packDTO, User $user): Storage |
| 23 | { |
| 24 | |
| 25 | try { |
| 26 | DB::beginTransaction(); |
| 27 | |
| 28 | $storage = new Storage($packDTO->toArray()); |
| 29 | $storage->user()->associate($user); |
| 30 | $storage->save(); |
| 31 | |
| 32 | (new TransferableStoreService())->store($storage); |
| 33 | |
| 34 | DB::commit(); |
| 35 | } catch (Exception $exception) { |
| 36 | DB::rollBack(); |
| 37 | throw $exception; |
| 38 | } |
| 39 | |
| 40 | ServiceProcessed::dispatch(self::class, $user); |
| 41 | return $storage; |
| 42 | } |
| 43 | } |