Skip to content

Commit

Permalink
chore: update play to 2.9-RC
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeQuadrat committed Sep 26, 2023
1 parent 8962832 commit 136ab4b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 30 deletions.
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sbt._

object Dependencies {

val playVersion = "2.8.20"
val playVersion = "2.9.0-RC2"
val typesafePlay = "com.typesafe.play" %% "play" % playVersion

val scalaVersion = "2.13.12"
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ addSbtPlugin("com.codecommit" %% "sbt-github-packages" % "0.5.3")
addSbtPlugin("org.wartremover" %% "sbt-wartremover" % "3.1.4")
addSbtPlugin("org.scalameta" %% "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.disneystreaming.smithy4s" %% "smithy4s-sbt-codegen" % "0.17.19")
addSbtPlugin("com.typesafe.play" %% "sbt-plugin" % "2.8.19")
addSbtPlugin("com.typesafe.play" %% "sbt-plugin" % "2.9.0-RC2")
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "2.0.9")

ThisBuild / dependencyOverrides ++= Seq(
Expand Down
60 changes: 38 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ smithy4play is a routing gernator for the play2 framework based on [smithy4s](ht
plugins.sbt

```scala
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.15")
addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.5.3")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.*.*")
addSbtPlugin("com.codecommit" % "sbt-github-packages" % "0.*.*")
addSbtPlugin(
"com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.14.2"
"com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % "0.*.*"
)
```

Expand Down Expand Up @@ -57,26 +57,10 @@ class PreviewController @Inject(
```

**Client**
- create Client Class
- extend the Client with the generated Scala Type and smithy4play Type ClientResponse
- implement a smithy4play RequestClient that handles the request

```scala
class PreviewControllerClient(
additionalHeaders: Map[String, Seq[String]] = Map.empty,
baseUri: String = "/")
(implicit ec: ExecutionContext, client: RequestClient)
extends PreviewControllerService[ClientResponse] {

val smithyPlayClient = new SmithyPlayClient(baseUri, TestControllerService.service)

override def preview(): ClientResponse[SimpleTestResponse] =
smithyPlayClient.send(PreviewControllerServiceGen.Preview(), Some(additionalHeaders))
}
```
now the methods from the client can be accessed like this:
- import the EnhancedGenericAPIClient
```scala
val previewControllerClient = new PreviewControllerClient()
import de.innfactory.smithy4play.client.GenericAPIClient.EnhancedGenericAPIClient
val previewControllerClient = PreviewControllerServiceGen.withClient(FakeRequestClient)
previewControllerClient.preview()
```
For a further examples take a look at the smithy4playTest project.
Expand Down Expand Up @@ -125,6 +109,38 @@ class ApiRouter @Inject()(
-> / api.ApiRouter
```

## Middlewares

If you want Middlewares that run before the endpoint logic follow these steps:

- Implement Middlewares
```scala
@Singleton
class ExampleMiddleware @Inject() (implicit
executionContext: ExecutionContext
) extends MiddlewareBase {

override protected def skipMiddleware(r: RoutingContext): Boolean = false

override def logic(
r: RoutingContext,
next: RoutingContext => RouteResult[EndpointResult]
): RouteResult[EndpointResult] =
next(r)
}
```
- Implement a MiddlewareRegistry and register your middlewares
```scala
class MiddlewareRegistry @Inject() (
disableAbleMiddleware: DisableAbleMiddleware,
testMiddlewareImpl: TestMiddlewareImpl,
validateAuthMiddleware: ValidateAuthMiddleware
) extends MiddlewareRegistryBase {
override val middlewares: Seq[MiddlewareBase] = Seq(ExampleMiddleware)
}
```


## Credits:

[innFactory ❤️ Open Source](https://innfactory.de)
2 changes: 1 addition & 1 deletion smithy4playTest/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ play.filters.enabled = []

smithy4play.autoRoutePackage = "controller"

play.http.secret.key = dkjfgherkgjerhgk
play.http.secret.key = dkjfgherkgjerhgkdkjfgherkgjerhgkdkjfgherkgjerhgkdkjfgherkgjerhgkdkjfgherkgjerhgkdkjfgherkgjerhgkdkjfgherkgjerhgkdkjfgherkgjerhgk
10 changes: 5 additions & 5 deletions smithy4playTest/test/TestControllerTest.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import controller.models.TestError
import de.innfactory.smithy4play.CodecUtils
import de.innfactory.smithy4play.client.GenericAPIClient.EnhancedGenericAPIClient
import de.innfactory.smithy4play.client.{ RequestClient, SmithyClientResponse }
import de.innfactory.smithy4play.client.{RequestClient, SmithyClientResponse}
import de.innfactory.smithy4play.client.SmithyPlayTestUtils._
import de.innfactory.smithy4play.compliancetests.ComplianceClient
import models.TestJson
import org.scalatestplus.play.{ BaseOneAppPerSuite, FakeApplicationFactory, PlaySpec }
import org.scalatestplus.play.{BaseOneAppPerSuite, FakeApplicationFactory, PlaySpec}
import play.api.Application
import play.api.Play.materializer
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.{ Json, OWrites }
import play.api.mvc.{ AnyContentAsEmpty, Result }
import play.api.libs.json.{Json, OWrites}
import play.api.mvc.{AnyContentAsEmpty, Result}
import play.api.test.FakeRequest
import play.api.test.Helpers._
import testDefinitions.test.{ SimpleTestResponse, TestControllerServiceGen, TestRequestBody }
import testDefinitions.test.{SimpleTestResponse, TestControllerServiceGen, TestRequestBody}
import smithy4s.ByteArray

import java.io.File
Expand Down

0 comments on commit 136ab4b

Please sign in to comment.