Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ReadingLogStoreService | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| store | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\ReadingLog\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\AbstractModelDefault; |
| 7 | use App\Models\ReadingLog\ReadingLog; |
| 8 | use App\Models\User; |
| 9 | use Domain\ReadingLog\DTOs\ReadingLogDTO; |
| 10 | use Illuminate\Database\QueryException; |
| 11 | use Symfony\Component\HttpKernel\Exception\HttpException; |
| 12 | |
| 13 | use function __; |
| 14 | |
| 15 | class ReadingLogStoreService |
| 16 | { |
| 17 | public function store(ReadingLogDTO $readingLogDTO, AbstractModelDefault $originable, User $user): ReadingLog |
| 18 | { |
| 19 | try { |
| 20 | $readingLog = new ReadingLog(); |
| 21 | $readingLog->fill($readingLogDTO->toArray()); |
| 22 | $readingLog->originable()->associate($originable); |
| 23 | $readingLog->save(); |
| 24 | } catch (QueryException $exception) { |
| 25 | throw new HttpException(422, |
| 26 | __('It was not possible to save the reading log. Please try again.') |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | ServiceProcessed::dispatch(self::class, $user); |
| 31 | return $readingLog; |
| 32 | } |
| 33 | } |