Skip to content

Commit

Permalink
Adapt with hydrator
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin committed Jul 30, 2024
1 parent ef35152 commit e062656
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 58 deletions.
22 changes: 5 additions & 17 deletions app/Http/Controllers/API/v1/TransportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@

namespace App\Http\Controllers\API\v1;

use App\Dto\Internal\CheckinSuccessDto;
use App\Dto\Transport\Station as StationDto;
use App\Enum\Business;
use App\Enum\StatusVisibility;
use App\Enum\TravelType;
use App\Exceptions\Checkin\AlreadyCheckedInException;
use App\Exceptions\CheckInCollisionException;
use App\Exceptions\HafasException;
use App\Exceptions\NotConnectedException;
use App\Exceptions\StationNotOnTripException;
use App\Http\Controllers\Backend\Transport\StationController;
use App\Http\Controllers\Backend\Transport\TrainCheckinController;
use App\Http\Controllers\HafasController;
use App\Http\Controllers\TransportController as TransportBackend;
use App\Http\Resources\CheckinSuccessResource;
use App\Http\Resources\StationResource;
use App\Http\Resources\StatusResource;
use App\Http\Resources\TripResource;
use App\Hydrators\CheckinRequestHydrator;
use App\Models\Event;
use App\Models\Station;
use App\Models\User;
use App\Notifications\YouHaveBeenCheckedIn;
Expand Down Expand Up @@ -386,22 +382,14 @@ public function create(Request $request): JsonResponse {
}

try {
$checkinResponse = TrainCheckinController::checkin((new CheckinRequestHydrator($validated))->hydrateFromApi());
$dto = (new CheckinRequestHydrator($validated))->hydrateFromApi();
$checkinResponse = TrainCheckinController::checkin($dto);

//ToDo: Check if documented structure has changed
// if isset, check in the other users with their default values
foreach ($withUsers ?? [] as $user) {
$checkin = TrainCheckinController::checkin(
user: $user,
trip: $trip,
origin: $originStation,
departure: $departure,
destination: $destinationStation,
arrival: $arrival,
travelReason: $travelReason,
visibility: $user->default_status_visibility,
event: $event,
);
$dto->setUser($user);
$dto->setStatusVisibility($user->default_status_visibility);
$checkin = TrainCheckinController::checkin($dto);
$user->notify(new YouHaveBeenCheckedIn($checkin['status'], auth()->user()));
}

Expand Down
22 changes: 10 additions & 12 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@
* @property int privacy_hide_days
* @property string language
* @property Carbon last_login
* @property Status[] $statuses
* @property SocialLoginProfile socialProfile
* @property int points
* @property boolean userInvisibleToMe
* @property string mastodonUrl
* @property int train_distance
* @property int train_duration
* @property boolean following
* @property boolean followPending
* @property boolean muted
* @property boolean isAuthUserBlocked
* @property boolean isBlockedByAuthUser
* @property int points
* @property boolean userInvisibleToMe
* @property string mastodonUrl
* @property int train_distance
* @property int train_duration
* @property boolean following
* @property boolean followPending
* @property boolean muted
* @property boolean isAuthUserBlocked
* @property boolean isBlockedByAuthUser
*
* // relationships
* @property Collection trainCheckins
Expand Down
Loading

0 comments on commit e062656

Please sign in to comment.