Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UpdateTripHandler | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Trip\Application\Command; |
| 6 | |
| 7 | use App\Shared\Domain\ValueObject\DateRange; |
| 8 | use App\Shared\Domain\ValueObject\Money; |
| 9 | use App\Shared\Infrastructure\Storage\SignedImageUrl; |
| 10 | use App\Trip\Application\Query\TripView; |
| 11 | use App\Trip\Application\TripAccess; |
| 12 | use App\Trip\Domain\TripRepository; |
| 13 | use App\Trip\Domain\ValueObject\TripId; |
| 14 | use App\Trip\Domain\ValueObject\TripRole; |
| 15 | |
| 16 | final readonly class UpdateTripHandler |
| 17 | { |
| 18 | public function __construct( |
| 19 | private TripAccess $access, |
| 20 | private TripRepository $trips, |
| 21 | private SignedImageUrl $imageUrls, |
| 22 | ) { |
| 23 | } |
| 24 | |
| 25 | public function handle(UpdateTripCommand $command): TripView |
| 26 | { |
| 27 | // Owner only: a stranger gets TripNotFound (404), a non-owner member |
| 28 | // TripAccessDenied (403). |
| 29 | $trip = $this->access->getForManage(new TripId($command->tripId), $command->userId); |
| 30 | |
| 31 | // Currency is fixed at creation; the budget stays in the trip currency. |
| 32 | $trip->update( |
| 33 | $command->name, |
| 34 | $command->destination, |
| 35 | DateRange::fromIso($command->startDate, $command->endDate), |
| 36 | new Money($command->budgetAmount, $trip->currency()), |
| 37 | ); |
| 38 | |
| 39 | $this->trips->save($trip); |
| 40 | |
| 41 | return TripView::fromTrip($trip, TripRole::OWNER, $this->imageUrls->for($trip->imageName())); |
| 42 | } |
| 43 | } |