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 package de.twomartens.timetable.bahnApi.mapper
import de.twomartens.timetable.bahnApi.model.db.BahnTimetable import de.twomartens.timetable.bahnApi.model.db.BahnTimetable
import de.twomartens.timetable.types.HourAtDay
import de.twomartens.timetable.types.NonEmptyString import de.twomartens.timetable.types.NonEmptyString
import org.mapstruct.* import org.mapstruct.*
import java.time.LocalDateTime
@Mapper( @Mapper(
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
@@ -15,10 +15,10 @@ interface BahnTimetableMapper {
@Mapping(target = "created", ignore = true) @Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true) @Mapping(target = "lastModified", ignore = true)
fun mapToDB(dto: de.twomartens.timetable.bahnApi.model.dto.BahnTimetable, fun mapToDB(dto: de.twomartens.timetable.bahnApi.model.dto.BahnTimetable,
dateTime: LocalDateTime): BahnTimetable { hourAtDay: HourAtDay): BahnTimetable {
return BahnTimetable( return BahnTimetable(
dto.eva, dto.eva,
dateTime, hourAtDay,
NonEmptyString(dto.station), NonEmptyString(dto.station),
dto.stops 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.Eva
import de.twomartens.timetable.bahnApi.model.dto.BahnStationStop import de.twomartens.timetable.bahnApi.model.dto.BahnStationStop
import de.twomartens.timetable.types.HourAtDay
import de.twomartens.timetable.types.NonEmptyString import de.twomartens.timetable.types.NonEmptyString
import org.bson.types.ObjectId import org.bson.types.ObjectId
import org.springframework.data.annotation.CreatedDate 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.index.TextIndexed
import org.springframework.data.mongodb.core.mapping.Document import org.springframework.data.mongodb.core.mapping.Document
import java.time.Instant import java.time.Instant
import java.time.LocalDateTime
@Document @Document
@CompoundIndex(def = "{'eva': 1, 'dateTime': 1}", unique = true) @CompoundIndex(def = "{'eva': 1, 'dateTime': 1}", unique = true)
data class BahnTimetable( data class BahnTimetable(
var eva: Eva, var eva: Eva,
var dateTime: LocalDateTime, var hourAtDay: HourAtDay,
@TextIndexed var station: NonEmptyString, @TextIndexed var station: NonEmptyString,
var stops: List<BahnStationStop> var stops: List<BahnStationStop>
) { ) {
@@ -24,6 +24,6 @@ class BahnDatabaseService(
} }
fun storeTimetable(timetable: BahnTimetable, hourAtDay: HourAtDay) { fun storeTimetable(timetable: BahnTimetable, hourAtDay: HourAtDay) {
bahnTimetableRepository.save(bahnTimetableMapper.mapToDB(timetable, hourAtDay.dateTime)) bahnTimetableRepository.save(bahnTimetableMapper.mapToDB(timetable, hourAtDay))
} }
} }