2023-04-25 20:11:49 +03:00
|
|
|
package server
|
|
|
|
|
|
2023-12-15 13:46:45 +02:00
|
|
|
import cats.data.NonEmptyList
|
2023-05-03 00:02:59 +03:00
|
|
|
import parse.Aggregate.AggregateKey
|
2023-12-24 23:54:16 +02:00
|
|
|
import parse.WeatherData
|
2023-04-25 20:11:49 +03:00
|
|
|
|
2025-01-31 14:56:59 +02:00
|
|
|
import java.time.{LocalDate, LocalDateTime, ZonedDateTime}
|
2023-04-25 20:11:49 +03:00
|
|
|
import java.time.format.DateTimeFormatter
|
2023-07-03 23:17:43 +03:00
|
|
|
import java.time.temporal.ChronoUnit
|
2023-04-25 20:11:49 +03:00
|
|
|
import scala.util.Try
|
|
|
|
|
|
|
|
|
|
object ValidateRoutes {
|
|
|
|
|
object DateTimeRange {
|
|
|
|
|
def unapply(str: String): Option[(LocalDateTime, LocalDateTime)] = {
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
|
|
|
|
|
str.split("-")
|
|
|
|
|
.toList
|
|
|
|
|
.map(str => Try(LocalDateTime.parse(str, formatter)).toOption) match {
|
|
|
|
|
case List(Some(from), Some(to)) => Some(from, to)
|
|
|
|
|
case _ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 15:36:30 +02:00
|
|
|
object ValidateDate {
|
2023-04-25 20:11:49 +03:00
|
|
|
def unapply(str: String): Option[LocalDate] = {
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd")
|
|
|
|
|
Try(LocalDate.parse(str, formatter)).toOption
|
|
|
|
|
}
|
2023-12-12 15:36:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object ValidateDateTime {
|
|
|
|
|
def unapply(str: String): Option[LocalDateTime] = {
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
|
|
|
|
|
Try(LocalDateTime.parse(str, formatter)).toOption
|
|
|
|
|
}
|
2023-04-25 20:11:49 +03:00
|
|
|
}
|
|
|
|
|
|
2025-01-31 14:56:59 +02:00
|
|
|
object ValidateZonedDateTime {
|
|
|
|
|
def unapply(str: String): Option[ZonedDateTime] = {
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ssZ")
|
|
|
|
|
Try(ZonedDateTime.parse(str, formatter)).toOption
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 16:22:15 +03:00
|
|
|
object ValidateMonths {
|
|
|
|
|
def unapply(str: String): Option[List[LocalDate]] = {
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd")
|
|
|
|
|
val monthList = str
|
|
|
|
|
.split(",")
|
|
|
|
|
.toList
|
|
|
|
|
.flatMap(str => Try(LocalDate.parse(str + "01", formatter)).toOption)
|
|
|
|
|
|
|
|
|
|
monthList match {
|
|
|
|
|
case Nil => None
|
|
|
|
|
case list => Some(list)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:11:49 +03:00
|
|
|
object CityList {
|
2023-12-15 13:46:45 +02:00
|
|
|
def unapply(str: String): Option[NonEmptyList[String]] = {
|
|
|
|
|
NonEmptyList.fromList(str.split(",").toList)
|
2023-04-25 20:11:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-24 23:54:16 +02:00
|
|
|
object AggFieldList {
|
|
|
|
|
def unapply(str: String): Option[NonEmptyList[String]] = {
|
|
|
|
|
val weatherFields = WeatherData.getKeys
|
|
|
|
|
val filteredList = str.split(",").toList.filter(weatherFields.contains)
|
|
|
|
|
NonEmptyList.fromList(filteredList)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 00:02:59 +03:00
|
|
|
object AggKey {
|
2023-04-26 16:37:11 +03:00
|
|
|
def unapply(str: String): Option[AggregateKey] = {
|
2023-05-03 00:02:59 +03:00
|
|
|
AggregateKey.fromString(str)
|
2023-04-25 20:11:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 23:17:43 +03:00
|
|
|
|
|
|
|
|
object Granularity {
|
|
|
|
|
def unapply(str: String): Option[ChronoUnit] = {
|
|
|
|
|
str match {
|
|
|
|
|
case "hour" => Some(ChronoUnit.HOURS)
|
|
|
|
|
case "day" => Some(ChronoUnit.DAYS)
|
|
|
|
|
case "month" => Some(ChronoUnit.MONTHS)
|
|
|
|
|
case "year" => Some(ChronoUnit.YEARS)
|
|
|
|
|
case _ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-03 23:33:28 +02:00
|
|
|
|
|
|
|
|
object ValidateInt {
|
|
|
|
|
def unapply(str: String): Option[Int] = {
|
|
|
|
|
Option(str.toInt)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-25 20:11:49 +03:00
|
|
|
}
|