Skip to content

Instantly share code, notes, and snippets.

Adam Warski adamw

Block or report user

Report or block adamw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View x.scala
package sttp.tapir.example
import io.circe.generic.JsonCodec
import sttp.tapir._
import sttp.model.StatusCode
import sttp.tapir.docs.openapi._
import sttp.tapir.openapi.circe.yaml._
import sttp.tapir.json.circe._
object Example extends App {
View x.scala
object CirceAnnotationCodecs {
import io.circe.{Decoder, Encoder}
import io.circe.generic.JsonCodec
import sttp.tapir._
import sttp.tapir.json.circe._
@JsonCodec
case class Foo(x: String)
View Example4Test.scala
it should "add 1 point" in {
// given
val updatedPoints = new AtomicInteger(0)
val userId = UUID.randomUUID()
val stubDao = newStubDaoConstantPoints(15, updatedPoints)
// when
new Points(stubDao).increase(userId).transact(transactor).unsafeRunSync()
// then
View Example4Test.scala
override protected def beforeAll(): Unit = {
super.beforeAll()
transactor = Transactor(
(),
(_: Unit) => Resource.pure(null),
KleisliInterpreter[IO](
Blocker.liftExecutionContext(ExecutionContext.global))
.ConnectionInterpreter,
Strategy.void
)
View Example3Test.scala
class Example3Test extends AnyFlatSpec with Matchers {
import Example3._
it should "add 1 point" in {
// given
val updatedPoints = new AtomicInteger(0)
val userId = UUID.randomUUID()
val stubDao = newStubDaoConstantPoints(15, updatedPoints)
// when
View Example3.scala
import java.util.UUID
import cats._
import cats.implicits._
class Points[F[_]: Monad](dao: Dao[F]) {
def increase(userId: UUID): F[Unit] =
for {
current <- dao.currentPoints(userId)
updated = calculatePointsIncrease(current)
View Example3.scala
trait Dao[F[_]] {
def currentPoints(userId: UUID): F[Int]
def updatePoints(userId: UUID, value: Int): F[Unit]
}
import doobie._
import doobie.implicits._
import doobie.postgres.implicits._
object DefaultDao extends Dao[ConnectionIO] {
View Example2Test.scala
it should "add 1 point" in {
import Example2._
PointsLogic.calculatePointsIncrease(15) shouldBe 16
}
it should "add 3 points" in {
import Example2._
PointsLogic.calculatePointsIncrease(16) shouldBe 19
}
View Example1Test.scala
class Example1Test extends AnyFlatSpec with Matchers with BeforeAndAfterAll {
private var postgres: EmbeddedPostgres = _
private var transactor: Transactor[IO] = _
implicit private val ioContextShift: ContextShift[IO] =
IO.contextShift(ExecutionContext.global)
override protected def beforeAll(): Unit = {
super.beforeAll()
postgres = EmbeddedPostgres.builder().start()
transactor = Transactor.fromDriverManager[IO](
View Example1.scala
import java.util.UUID
import doobie._
import doobie.implicits._
import doobie.postgres.implicits._
class Points(dao: Dao) {
def increase(userId: UUID): ConnectionIO[Unit] =
for {
current <- dao.currentPoints(userId)
You can’t perform that action at this time.