Skip to content

Commit

Permalink
some more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof committed Jun 15, 2022
1 parent 4bbd42b commit 1191ed8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package akka.http.scaladsl.server.util
/**
* Constructor for instances of type `R` which can be created from a tuple of type `T`.
*/
@FunctionalInterface
trait ConstructFromTuple[T, R] extends (T => R)

object ConstructFromTuple extends ConstructFromTupleInstances
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ package docs.http.scaladsl
import akka.event.LoggingAdapter
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.{ Directive, Route }
import akka.http.scaladsl.server.directives.FormFieldDirectives.FieldSpec
import akka.http.scaladsl.server.util.ConstructFromTuple
import akka.testkit.TestActors

import scala.annotation.nowarn
import docs.CompileOnlySpec

Expand Down Expand Up @@ -262,8 +265,7 @@ class HttpServerExampleSpec extends AnyWordSpec with Matchers
pathEnd {
concat(
put {
// form extraction from multipart or www-url-encoded forms
formFields("email", "total".as[Money]).as(Order) { (order: Order) =>
formFields("email", "total".as[Money]).as(Order.apply _) { (order: Order) =>
complete {
// complete with serialized Future result
(myDbActor ? Update(order)).mapTo[TransactionResult]
Expand All @@ -285,7 +287,7 @@ class HttpServerExampleSpec extends AnyWordSpec with Matchers
get {
// parameters to case class extraction
parameters("size".as[Int], "color".optional, "dangerous".withDefault("no"))
.as(OrderItem) { (orderItem: OrderItem) =>
.as(OrderItem.apply _) { (orderItem: OrderItem) =>
// ... route using case class instance created from
// required and optional query parameters
complete("") // #hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ object SprayJsonExample {
orders.find(o => o.id == itemId)
}
def saveOrder(order: Order): Future[Done] = {
orders = order match {
case Order(items) => items ::: orders
case _ => orders
}
orders = order.items ::: orders
Future { Done }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CaseClassExtractionExamplesSpec extends RoutingSpec with Inside {
"example 4 test" in {
val route =
(path("color" / Segment) &
parameters("r".as[Int], "g".as[Int], "b".as[Int])).as(Color) { color =>
parameters("r".as[Int], "g".as[Int], "b".as[Int])).as(Color.apply _) { color =>
// ... route working with the `color` instance
doSomethingWith(color) // #hide
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class JsonStreamingExamplesSpec extends RoutingSpec with CompileOnlySpec {

Post("/metrics", entity = data) ~> route ~> check {
status should ===(StatusCodes.OK)
responseAs[String] should ===("""{"msg":"Total metrics received: 2"}""")
responseAs[String] should ===("Total metrics received: 2")
}

// the FramingWithContentType will reject any content type that it does not understand:
Expand Down

0 comments on commit 1191ed8

Please sign in to comment.