This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val updateUserEndpoint = secureEndpoint.post | |
.in(User) | |
.in(jsonBody[UpdateUser_IN]) | |
.out(jsonBody[UpdateUser_OUT]) | |
.serverLogic { | |
case (authData, data) => | |
(for { | |
userId <- auth(authData) | |
_ <- userService.changeUser(userId, data.login, data.email).transact(xa) | |
} yield UpdateUser_OUT()).toOut |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class DBConfig(username: String, password: String, url: String, | |
migrateOnStart: Boolean, driver: String, connectThreadPoolSize: Int) { | |
override def toString: String = | |
s"DBConfig($username,***,$url,$migrateOnStart,$driver,$connectThreadPoolSize)" | |
} | |
case class HttpConfig(host: String, port: Int) | |
// ... other config classes ... | |
case class Config(db: DBConfig, api: HttpConfig, email: EmailConfig, | |
passwordReset: PasswordResetConfig, user: UserConfig) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait EmailModule extends BaseModule { | |
lazy val emailService = new EmailService(idGenerator, emailSender, config.email, xa) | |
// the EmailService implements the EmailScheduler functionality - hence, creating | |
// an alias for this dependency | |
lazy val emailScheduler: EmailScheduler = emailService | |
lazy val emailTemplates = new EmailTemplates() | |
// depending on the configuration, creating the appropriate EmailSender instance | |
lazy val emailSender: EmailSender = if (config.email.mailgun.enabled) { | |
new MailgunEmailSender(config.email.mailgun)(sttpBackend) | |
} else if (config.email.smtp.enabled) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"contractName": "Tender", | |
"abi": [ | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val ae = IO.effectAsync[Any, Throwable, Unit] { cb => | |
ec3.submit(new Runnable { | |
override def run(): Unit = { | |
println(Thread.currentThread().getName + " (async)") | |
cb(IO.fail(new IllegalStateException())) | |
} | |
}) | |
} | |
run("async shift error") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run("async shift error") { | |
ae.guarantee(IO.shift(ec1)).guarantee(printThread) | |
} | |
/* | |
Outputs: | |
-- async shift error -- | |
ec3-1-785992331 (async) | |
ec1-2-274064559 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val ae = IO.async[Unit] { cb => | |
ec3.submit(new Runnable { | |
override def run(): Unit = { | |
println(Thread.currentThread().getName + " (async)") | |
cb(Left(new IllegalStateException())) | |
} | |
}) | |
} | |
run("async error") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run("async shift") { | |
a *> IO.shift(ec1) *> printThread | |
} | |
/* | |
Outputs: | |
-- async shift -- | |
ec3-1-785992331 (async) | |
ec1-2-274064559 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tapir.docs.openapi._ | |
import tapir.openapi.circe.yaml._ | |
val yaml = List(petEndpoint).toOpenAPI("Our pets", "1.0").toYaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val runtime: DefaultRuntime = new DefaultRuntime {} | |
val serve = BlazeServerBuilder[Task] | |
.bindHttp(8080, "localhost") | |
.withHttpApp(Router("/" -> service).orNotFound) | |
.serve | |
.compile | |
.drain | |
runtime.unsafeRun(serve) |