Skip to content

Instantly share code, notes, and snippets.

View pjazdzewski1990's full-sized avatar

Patryk Jażdżewski pjazdzewski1990

View GitHub Profile
package io.scalac
import akka.actor.typed.{ActorRef, ActorSystem, Behavior}
import akka.actor.typed.scaladsl.{ActorContext, Behaviors}
import akka.actor.typed.scaladsl.Behaviors.Receive
import akka.util.Timeout
import scala.concurrent.duration._
import scala.concurrent.Future
import scala.util.Random
<!DOCTYPE html>
<html>
<style>
.outer {
position: absolute;
z-index: 9;
background-color: #f1f1f1;
text-align: center;
border: 1px solid #d3d3d3;
builder.setCommandHandler(
classOf[SaveRatio],
asJavaBiFunction
[SaveRatio, CommandContext[NotUsed], Persist[_ <: ExchangeEvent]](
(cmd: SaveRatio, ctx: CommandContext[NotUsed]) => {
ctx.thenPersist(
saveRatioToRatioChanged(cmd),
(t: ExchangeEvent) => ctx.reply(NotUsed)
)
}
object Implicits {
implicit def requestToServiceCallWithCompletedFuture[Req, Resp]
(reqFunc: Req => Resp): ServiceCall[Req, Resp] = {
new ServiceCall[Req, Resp] {
override def invoke(request: Req): CompletionStage[Resp] = {
completedFuture(reqFunc(request))
}
}
}
class MicroserviceExceptionSerializer extends ExceptionSerializer {
override def serialize(exception: Throwable,
accept: java.util.Collection[MessageProtocol])
: RawExceptionMessage = {
val mp = MessageProtocol.fromContentTypeHeader(Optional.empty())
val defaultMessage = new RawExceptionMessage(
TransportErrorCode.InternalServerError,
mp,
lazy val BigDecimalSerializer: PathParamSerializer[BigDecimal] =
com.lightbend.lagom.javadsl.api.deser.PathParamSerializers.required(
"BigDecimal",
(pathValue: String) => BigDecimal(pathValue),
(v: BigDecimal) => v.toString
)
trait ExchangeRatesService extends Service {
def getExchangeRate(fromUnit: String,
toUnit: String
): ServiceCall[NotUsed, ExchangeRatio]
def setExchangeRate(fromUnit: String,
toUnit: String
): ServiceCall[Rate, NotUsed]
trait CalculatorService extends Service {
def calculate(fromValue: BigDecimal,
fromUnit: String,
toUnit: String
): ServiceCall[NotUsed, CalculatedValue]
def descriptor(): Descriptor =
named("calculatorservice")
.`with`(
def descriptor(): Descriptor =
named("calculatorservice")
.`with`(
restCall(
Method.GET,
"/api/calculator/exchange?fromValue&fromUnit&toUnit",
calculate _
)
)
def calculate(fromValue: BigDecimal,
fromUnit: String,
toUnit: String): ServiceCall[NotUsed, CalculatedValue]