From 0227ac3b4336d88b2add8cea1618a1e97b7989af Mon Sep 17 00:00:00 2001 From: Guntis Smaukstelis Date: Wed, 3 May 2023 22:37:05 +0300 Subject: [PATCH] Improve help json response --- src/main/scala/parse/Aggregate.scala | 2 +- src/main/scala/parse/WeatherData.scala | 4 ++++ src/main/scala/server/Server.scala | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/scala/parse/Aggregate.scala b/src/main/scala/parse/Aggregate.scala index ddb1267..f83eb99 100644 --- a/src/main/scala/parse/Aggregate.scala +++ b/src/main/scala/parse/Aggregate.scala @@ -38,7 +38,7 @@ object Aggregate { val classSymbol = runtimeMirror.classSymbol(classOf[AggregateKey]) // Get all case classes that extend the AggregateKey trait - val keys = classSymbol.knownDirectSubclasses.map(_.name.toString).toList + val keys = classSymbol.knownDirectSubclasses.map(_.name.toString.toLowerCase).toList keys } diff --git a/src/main/scala/parse/WeatherData.scala b/src/main/scala/parse/WeatherData.scala index f11d2ed..59e707c 100644 --- a/src/main/scala/parse/WeatherData.scala +++ b/src/main/scala/parse/WeatherData.scala @@ -71,6 +71,10 @@ object WeatherData { def getDoubleParamCount: Int = { getParamCount - 1 // minus one because 'phenomena' List[String] not Double } + + def getKeys: List[String] = { + WeatherData(None, None, None, None, None, None, None, None, None, None, None, None, None, List.empty).productElementNames.toList + } } //val cityList: List[String] = List("Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni", "Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni") diff --git a/src/main/scala/server/Server.scala b/src/main/scala/server/Server.scala index 7a9b31f..9523600 100644 --- a/src/main/scala/server/Server.scala +++ b/src/main/scala/server/Server.scala @@ -4,7 +4,7 @@ import cats.effect._ import cats.implicits.toTraverseOps import db.DBService import fetch.FetchService -import parse.Parser +import parse.{Parser, WeatherData} import server.ValidateRoutes.{AggKey, CityList, DateTimeRange, ValidDate} import io.circe.{Encoder, Json, Printer} import org.http4s._ @@ -70,7 +70,16 @@ object Server extends IOApp { // http://localhost:3000/help case GET -> Root / "help" => - Ok(AggregateKey.getKeys.asJson.pretty) + Ok(Json.obj( + "aggregate fields" -> WeatherData.getKeys.asJson, + "aggregate keys" -> AggregateKey.getKeys.asJson, + "example urls" -> List( + "http://localhost:3000/query/20230414_2200-20230501_1230/Liepāja,Rēzekne/tempMax/max", + "http://localhost:3000/fetch/date/20230423", + "http://localhost:3000/show/all_dates", + "http://localhost:3000/show/date/20230423", + ).asJson, + ).pretty) } private val httpApp = Router("/" -> appRoutes).orNotFound