Add real-time water temperature backend (Ūdens), fetch-on-demand like warnings
This commit is contained in:
@@ -6,7 +6,7 @@ import com.comcast.ip4s.IpLiteralSyntax
|
||||
import data.DataService
|
||||
import db.PostgresService
|
||||
import fetch.csv.FileNameService
|
||||
import fetch.lvgmc.FetchService
|
||||
import fetch.lvgmc.{FetchService, WaterTemperatureService}
|
||||
import fetch.warnings.WarningService
|
||||
import fs2.io.file.{Files, Path}
|
||||
import server.ValidateRoutes.{AggFieldList, AggKey, CityList, DateTimeRange, Granularity, ValidateDate, ValidateDateTime, ValidateInt, ValidateMonths, ValidateZonedDateTime}
|
||||
@@ -34,14 +34,14 @@ import scala.concurrent.duration.DurationInt
|
||||
|
||||
|
||||
object Server {
|
||||
def of(postgresService: PostgresService, dataService: DataService, fetch: FetchService, warnings: WarningService): IO[Server] = {
|
||||
def of(postgresService: PostgresService, dataService: DataService, fetch: FetchService, warnings: WarningService, waterTemperatures: WaterTemperatureService): IO[Server] = {
|
||||
Slf4jLogger.create[IO].map {
|
||||
new Server(postgresService, dataService, fetch, warnings, _)
|
||||
new Server(postgresService, dataService, fetch, warnings, waterTemperatures, _)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Server(postgresService: PostgresService, dataService: DataService, fetch: FetchService, warnings: WarningService, log: Logger[IO]) {
|
||||
class Server(postgresService: PostgresService, dataService: DataService, fetch: FetchService, warnings: WarningService, waterTemperatures: WaterTemperatureService, log: Logger[IO]) {
|
||||
private case class ResponseWrapper(result: Map[String, Option[Aggregate.AggregateValue]], query: UserQuery)
|
||||
private case class LatestTemperature(city: String, observedAt: String, value: Option[Double])
|
||||
|
||||
@@ -54,6 +54,14 @@ class Server(postgresService: PostgresService, dataService: DataService, fetch:
|
||||
ServiceUnavailable("LVĢMC brīdinājumu dati pašlaik nav pieejami")
|
||||
}
|
||||
|
||||
case GET -> Root / "water-temperatures" =>
|
||||
waterTemperatures.fetchWaterTemperatures
|
||||
.flatMap(result => Ok(result.asJson))
|
||||
.handleErrorWith { error =>
|
||||
log.error(error)("Unable to load LVĢMC water temperatures") *>
|
||||
ServiceUnavailable("Ūdens temperatūras dati pašlaik nav pieejami")
|
||||
}
|
||||
|
||||
// http://0.0.0.0:8080/api/show/lvgmc-forecast/Latvija_LTV_pilsetas_tekosa_dn.csv
|
||||
case GET -> Root / "show" / "lvgmc-forecast" / fileName =>
|
||||
fetch.fetchFile(fileName).flatMap(bytes =>
|
||||
|
||||
Reference in New Issue
Block a user