Skip to content

Commit

Permalink
add ping
Browse files Browse the repository at this point in the history
  • Loading branch information
mmvpm committed Mar 3, 2024
1 parent 46cb8e1 commit 0750e8f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion stub/src/main/scala/com/github/mmvpm/stub/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ object Main extends IOApp {
for {
_ <- IO.pure(0)

pingHandler: PingHandler[IO] = new PingHandler[IO]

stubDao: StubDao[IO] = new StubDaoPostgresql[IO]
stubService: StubService[IO] = new StubServiceImpl[IO](stubDao)
stubHandler: StubHandler[IO] = new StubHandler[IO](stubService)

handlers = List(stubHandler)
handlers = List(pingHandler, stubHandler)
endpoints <- IO.delay(handlers.flatMap(_.endpoints))
routes = Http4sServerInterpreter[IO].toRoutes(swaggerBy(endpoints) ++ endpoints)
server <- serverBuilder(config, routes).value.rethrow
Expand Down
17 changes: 17 additions & 0 deletions stub/src/main/scala/com/github/mmvpm/stub/api/PingHandler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.mmvpm.stub.api
import cats.Applicative
import sttp.tapir._
import sttp.tapir.server.ServerEndpoint

class PingHandler[F[_]: Applicative] extends Handler[F] {

private val ping: ServerEndpoint[Any, F] =
endpoint.get
.summary("Ping")
.in("api" / "v1" / "ping")
.out(stringBody)
.serverLogic(_ => Applicative[F].pure(Right("pong")))

override def endpoints: List[ServerEndpoint[Any, F]] =
List(ping).map(_.withTag("util"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ class StubHandler[F[_]](stubService: StubService[F]) extends Handler[F] {
.serverLogic((stubService.updateStub _).tupled(_).value)

override def endpoints: List[ServerEndpoint[Any, F]] =
List(getStub, getStubs, createStub, updateStub)
List(getStub, getStubs, createStub, updateStub).map(_.withTag("stub"))
}

0 comments on commit 0750e8f

Please sign in to comment.