Use HourAtDay

This commit is contained in:
2023-10-26 19:17:06 +02:00
parent ae358fd690
commit 91be5d66c5
3 changed files with 6 additions and 6 deletions
@@ -1,9 +1,9 @@
package de.twomartens.timetable.bahnApi.mapper
import de.twomartens.timetable.bahnApi.model.db.BahnTimetable
import de.twomartens.timetable.types.HourAtDay
import de.twomartens.timetable.types.NonEmptyString
import org.mapstruct.*
import java.time.LocalDateTime
@Mapper(
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
@@ -15,10 +15,10 @@ interface BahnTimetableMapper {
@Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true)
fun mapToDB(dto: de.twomartens.timetable.bahnApi.model.dto.BahnTimetable,
dateTime: LocalDateTime): BahnTimetable {
hourAtDay: HourAtDay): BahnTimetable {
return BahnTimetable(
dto.eva,
dateTime,
hourAtDay,
NonEmptyString(dto.station),
dto.stops
)
@@ -2,6 +2,7 @@ package de.twomartens.timetable.bahnApi.model.db
import de.twomartens.timetable.bahnApi.model.Eva
import de.twomartens.timetable.bahnApi.model.dto.BahnStationStop
import de.twomartens.timetable.types.HourAtDay
import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate
@@ -11,13 +12,12 @@ import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.TextIndexed
import org.springframework.data.mongodb.core.mapping.Document
import java.time.Instant
import java.time.LocalDateTime
@Document
@CompoundIndex(def = "{'eva': 1, 'dateTime': 1}", unique = true)
data class BahnTimetable(
var eva: Eva,
var dateTime: LocalDateTime,
var hourAtDay: HourAtDay,
@TextIndexed var station: NonEmptyString,
var stops: List<BahnStationStop>
) {
@@ -24,6 +24,6 @@ class BahnDatabaseService(
}
fun storeTimetable(timetable: BahnTimetable, hourAtDay: HourAtDay) {
bahnTimetableRepository.save(bahnTimetableMapper.mapToDB(timetable, hourAtDay.dateTime))
bahnTimetableRepository.save(bahnTimetableMapper.mapToDB(timetable, hourAtDay))
}
}