This is an automated email from the ASF dual-hosted git repository. fanningpj pushed a commit to branch createStation in repository https://gitbox.apache.org/repos/asf/incubator-pekko-samples.git
commit 6813a94c0dca08d5dc754ca2fb522e636ea346f3 Author: Arnout Engelen <[email protected]> AuthorDate: Fri Nov 1 15:58:08 2019 +0100 Station creation --- .../src/main/scala/sample/sharding/WeatherRoutes.scala | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/akka-sample-sharding-scala/src/main/scala/sample/sharding/WeatherRoutes.scala b/akka-sample-sharding-scala/src/main/scala/sample/sharding/WeatherRoutes.scala index 70eb21f..0bc274e 100644 --- a/akka-sample-sharding-scala/src/main/scala/sample/sharding/WeatherRoutes.scala +++ b/akka-sample-sharding-scala/src/main/scala/sample/sharding/WeatherRoutes.scala @@ -34,11 +34,19 @@ class WeatherRoutes(guardian: ActorRef[Guardian.Command])(implicit system: Actor } }, pathPrefix("weather-stations") { - get { - onComplete((guardian ? GetWeatherStations).mapTo[WeatherStations]) { - case Success(value) => complete(s"The result was $value") - case Failure(e) => complete((StatusCodes.InternalServerError, s"An error occurred: ${e.getMessage}")) + concat( + get { + onComplete((guardian ? GetWeatherStations).mapTo[WeatherStations]) { + case Success(value) => complete(s"The result was $value") + case Failure(e) => complete((StatusCodes.InternalServerError, s"An error occurred: ${e.getMessage}")) + } + }, + // REST-wise we should expect PUT here, but let's be lenient and also accept POST: + (path(IntNumber) & (put | post)) { sid => + // This command is 'fire and forget' + guardian ! AddWeatherStation(sid) + complete(StatusCodes.Accepted) } - } + ) }) } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
