mirror of
https://github.com/2martens/tsw-timetable.git
synced 2026-10-17 16:06:51 +02:00
Moved common model classes to common package
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package de.twomartens.timetable.bahnApi.model
|
package de.twomartens.timetable.bahnApi.model
|
||||||
|
|
||||||
import de.twomartens.timetable.model.db.StationId
|
import de.twomartens.timetable.model.common.StationId
|
||||||
|
|
||||||
@JvmInline
|
@JvmInline
|
||||||
value class Eva(val value: Int) {
|
value class Eva(val value: Int) {
|
||||||
@@ -18,7 +18,7 @@ value class Eva(val value: Int) {
|
|||||||
val UNKNOWN = Eva(-1)
|
val UNKNOWN = Eva(-1)
|
||||||
|
|
||||||
fun of(stationId: StationId): Eva {
|
fun of(stationId: StationId): Eva {
|
||||||
return Eva(stationId.stationIdWithinCountry.name.toInt())
|
return Eva(stationId.stationIdWithinCountry.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package de.twomartens.timetable.controller
|
package de.twomartens.timetable.controller
|
||||||
|
|
||||||
import de.twomartens.timetable.bahnApi.service.ScheduledTaskService
|
import de.twomartens.timetable.bahnApi.service.ScheduledTaskService
|
||||||
import de.twomartens.timetable.model.db.UserId
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.repository.TswRouteRepository
|
import de.twomartens.timetable.repository.TswRouteRepository
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
import io.swagger.v3.oas.annotations.Operation
|
import io.swagger.v3.oas.annotations.Operation
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
import de.twomartens.timetable.types.PositiveInteger
|
import de.twomartens.timetable.types.PositiveInteger
|
||||||
|
|
||||||
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
|
|
||||||
@JvmInline
|
@JvmInline
|
||||||
value class CountryCode(val countryCode: NonEmptyString) {
|
value class CountryCode(val countryCode: NonEmptyString) {
|
||||||
init {
|
init {
|
||||||
require(countryCode.name.length == 2) {
|
require(countryCode.value.length == 2) {
|
||||||
"CountryCode must be only two characters long to conform to ISO 3166-1 alpha-2"
|
"CountryCode must be only two characters long to conform to ISO 3166-1 alpha-2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
|
import de.twomartens.timetable.types.PositiveInteger
|
||||||
|
|
||||||
|
@JvmInline
|
||||||
|
value class FormationId private constructor(val id: Int) {
|
||||||
|
companion object {
|
||||||
|
val EMPTY = FormationId(-1)
|
||||||
|
|
||||||
|
fun of(id: PositiveInteger): FormationId {
|
||||||
|
return FormationId(id.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
data class Platform(
|
data class Platform(
|
||||||
var name: String,
|
var name: String,
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
|
|
||||||
|
@JvmInline
|
||||||
|
value class Section private constructor(val value: String) {
|
||||||
|
companion object {
|
||||||
|
fun of(section: NonEmptyString): Section {
|
||||||
|
return Section(section.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
|
|
||||||
|
@JvmInline
|
||||||
|
value class ServiceId private constructor(val value: String) {
|
||||||
|
companion object {
|
||||||
|
fun of(id: NonEmptyString): ServiceId {
|
||||||
|
return ServiceId(id.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
|
|
||||||
|
@JvmInline
|
||||||
|
value class StationId private constructor(val value: String) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val idPattern = Regex("^\\w{2}-(?<countryStationId>\\w.*)")
|
||||||
|
|
||||||
|
fun of(id: NonEmptyString): StationId {
|
||||||
|
require(idPattern.matches(id.value)) {
|
||||||
|
"StationId must start with two character country code, followed by a dash, " +
|
||||||
|
"and at least one word character"
|
||||||
|
}
|
||||||
|
|
||||||
|
return StationId(id.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val stationIdWithinCountry: String
|
||||||
|
get() {
|
||||||
|
val matchResult = idPattern.matchEntire(value)
|
||||||
|
val groupMatch = matchResult?.groups?.get("countryStationId")?.value
|
||||||
|
|
||||||
|
require(matchResult != null && groupMatch != null)
|
||||||
|
|
||||||
|
return groupMatch
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
|
import de.twomartens.timetable.types.PositiveInteger
|
||||||
|
|
||||||
|
@JvmInline
|
||||||
|
value class TrackId private constructor(val value: Int) {
|
||||||
|
companion object {
|
||||||
|
fun of(id: PositiveInteger): TrackId {
|
||||||
|
return TrackId(id.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.twomartens.timetable.model.common
|
||||||
|
|
||||||
|
import de.twomartens.timetable.types.NonEmptyString
|
||||||
|
|
||||||
|
@JvmInline
|
||||||
|
value class UserId private constructor(val value: String) {
|
||||||
|
companion object {
|
||||||
|
fun of(id: NonEmptyString): UserId {
|
||||||
|
return UserId(id.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.db
|
||||||
|
|
||||||
|
import de.twomartens.timetable.model.common.FormationId
|
||||||
|
import de.twomartens.timetable.model.common.UserId
|
||||||
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
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package de.twomartens.timetable.model.db
|
|
||||||
|
|
||||||
import de.twomartens.timetable.types.PositiveInteger
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class FormationId(val id: PositiveInteger)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package de.twomartens.timetable.model.db
|
|
||||||
|
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class Section(val name: NonEmptyString)
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.db
|
||||||
|
|
||||||
|
import de.twomartens.timetable.model.common.Platform
|
||||||
|
import de.twomartens.timetable.model.common.StationId
|
||||||
import org.bson.types.ObjectId
|
import org.bson.types.ObjectId
|
||||||
import org.springframework.data.annotation.CreatedDate
|
import org.springframework.data.annotation.CreatedDate
|
||||||
import org.springframework.data.annotation.Id
|
import org.springframework.data.annotation.Id
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package de.twomartens.timetable.model.db
|
|
||||||
|
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class StationId(val id: NonEmptyString) {
|
|
||||||
init {
|
|
||||||
require(idPattern.matches(id.name)) {
|
|
||||||
"StationId must start with two character country code, followed by a dash, " +
|
|
||||||
"and at least one word character"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val idPattern = Regex("^\\w{2}-(?<countryStationId>\\w.*)")
|
|
||||||
}
|
|
||||||
|
|
||||||
val stationIdWithinCountry: NonEmptyString
|
|
||||||
get() {
|
|
||||||
val matchResult = idPattern.matchEntire(id.name)
|
|
||||||
val groupMatch = matchResult?.groups?.get("countryStationId")?.value
|
|
||||||
return when {
|
|
||||||
matchResult == null || groupMatch == null ->
|
|
||||||
throw IllegalArgumentException("id wasn't matched by pattern")
|
|
||||||
|
|
||||||
else -> NonEmptyString(groupMatch)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package de.twomartens.timetable.model.db
|
|
||||||
|
|
||||||
import de.twomartens.timetable.types.PositiveInteger
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class TrackId(val id: PositiveInteger)
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.db
|
||||||
|
|
||||||
|
import de.twomartens.timetable.model.common.*
|
||||||
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
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.twomartens.timetable.model.db
|
package de.twomartens.timetable.model.db
|
||||||
|
|
||||||
|
import de.twomartens.timetable.model.common.UserId
|
||||||
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
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package de.twomartens.timetable.model.db
|
|
||||||
|
|
||||||
import de.twomartens.timetable.types.NonEmptyString
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class UserId(val id: NonEmptyString)
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package de.twomartens.timetable.repository
|
package de.twomartens.timetable.repository
|
||||||
|
|
||||||
|
import de.twomartens.timetable.model.common.UserId
|
||||||
import de.twomartens.timetable.model.db.TswRoute
|
import de.twomartens.timetable.model.db.TswRoute
|
||||||
import de.twomartens.timetable.model.db.UserId
|
|
||||||
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.mongodb.repository.MongoRepository
|
import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
|
|||||||
Reference in New Issue
Block a user