Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗃️ drop origin and destination on train_checkins #2581

Merged
merged 7 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'develop' into dev-ks/checkin-ori-des
# Conflicts:
#	app/Http/Controllers/Backend/User/DashboardController.php
#	app/Http/Controllers/FrontendStatusController.php
#	app/Models/Checkin.php
#	database/migrations/2023_12_20_000000_migrate_stopover_relation_id_in_train_checkins.php
#	database/schema/sqlite-schema.sql
#	tests/Feature/APIv1/StatusTest.php
  • Loading branch information
MrKrisKrisu committed Jun 6, 2024
commit 1424a6186ed5d6c9e2c80be8d235ac778220f131
7 changes: 5 additions & 2 deletions app/Http/Controllers/Backend/User/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public static function getPrivateDashboard(User $user): Paginator {
$followingIDs[] = $user->id;
return Status::with([
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin',
'mentions.mentioned',
'checkin.originStopover.station', 'checkin.destinationStopover.station',
'checkin.Trip.stopovers.station'
'checkin.trip.stopovers.station'
])
->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id')
->select('statuses.*')
Expand All @@ -40,8 +41,10 @@ public static function getPrivateDashboard(User $user): Paginator {
public static function getGlobalDashboard(User $user): Paginator {
return Status::with([
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin',
'mentions.mentioned',
'checkin.originStopover.station', 'checkin.destinationStopover.station',
'checkin.Trip.stopovers.station'
'checkin.originStopover', 'checkin.destinationStopover',
'checkin.trip.stopovers.station'
])
->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id')
->join('users', 'statuses.user_id', '=', 'users.id')
Expand Down
8 changes: 8 additions & 0 deletions app/Models/Checkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public function HafasTrip(): HasOne {
return $this->trip();
}

public function originStation(): HasOne {
return $this->hasOne(Station::class, 'ibnr', 'origin');
}

public function destinationStation(): HasOne {
return $this->hasOne(Station::class, 'ibnr', 'destination');
}

public function trip(): HasOne {
return $this->hasOne(Trip::class, 'trip_id', 'trip_id');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public function up(): void {
->orWhereNull('destination_stopover_id')
->limit(100)
->each(function(Checkin $checkin) {
$originStopover = $checkin->HafasTrip->stopovers->where('train_station_id', $checkin->originStopover->station->id)
$originStopover = $checkin->trip->stopovers->where('train_station_id', $checkin->originStopover->station->id)
->where('departure_planned', $checkin->departure)
->first();

$destinationStopover = $checkin->HafasTrip->stopovers->where('train_station_id', $checkin->destinationStopover->station->id)
$destinationStopover = $checkin->trip->stopovers->where('train_station_id', $checkin->destinationStopover->station->id)
->where('arrival_planned', $checkin->arrival)
->first();

Expand Down
29 changes: 27 additions & 2 deletions database/schema/sqlite-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,24 @@ CREATE INDEX "activity_log_log_name_index" on "activity_log" ("log_name");
CREATE TABLE IF NOT EXISTS "mentions" ("id" integer primary key autoincrement not null, "status_id" integer not null, "mentioned_id" integer not null, "position" integer not null, "length" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("status_id") references "statuses"("id") on delete cascade, foreign key("mentioned_id") references "users"("id") on delete cascade);
CREATE UNIQUE INDEX "mentions_status_id_mentioned_id_position_unique" on "mentions" ("status_id", "mentioned_id", "position");
CREATE TABLE IF NOT EXISTS "wikidata_entities" ("id" varchar not null, "data" text, "last_updated_at" datetime, "created_at" datetime, "updated_at" datetime, primary key ("id"));
CREATE INDEX "ifopt" on "train_stations" ("ifopt_a", "ifopt_b", "ifopt_c", "ifopt_d", "ifopt_e");
CREATE TABLE IF NOT EXISTS "reports" ("id" integer primary key autoincrement not null, "status" varchar not null default 'open', "subject_type" varchar not null, "subject_id" integer not null, "reason" varchar, "description" varchar, "reporter_id" integer, "created_at" datetime, "updated_at" datetime, foreign key("reporter_id") references "users"("id") on delete set null);
CREATE INDEX "reports_subject_type_subject_id_index" on "reports" ("subject_type", "subject_id");
CREATE INDEX "reports_status_index" on "reports" ("status");
CREATE INDEX "poly_lines_parent_id_index" on "poly_lines" ("parent_id");
CREATE TABLE train_stations (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ibnr BIGINT UNSIGNED DEFAULT NULL, name VARCHAR(255) NOT NULL, latitude NUMERIC(9, 6) NOT NULL, longitude NUMERIC(9, 6) NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, rilIdentifier VARCHAR(255) DEFAULT NULL, time_offset INTEGER DEFAULT NULL, shift_time BOOLEAN DEFAULT NULL, wikidata_id VARCHAR(255) DEFAULT NULL, ifopt_e INTEGER DEFAULT NULL, ifopt_d INTEGER DEFAULT NULL, ifopt_c INTEGER DEFAULT NULL, ifopt_b INTEGER DEFAULT NULL, ifopt_a VARCHAR(255) DEFAULT NULL);
CREATE INDEX ifopt ON train_stations (ifopt_a, ifopt_b, ifopt_c, ifopt_d, ifopt_e);
CREATE INDEX train_stations_rilidentifier_index ON train_stations (rilIdentifier);
CREATE UNIQUE INDEX train_stations_ibnr_unique ON train_stations (ibnr);
CREATE INDEX "hafas_trips_operator_id_category_index" on "hafas_trips" ("operator_id", "category");
CREATE INDEX "queue_monitor_name_status_queue_index" on "queue_monitor" ("name", "status", "queue");
CREATE INDEX "statuses_user_id_visibility_index" on "statuses" ("user_id", "visibility");
CREATE INDEX "poly_lines_source_index" on "poly_lines" ("source");
CREATE INDEX "index_trip_id_arrival_departure" on "train_stopovers" ("trip_id", "arrival_planned", "departure_planned");
CREATE TABLE events (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, station_id BIGINT UNSIGNED DEFAULT NULL, name VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL, hashtag VARCHAR(255) DEFAULT NULL, host VARCHAR(255) DEFAULT NULL, url VARCHAR(255) DEFAULT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, event_start DATETIME DEFAULT NULL --If different from checkin_start
, event_end DATETIME DEFAULT NULL --If different from checkin_end
, approved_by INTEGER DEFAULT NULL, checkin_start DATETIME NOT NULL, checkin_end DATETIME NOT NULL, FOREIGN KEY (station_id) REFERENCES train_stations (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE);
CREATE UNIQUE INDEX events_slug_unique ON events (slug);
CREATE INDEX IDX_5387574A21BDB235 ON events (station_id);
CREATE TABLE IF NOT EXISTS "reports" ("id" integer primary key autoincrement not null, "status" varchar not null default 'open', "subject_type" varchar not null, "subject_id" integer not null, "reason" varchar, "description" varchar, "reporter_id" integer, "created_at" datetime, "updated_at" datetime, foreign key("reporter_id") references "users"("id") on delete set null);
CREATE INDEX "reports_subject_type_subject_id_index" on "reports" ("subject_type", "subject_id");
CREATE INDEX "reports_status_index" on "reports" ("status");
Expand Down Expand Up @@ -282,4 +299,12 @@ INSERT INTO migrations VALUES(182,'2024_03_22_000001_migrate_origin_and_destinat
INSERT INTO migrations VALUES(183,'2024_03_22_000002_make_trip_origin_id_and_destination_id_not_nullable',1);
INSERT INTO migrations VALUES(184,'2024_01_30_000001_create_reports_table',2);
INSERT INTO migrations VALUES(185,'2024_04_19_131906_add_index_to_poly_line_parent_id',2);
INSERT INTO migrations VALUES(186,'2024_05_22_000003_drop_origin_destination_from_check_in',2);
INSERT INTO migrations VALUES(186,'2024_05_21_000001_remove_station_ibnr_from_hafas_trips',2);
INSERT INTO migrations VALUES(187,'2024_05_21_000000_make_ibnr_nullable_on_stations',3);
INSERT INTO migrations VALUES(188,'2024_05_22_000004_add_index_operator_id_category_to_hafas_trips',3);
INSERT INTO migrations VALUES(189,'2024_05_22_000005_add_index_name_status_queue_on_queue_monitor',3);
INSERT INTO migrations VALUES(190,'2024_05_22_000008_add_index_user_id_visibility_on_statuses',3);
INSERT INTO migrations VALUES(191,'2024_05_25_000000_add_source_index_to_polylines',3);
INSERT INTO migrations VALUES(192,'2024_05_25_000001_add_trip_id_arrival_departure_index_to_train_stopovers',3);
INSERT INTO migrations VALUES(193,'2024_05_27_000000_drop_shadow_banned_from_users',3);
INSERT INTO migrations VALUES(194,'2024_05_30_000000_add_prefix_to_begin_end_on_events',3);
10 changes: 5 additions & 5 deletions tests/Feature/APIv1/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public function testActiveStatusesDontShowStatusesFromTheFuture(): void {
$trip = Trip::factory(['departure' => $departure, 'arrival' => $arrival])->create();

Checkin::factory([
'user_id' => $user->id,
'departure' => $trip->departure,
'arrival' => $trip->arrival,
'trip_id' => $trip->trip_id,
])->create();
'user_id' => $user->id,
'departure' => $trip->departure,
'arrival' => $trip->arrival,
'trip_id' => $trip->trip_id,
])->create();

$response = $this->get('/api/v1/user/statuses/active');
$response->assertNotFound();
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.