Improve help json response

This commit is contained in:
Guntis Smaukstelis
2023-05-03 22:37:05 +03:00
parent 9fbc6f9f37
commit 0227ac3b43
3 changed files with 16 additions and 3 deletions
+1 -1
View File
@@ -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
}
+4
View File
@@ -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")
+11 -2
View File
@@ -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