Advertisement
trishLEX

PhotosRoute

Jul 5th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.80 KB | None | 0 0
  1. package ru.metahouse.prices.api.v1
  2.  
  3. import akka.http.scaladsl.server.Directives._
  4. import akka.http.scaladsl.server.{RequestContext, Route}
  5. import ru.metahouse.commons.frontend.HttpUtils._
  6. import ru.metahouse.prices.HttpService
  7. import ru.metahouse.prices.model.Photo
  8.  
  9. import scala.concurrent.ExecutionContext
  10.  
  11.  
  12.  
  13. trait PhotosRoute {
  14.   this: HttpService =>
  15.  
  16.   val photos: Route = pathPrefix("photos") {
  17.     path("add") {
  18.  
  19.       post {
  20.         extractExecutionContext { implicit ec: ExecutionContext =>
  21.           extractRequestContext { rc: RequestContext =>
  22.             val request = rc.request.entity.convertTo[Photo]
  23.             val msg = if (request.value.isDefined) StatusCodes.OK else StatusCodes.InternalServerError
  24.             complete(msg)
  25.           }
  26.         }
  27.       }
  28.     }
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement