diff --git a/build.sbt b/build.sbt index 6364d9e..d857e70 100644 --- a/build.sbt +++ b/build.sbt @@ -31,7 +31,7 @@ ThisBuild / organization := "app.softnetwork" name := "payment" -ThisBuild / version := "0.4.1" +ThisBuild / version := "0.4.2" ThisBuild / scalaVersion := "2.12.15" diff --git a/core/src/main/scala/app/softnetwork/payment/launch/PaymentRoutes.scala b/core/src/main/scala/app/softnetwork/payment/launch/PaymentRoutes.scala index 6e3088e..21acc9c 100644 --- a/core/src/main/scala/app/softnetwork/payment/launch/PaymentRoutes.scala +++ b/core/src/main/scala/app/softnetwork/payment/launch/PaymentRoutes.scala @@ -1,8 +1,7 @@ package app.softnetwork.payment.launch import akka.actor.typed.ActorSystem -import akka.http.scaladsl.server.Route -import app.softnetwork.api.server.ApiRoutes +import app.softnetwork.api.server.{ApiRoute, ApiRoutes} import app.softnetwork.payment.serialization.paymentFormats import app.softnetwork.payment.service.GenericPaymentService import app.softnetwork.persistence.schema.SchemaProvider @@ -17,6 +16,10 @@ trait PaymentRoutes extends ApiRoutes with PaymentGuardian { _: SchemaProvider = def paymentService: ActorSystem[_] => GenericPaymentService - override def apiRoutes(system: ActorSystem[_]): Route = paymentService(system).route + override def apiRoutes: ActorSystem[_] => List[ApiRoute] = + system => + List( + paymentService(system) + ) } diff --git a/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentEndpoints.scala b/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentEndpoints.scala index bb1a357..feead6d 100644 --- a/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentEndpoints.scala +++ b/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentEndpoints.scala @@ -1,6 +1,5 @@ package app.softnetwork.payment.service -import akka.http.scaladsl.server.Route import app.softnetwork.payment.handlers.GenericPaymentHandler import app.softnetwork.payment.message.PaymentMessages._ import app.softnetwork.payment.model._ @@ -57,7 +56,6 @@ trait GenericPaymentEndpoints hooks ) - lazy val route: Route = apiRoute } case class UploadDocument(pages: Part[Array[Byte]]) { //TODO pages may include multiple parts diff --git a/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentService.scala b/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentService.scala index f26402a..1d40880 100644 --- a/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentService.scala +++ b/core/src/main/scala/app/softnetwork/payment/service/GenericPaymentService.scala @@ -36,7 +36,8 @@ trait GenericPaymentService with DefaultComplete with Json4sSupport with StrictLogging - with BasicPaymentService { _: GenericPaymentHandler => + with BasicPaymentService + with ApiRoute { _: GenericPaymentHandler => implicit def serialization: Serialization.type = jackson.Serialization diff --git a/mangopay/api/src/main/scala/app/softnetwork/payment/api/BasicServiceEndpoint.scala b/mangopay/api/src/main/scala/app/softnetwork/payment/api/BasicServiceEndpoint.scala index 63aa911..48fc849 100644 --- a/mangopay/api/src/main/scala/app/softnetwork/payment/api/BasicServiceEndpoint.scala +++ b/mangopay/api/src/main/scala/app/softnetwork/payment/api/BasicServiceEndpoint.scala @@ -1,5 +1,6 @@ package app.softnetwork.payment.api +import akka.actor.typed.ActorSystem import app.softnetwork.api.server.ApiEndpoint import app.softnetwork.session.service.SessionEndpoints import com.softwaremill.session.{ @@ -15,7 +16,7 @@ import sttp.tapir._ import sttp.tapir.model.UsernamePassword import sttp.tapir.server.{PartialServerEndpointWithSecurityOutput, ServerEndpoint} -import scala.concurrent.Future +import scala.concurrent.{ExecutionContext, Future} import scala.language.implicitConversions trait BasicServiceEndpoint extends ApiEndpoint with TapirEndpoints { @@ -63,8 +64,9 @@ trait BasicServiceEndpoint extends ApiEndpoint with TapirEndpoints { } object BasicServiceEndpoint { - def apply(_sessionEndpoints: SessionEndpoints): BasicServiceEndpoint = + def apply(_system: ActorSystem[_], _sessionEndpoints: SessionEndpoints): BasicServiceEndpoint = new BasicServiceEndpoint { override def sessionEndpoints: SessionEndpoints = _sessionEndpoints + override implicit def ec: ExecutionContext = _system.executionContext } } diff --git a/mangopay/api/src/main/scala/app/softnetwork/payment/api/MangoPayWithSchedulerRoutes.scala b/mangopay/api/src/main/scala/app/softnetwork/payment/api/MangoPayWithSchedulerRoutes.scala index e84588b..f3f31f8 100644 --- a/mangopay/api/src/main/scala/app/softnetwork/payment/api/MangoPayWithSchedulerRoutes.scala +++ b/mangopay/api/src/main/scala/app/softnetwork/payment/api/MangoPayWithSchedulerRoutes.scala @@ -1,11 +1,11 @@ package app.softnetwork.payment.api import akka.actor.typed.ActorSystem -import akka.http.scaladsl.server.Route +import app.softnetwork.api.server.ApiRoute import app.softnetwork.persistence.schema.SchemaProvider import app.softnetwork.scheduler.launch.SchedulerRoutes trait MangoPayWithSchedulerRoutes extends SchedulerRoutes with MangoPayRoutes { _: SchemaProvider => - override def apiRoutes(system: ActorSystem[_]): Route = - super.apiRoutes(system) ~ schedulerService(system).route + override def apiRoutes: ActorSystem[_] => List[ApiRoute] = + system => super.apiRoutes(system) :+ schedulerService(system) } diff --git a/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala b/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala index c438c08..ca8760c 100644 --- a/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala +++ b/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala @@ -2,9 +2,9 @@ package app.softnetwork.sbt.build object Versions { - val genericPersistence = "0.3.4" + val genericPersistence = "0.3.5" - val scheduler = "0.3.4" + val scheduler = "0.3.5" val scalatest = "3.1.1" } diff --git a/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentEndpointsTestKit.scala b/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentEndpointsTestKit.scala index d9b9f89..d4f5a3d 100644 --- a/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentEndpointsTestKit.scala +++ b/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentEndpointsTestKit.scala @@ -5,9 +5,11 @@ import app.softnetwork.api.server.ApiEndpoint import app.softnetwork.payment.launch.PaymentEndpoints import app.softnetwork.payment.service.{GenericPaymentEndpoints, MockPaymentEndpoints} import app.softnetwork.persistence.schema.SchemaProvider -import app.softnetwork.session.scalatest.SessionEndpointsRoute +import app.softnetwork.session.scalatest.SessionEndpointsRoutes +import com.softwaremill.session.CsrfCheck -trait PaymentEndpointsTestKit extends PaymentEndpoints { _: SchemaProvider => +trait PaymentEndpointsTestKit extends PaymentEndpoints with SessionEndpointsRoutes { + _: SchemaProvider with CsrfCheck => override def paymentEndpoints: ActorSystem[_] => GenericPaymentEndpoints = system => MockPaymentEndpoints(system, sessionEndpoints(system)) @@ -15,7 +17,7 @@ trait PaymentEndpointsTestKit extends PaymentEndpoints { _: SchemaProvider => override def endpoints: ActorSystem[_] => List[ApiEndpoint] = system => List( - SessionEndpointsRoute(system, sessionEndpoints(system)), + sessionServiceEndpoints(system), paymentEndpoints(system) ) diff --git a/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentRoutesTestKit.scala b/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentRoutesTestKit.scala index c562bb7..8b3e5e0 100644 --- a/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentRoutesTestKit.scala +++ b/testkit/src/main/scala/app/softnetwork/payment/scalatest/PaymentRoutesTestKit.scala @@ -1,19 +1,22 @@ package app.softnetwork.payment.scalatest import akka.actor.typed.ActorSystem -import akka.http.scaladsl.server.Route +import app.softnetwork.api.server.ApiRoute import app.softnetwork.payment.launch.PaymentRoutes import app.softnetwork.payment.service.{GenericPaymentService, MockPaymentService} import app.softnetwork.persistence.schema.SchemaProvider -import app.softnetwork.session.scalatest.SessionServiceRoute +import app.softnetwork.session.scalatest.SessionServiceRoutes -trait PaymentRoutesTestKit extends PaymentRoutes { _: SchemaProvider => +trait PaymentRoutesTestKit extends PaymentRoutes with SessionServiceRoutes { _: SchemaProvider => override def paymentService: ActorSystem[_] => GenericPaymentService = system => MockPaymentService(system, sessionService(system)) - override def apiRoutes(system: ActorSystem[_]): Route = - paymentService(system).route ~ - SessionServiceRoute(sessionService(system)).route + override def apiRoutes: ActorSystem[_] => List[ApiRoute] = + system => + List( + paymentService(system), + sessionServiceRoute(system) + ) }