src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt

changeset 225
87328572e36f
parent 210
37fbdcb422b7
child 227
f0ede8046b59
     1.1 --- a/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt	Wed Aug 18 12:47:32 2021 +0200
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt	Wed Aug 18 14:57:45 2021 +0200
     1.3 @@ -33,6 +33,7 @@
     1.4  import javax.servlet.http.HttpServletResponse
     1.5  import javax.servlet.http.HttpSession
     1.6  import kotlin.math.min
     1.7 +import java.sql.Date as SqlDate
     1.8  
     1.9  typealias MappingMethod = (HttpRequest, DataAccessObject) -> Unit
    1.10  typealias PathParameters = Map<String, String>
    1.11 @@ -289,3 +290,18 @@
    1.12      }
    1.13  }
    1.14  
    1.15 +// <editor-fold desc="Validators">
    1.16 +
    1.17 +fun dateOptValidator(input: String?): ValidationResult<SqlDate?> {
    1.18 +    return if (input.isNullOrBlank()) {
    1.19 +        ValidatedValue(null)
    1.20 +    } else {
    1.21 +        try {
    1.22 +            ValidatedValue(SqlDate.valueOf(input))
    1.23 +        } catch (ignored: IllegalArgumentException) {
    1.24 +            ValidationError("validation.date.format")
    1.25 +        }
    1.26 +    }
    1.27 +}
    1.28 +
    1.29 +// </editor-fold>

mercurial