You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Routes.scala 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package de.codingchallenge
  2. import akka.actor.ActorSystem
  3. import akka.http.scaladsl.model._
  4. import akka.http.scaladsl.server.Directives.{pathPrefix, _}
  5. import akka.http.scaladsl.server._
  6. import akka.stream.{ActorMaterializer, Materializer}
  7. import akka.util.ByteString
  8. import de.codingchallenge.configuration.Environment
  9. import com.typesafe.scalalogging.LazyLogging
  10. import de.codingchallenge.services.ArticleExportService
  11. class Routes(articleExportService: ArticleExportService,
  12. actorSystem: ActorSystem,
  13. actorMaterializer: ActorMaterializer,
  14. environment: Environment)
  15. extends LazyLogging {
  16. implicit val as: ActorSystem = actorSystem
  17. implicit val mat: Materializer = actorMaterializer
  18. var on: Boolean = true
  19. val serviceRoutes: Route =
  20. pathSuffix("readinessProbe") {
  21. get {
  22. if(on) {
  23. complete {
  24. HttpEntity(ContentTypes.`application/json`, ByteString(de.codingchallenge.BuildInfo.toJson))
  25. }
  26. } else {
  27. complete(StatusCodes.ServiceUnavailable)
  28. }
  29. }
  30. } ~ path("health") {
  31. get {
  32. complete {
  33. HttpEntity(ContentTypes.`application/json`, ByteString(de.codingchallenge.BuildInfo.toJson))
  34. }
  35. }
  36. }
  37. val exportRoute: Route =
  38. path("articles") {
  39. get {
  40. onSuccess(articleExportService.exportArticles()) { res =>
  41. complete(res)
  42. }
  43. }
  44. }
  45. val routes: Route =
  46. pathPrefix("inoio-coding-challenge") {
  47. serviceRoutes
  48. } ~ pathPrefix("inoio-coding-challenge" / "export") {
  49. exportRoute
  50. } ~ serviceRoutes
  51. val rejectRoute: Route = reject
  52. def shutdown(): Unit = on = false
  53. }