feat: Add platforms to stations

This commit is contained in:
2025-09-18 18:57:36 +02:00
parent 050badbd85
commit 19a178bbd2
5 changed files with 80 additions and 12 deletions
@@ -2,5 +2,16 @@ package de.twomartens.timetable.model.common
data class Platform(
var name: String,
var sections: MutableList<Section>
)
) {
private var sectionsInternal: MutableSet<Section> = mutableSetOf()
val sections: Set<Section> get() = sectionsInternal
fun addSection(section: Section) {
sectionsInternal.add(section)
}
fun addAllSections(sections: Collection<Section>) {
sectionsInternal.addAll(sections)
}
}
@@ -18,7 +18,6 @@ data class Station(
var stationId: StationId,
var countryCode: CountryCode,
var name: NonEmptyString,
var platforms: List<Platform>
) {
@Id
lateinit var id: ObjectId
@@ -28,4 +27,24 @@ data class Station(
@LastModifiedDate
lateinit var lastModified: Instant
private var platformsInternal: MutableMap<String, Platform> = mutableMapOf()
val platforms: List<Platform> get() = platformsInternal.values.toList()
fun addPlatform(platform: Platform?) {
if (platform == null) {
return
}
if (!platformsInternal.containsKey(platform.name)) {
platformsInternal[platform.name] = platform
} else {
platformsInternal[platform.name]?.addAllSections(platform.sections)
}
}
fun addAllPlatforms(platforms: Collection<Platform>) {
platforms.forEach { addPlatform(it) }
}
}
@@ -16,12 +16,13 @@ interface StationMapper {
@Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true)
fun mapToDB(countryCode: CountryCode, dto: Station): de.twomartens.timetable.model.db.Station {
return de.twomartens.timetable.model.db.Station(
val station = de.twomartens.timetable.model.db.Station(
StationId.of(NonEmptyString(countryCode.countryCode.value + "-" + dto.id)),
countryCode,
NonEmptyString(dto.name),
dto.platforms
NonEmptyString(dto.name)
)
station.addAllPlatforms(dto.platforms)
return station
}
fun mapStationsToDto(stations: List<de.twomartens.timetable.model.db.Station>): List<Station>