Skip to content

Commit

Permalink
✨ add TripSource for future purposes (#2154)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu authored Nov 22, 2023
1 parent 6925a70 commit 1453af5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
17 changes: 17 additions & 0 deletions app/Enum/TripSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace App\Enum;

enum TripSource: string
{
/**
* Trips created by data from DB-Rest (HAFAS Deutsche Bahn).
* @see https://v5.db.transport.rest/
*/
case HAFAS = 'hafas';

/**
* Trips created by the user - with manual data.
*/
case USER = 'user';
}
8 changes: 5 additions & 3 deletions app/Models/HafasTrip.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

use App\Casts\UTCDateTime;
use App\Enum\HafasTravelType;
use App\Enum\TripSource;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
* @property $stopovers
* @property $stopovers
* @property PolyLine $polyLine
* @property PolyLine $polyline
* @property $linename
* @property $linename
*/
class HafasTrip extends Model
{
Expand All @@ -23,7 +24,7 @@ class HafasTrip extends Model

protected $fillable = [
'trip_id', 'category', 'number', 'linename', 'journey_number', 'operator_id', 'origin', 'destination',
'polyline_id', 'departure', 'arrival', 'delay', 'last_refreshed',
'polyline_id', 'departure', 'arrival', 'delay', 'source', 'last_refreshed',
];
protected $hidden = ['created_at', 'updated_at'];
protected $casts = [
Expand All @@ -38,6 +39,7 @@ class HafasTrip extends Model
'departure' => UTCDateTime::class,
'arrival' => UTCDateTime::class,
'last_refreshed' => 'datetime',
'source' => TripSource::class,
];

public function polyline(): HasOne {
Expand Down
23 changes: 23 additions & 0 deletions database/migrations/2023_11_22_000000_add_source_to_trips.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{

public function up(): void {
Schema::table('hafas_trips', static function(Blueprint $table) {
$table->string('source')
->default('hafas')
->after('delay');
});
}

public function down(): void {
Schema::table('hafas_trips', static function(Blueprint $table) {
$table->dropColumn('source');
});
}
};

0 comments on commit 1453af5

Please sign in to comment.