Advertisement
trishLEX

Untitled

Oct 29th, 2017
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.88 KB | None | 0 0
  1.     val route =
  2.       pathSingleSlash {
  3.         complete("root")
  4.       } ~
  5.         pathPrefix("digit") {
  6.           pathEndOrSingleSlash {
  7.             complete("here a digit")
  8.           } ~
  9.             path(IntNumber) { int =>
  10.               complete(if (int % 2 == 0) "even digit" else "odd digit")
  11.             }
  12.         }
  13.  
  14.  
  15. вот так было в метакомерсе
  16.  
  17.  
  18.   val photos: Route = pathPrefix("photos") {
  19.  
  20.     path("get") {
  21.       (get & parameters("sessionId") & extractExecutionContext) { (sessionId, ec) =>
  22.         implicit val _ec = ec
  23.         extractAuthContext { auth =>
  24.           log(auth, None) {
  25.             val filter = PhotoFilter(sessionIds = List(sessionId))
  26.             onSuccess(LoadPhotosStream(filter).runWith(Sink.seq[Photo]).map(_.toList)) {
  27.               case Nil => complete(404 -> ApiResponse(404, message = Some("session not found")))
  28.               case result => complete(result)
  29.             }
  30.           }
  31.         }
  32.       } ~
  33.       (post & extractExecutionContext & extractStrictEntity(10.seconds)) { (ec, entity) =>
  34.         implicit val _ec = ec
  35.         extractAuthContext { auth =>
  36.           log(auth, None) {
  37.             val f = for {
  38.               req <- entity.convertTo[PhotosRequest]
  39.               result <- LoadPhotosStream(PhotoFilter(ids = req.ids)).runWith(Sink.seq[Photo]).map(_.toList)
  40.             } yield result
  41.  
  42.             onSuccess(f) {
  43.               case Nil => complete(404 -> ApiResponse(404, message = Some("photos not found")))
  44.               case result => complete(result)
  45.             }
  46.           }
  47.         }
  48.       }
  49.     } ~
  50.     path("add") {
  51.       post {
  52.         request[List[Photo], String] { case (auth, rc, ec) =>
  53.             implicit val _ec = ec
  54.             FutureUtil.serialise(rc)(photo => photoStorage ? SavePhoto(photo, refresh = true, Progress.None, auth)).map(_ => "ok")
  55.         }
  56.       }
  57.     }
  58.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement