feat: Process fetched timetables and combine stops into services

This commit is contained in:
2025-09-18 17:19:55 +02:00
parent 513acf40c2
commit 050badbd85
19 changed files with 519 additions and 3 deletions
@@ -0,0 +1,35 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.common.ServiceId
import de.twomartens.timetable.model.common.TimetableId
import de.twomartens.timetable.model.common.UserId
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.mapping.Document
import java.time.Instant
@Document
@CompoundIndex(def = "{'userId': 1, 'timetableId': 1, 'serviceId': 1}", unique = true)
data class Service(
var userId: UserId,
var timetableId: TimetableId,
var serviceId: ServiceId,
private var stops: MutableList<ServiceStop> = mutableListOf()
) {
@Id
lateinit var id: ObjectId
@CreatedDate
lateinit var created: Instant
@LastModifiedDate
lateinit var lastModified: Instant
fun addStop(stop: ServiceStop) {
stops.add(stop)
stops.sortWith(compareBy { it.plannedDepartureTime ?: it.plannedArrivalTime })
}
}
@@ -0,0 +1,14 @@
package de.twomartens.timetable.model.db
import de.twomartens.timetable.model.common.ServiceId
import de.twomartens.timetable.model.common.TimetableId
import de.twomartens.timetable.model.common.UserId
import org.bson.types.ObjectId
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.stereotype.Repository
@Repository
interface ServiceRepository : MongoRepository<Service, ObjectId> {
fun existsServiceByUserIdAndTimetableIdAndServiceId(userId: UserId, timetableId: TimetableId, serviceId: ServiceId): Boolean
fun getServiceByUserIdAndTimetableIdAndServiceId(userId: UserId, timetableId: TimetableId, serviceId: ServiceId): Service?
}
@@ -0,0 +1,32 @@
package de.twomartens.timetable.model.db
import java.time.ZonedDateTime
data class ServiceStop(
/** The EVA number of the station */
val eva: String,
/** Planned arrival time at this stop */
var plannedArrivalTime: ZonedDateTime? = null,
/** Planned departure time from this stop */
var plannedDepartureTime: ZonedDateTime? = null,
/** Platform for arrival */
var plannedArrivalPlatform: String? = null,
/** Platform for departure */
var plannedDeparturePlatform: String? = null,
/** Line information for arrival */
var arrivalLine: String? = null,
/** Line information for departure */
var departureLine: String? = null,
/** Path information for arrival */
var plannedArrivalPath: String? = null,
/** Path information for departure */
var plannedDeparturePath: String? = null
)
@@ -2,7 +2,9 @@ package de.twomartens.timetable.model.dto
enum class TimetableState {
NEW,
PROCESSING,
FETCHING_TIMETABLES,
TIMETABLES_FETCHED,
SERVICES_COLLECTED,
ENTER_FORMATIONS,
LINK_SERVICES,
READY_FOR_USAGE