24 */ |
24 */ |
25 |
25 |
26 package de.uapcore.lightpit |
26 package de.uapcore.lightpit |
27 |
27 |
28 import de.uapcore.lightpit.dao.DataAccessObject |
28 import de.uapcore.lightpit.dao.DataAccessObject |
|
29 import de.uapcore.lightpit.entities.HasNode |
29 import de.uapcore.lightpit.viewmodel.NavMenu |
30 import de.uapcore.lightpit.viewmodel.NavMenu |
30 import de.uapcore.lightpit.viewmodel.View |
31 import de.uapcore.lightpit.viewmodel.View |
31 import jakarta.servlet.http.HttpServletRequest |
32 import jakarta.servlet.http.HttpServletRequest |
32 import jakarta.servlet.http.HttpServletResponse |
33 import jakarta.servlet.http.HttpServletResponse |
33 import jakarta.servlet.http.HttpSession |
34 import jakarta.servlet.http.HttpSession |
36 import java.sql.Date as SqlDate |
37 import java.sql.Date as SqlDate |
37 |
38 |
38 typealias MappingMethod = (HttpRequest, DataAccessObject) -> Unit |
39 typealias MappingMethod = (HttpRequest, DataAccessObject) -> Unit |
39 typealias PathParameters = Map<String, String> |
40 typealias PathParameters = Map<String, String> |
40 |
41 |
|
42 sealed class OptionalPathInfo<in T : HasNode>(info: T) { |
|
43 class Specific<T: HasNode>(val elem: T) : OptionalPathInfo<T>(elem) |
|
44 data object All : OptionalPathInfo<HasNode>(object : HasNode { override val node = "-"}) |
|
45 data object None : OptionalPathInfo<HasNode>(object : HasNode { override val node = "~"}) |
|
46 data object NotFound : OptionalPathInfo<HasNode>(object : HasNode { override val node = ""}) |
|
47 val node = info.node |
|
48 } |
|
49 |
41 sealed interface ValidationResult<T> |
50 sealed interface ValidationResult<T> |
42 class ValidationError<T>(val message: String): ValidationResult<T> |
51 class ValidationError<T>(val message: String): ValidationResult<T> |
43 class ValidatedValue<T>(val result: T): ValidationResult<T> |
52 class ValidatedValue<T>(val result: T): ValidationResult<T> |
44 |
53 |
45 class HttpRequest( |
54 class HttpRequest( |
168 defaultValue |
177 defaultValue |
169 } |
178 } |
170 is ValidatedValue -> { |
179 is ValidatedValue -> { |
171 result.result |
180 result.result |
172 } |
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 |
|
186 fun <T : HasNode> lookupPathParam(paramName: String, list: List<T>): OptionalPathInfo<T> { |
|
187 return when (val node = this.pathParams[paramName]) { |
|
188 null -> OptionalPathInfo.All |
|
189 "-" -> OptionalPathInfo.All |
|
190 "~" -> OptionalPathInfo.None |
|
191 else -> list.find { it.node == node } |
|
192 ?.let { OptionalPathInfo.Specific(it) } |
|
193 ?: OptionalPathInfo.NotFound |
173 } |
194 } |
174 } |
195 } |
175 |
196 |
176 val body: String by lazy { |
197 val body: String by lazy { |
177 request.reader.lineSequence().joinToString("\n") |
198 request.reader.lineSequence().joinToString("\n") |