Add transport DDL, repos and transport service

Add database DDL and server-side data access/service layers for transport domain. New SQL DDL files create transport_types, lines, stations, platforms and platform_lines tables (with FKs, indexes, spatial POINT column, CHECK constraints, and triggers to populate location). New repositories implement queries and CRUD for lines, stations, platforms and platform_lines (including distance/nearest-platform and accessibility queries). A transportService aggregates repo functions and exposes high-level operations (CRUD, station/line lookups, platform-line management and nearest-platform validation).
This commit is contained in:
2026-09-22 10:27:12 +02:00
parent 38882d7b87
commit e5eccb77db
11 changed files with 660 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS `transport_types` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL UNIQUE,
`descriptor` VARCHAR(100) NOT NULL UNIQUE,
`glyphUrl` VARCHAR(2048),
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
);
INSERT IGNORE INTO `transport_types` (name, descriptor, glyphUrl) VALUES
('Bus', 'bus', "https://upload.wikimedia.org/wikipedia/commons/4/46/Paris_Bus_icon.svg"),
('Métro', 'metro', "https://upload.wikimedia.org/wikipedia/commons/5/5e/Metro-M.svg"),
('RER', 'rer', "https://upload.wikimedia.org/wikipedia/commons/1/13/RER.svg"),
('Transilien', 'transilien', "https://upload.wikimedia.org/wikipedia/fr/f/f3/Logo_Transilien_%28RATP%29.svg"),
('Trains TER', 'tertrain', "https://upload.wikimedia.org/wikipedia/commons/9/98/Logo_TER.svg");
+17
View File
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS `lines` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`code` VARCHAR(50) NOT NULL UNIQUE,
`name` VARCHAR(255),
`textColorHex` VARCHAR(7),
`backColorHex` VARCHAR(7),
`transportTypeId` INT UNSIGNED NOT NULL,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
CONSTRAINT `fk_lines_transport_type`
FOREIGN KEY (`transportTypeId`)
REFERENCES `transport_types` (`id`),
INDEX `idx_transport_type` (`transportTypeId`)
);
+9
View File
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `stations` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NULL,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
INDEX idx_stations_name (name)
);
+22
View File
@@ -0,0 +1,22 @@
CREATE TABLE IF NOT EXISTS `platforms` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`stationId` INT UNSIGNED NOT NULL,
`name` VARCHAR(255) NULL,
`direction` VARCHAR(255) NULL,
`latitude` DECIMAL(10, 8) NOT NULL,
`longitude` DECIMAL(11, 8) NOT NULL,
`location` POINT NOT NULL,
`isPRM` BOOLEAN NOT NULL DEFAULT FALSE,
`hasElevator` BOOLEAN NOT NULL DEFAULT FALSE,
`createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
SPATIAL INDEX idx_platforms_location (location),
INDEX idx_platforms_station (stationId),
CONSTRAINT fk_platforms_station FOREIGN KEY (stationId)
REFERENCES stations(id) ON DELETE CASCADE,
CONSTRAINT chk_platforms_latitude CHECK (latitude BETWEEN -90 AND 90),
CONSTRAINT chk_platforms_longitude CHECK (longitude BETWEEN -180 AND 180)
);
+17
View File
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS `platform_lines` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`platformId` INT UNSIGNED NOT NULL,
`lineId` INT UNSIGNED NOT NULL,
`directionId` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`orderInLine` SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uq_platform_line_dir (platformId, lineId, directionId),
UNIQUE KEY uq_line_dir_order (lineId, directionId, orderInLine),
INDEX idx_pl_line (lineId),
CONSTRAINT fk_pl_platform FOREIGN KEY (platformId)
REFERENCES platforms(id) ON DELETE CASCADE,
CONSTRAINT fk_pl_line FOREIGN KEY (lineId)
REFERENCES `lines`(id) ON DELETE CASCADE
);
+13
View File
@@ -0,0 +1,13 @@
CREATE TRIGGER IF NOT EXISTS trg_platforms_before_insert
BEFORE INSERT ON `platforms`
FOR EACH ROW
BEGIN
SET NEW.location = POINT(NEW.longitude, NEW.latitude);
END;
CREATE TRIGGER IF NOT EXISTS trg_platforms_before_update
BEFORE UPDATE ON `platforms`
FOR EACH ROW
BEGIN
SET NEW.location = POINT(NEW.longitude, NEW.latitude);
END;