Commit 934962ef authored by Andreas Muttscheller's avatar Andreas Muttscheller

addStation with station name instead of eva

parent 5516887f
......@@ -5,7 +5,6 @@ import com.amazonaws.services.dynamodbv2.{AmazonDynamoDB, AmazonDynamoDBClientBu
import de.codecentric.amuttsch.bahndelayinfo.aws
import org.json4s._
import org.json4s.native.JsonMethods._
import org.json4s.prefs.EmptyValueStrategy
import org.json4s.native.Serialization.write
import scala.io.Source
......
......@@ -198,6 +198,8 @@ class APISlackBotEventHandlerWorker {
search("timetables") bool BoolQuery(
must = Seq(
MatchQuery("station", station),
),
should = Seq(
MatchQuery("train", searchString),
MatchQuery("pathTo", searchString),
)
......@@ -354,14 +356,23 @@ class APISlackBotEventHandlerWorker {
asUser = Some(true))
}
private def addStation(message: Message, eva: String): Unit = {
val lambdaClient = AWSLambdaClientBuilder.defaultClient
val rq = new InvokeRequest()
.withFunctionName(aws.getLambdaFunctionName("ScheduledPlannedTimetableFetchWorker"))
.withPayload(write(List(eva)))
rq.setInvocationType(InvocationType.Event)
lambdaClient.invoke(rq)
slackApiClient.postChatMessage(message.channel, s"Added station $eva!", asUser = Some(true))
private def addStation(message: Message, station: String): Unit = {
getEitherStationOrStations(station) match {
case Right(s) =>
val lambdaClient = AWSLambdaClientBuilder.defaultClient
val rq = new InvokeRequest()
.withFunctionName(aws.getLambdaFunctionName("ScheduledPlannedTimetableFetchWorker"))
.withPayload(write(List(s.eva.toString)))
rq.setInvocationType(InvocationType.Event)
lambdaClient.invoke(rq)
slackApiClient.postChatMessage(message.channel, s"Added station ${s.name}!", asUser = Some(true))
case Left(s) =>
slackApiClient.postChatMessage(
message.channel,
"Please specify station:\n" + s.map(_.name).mkString("\n"),
asUser = Some(true)
)
}
}
def getOrCreateUser(message: Message): SlackUser = {
......
......@@ -87,6 +87,6 @@ class ScheduledPlannedTimetableFetchWorker {
object ScheduledPlannedTimetableFetchWorker extends App {
val sptfw = new ScheduledPlannedTimetableFetchWorker()
val evas = new java.util.LinkedList[String]()
evas.add("8001377")
evas.add("8000105")
sptfw.handleRequest(evas, null)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment