Change data structure for meteo adding AggregateKey and AggregateValue

This commit is contained in:
Guntis Smaukstelis
2023-04-26 16:37:11 +03:00
parent 3cd223dddd
commit 1bf41973a7
7 changed files with 161 additions and 62 deletions
+4 -3
View File
@@ -4,9 +4,9 @@ import cats.effect._
import cats.implicits.toTraverseOps
import db.DBService
import fetch.FetchService
import parse.{MeteoData, Parser}
import parse.{AggregateKey, AggregateValue, Parser}
import server.ValidateRoutes.{Aggregate, CityList, DateTimeRange, ValidDate}
import io.circe.{Json, Printer}
import io.circe.{Encoder, Json, Printer}
import org.http4s._
import org.http4s.dsl.io._
import org.http4s.server.Router
@@ -31,6 +31,7 @@ object Server extends IOApp {
DBService.getInRange(from, to)
.map(Parser.queryData(_, cities, aggregate))
.flatMap(result => Ok(result.asJson.pretty))
// .flatMap(result => Ok("make json encoder"))
// http://localhost:3000/fetch/date/20230423
case GET -> Root / "fetch" / "date" / ValidDate(date) =>
@@ -64,7 +65,7 @@ object Server extends IOApp {
// http://localhost:3000/help
case GET -> Root / "help" =>
Ok(MeteoData.getKeys.asJson.pretty)
Ok(AggregateKey.getKeys.asJson.pretty)
}
private val httpApp = Router("/" -> appRoutes).orNotFound
+3 -3
View File
@@ -1,6 +1,6 @@
package server
import parse.{AggregateMeteo, Meteo}
import parse.AggregateKey
import java.time.{LocalDate, LocalDateTime}
import java.time.format.DateTimeFormatter
@@ -36,8 +36,8 @@ object ValidateRoutes {
}
object Aggregate {
def unapply(str: String): Option[AggregateMeteo] = {
Meteo.stringToAggregateParam(str)
def unapply(str: String): Option[AggregateKey] = {
AggregateKey.stringToAggregateParam(str)
}
}
}