-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: creates api endpoints specifications
- Loading branch information
1 parent
59fa621
commit 6ff71ab
Showing
2 changed files
with
32 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
28 changes: 28 additions & 0 deletions
28
restocking/src/main/scala/dev/atedeg/mdm/restocking/api/endpoints/Endpoints.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.atedeg.mdm.restocking.api.endpoints | ||
|
||
import cats.data.{ EitherT, ReaderT } | ||
import cats.effect.IO | ||
import io.circe.generic.auto.* | ||
import org.http4s.HttpRoutes | ||
import sttp.tapir.* | ||
import sttp.tapir.generic.auto.* | ||
import sttp.tapir.json.circe.jsonBody | ||
import sttp.tapir.server.http4s.Http4sServerInterpreter | ||
|
||
import dev.atedeg.mdm.restocking.api.{ remaningQuintalsOfMilkHandler, DBClient } | ||
import dev.atedeg.mdm.restocking.api.dto.RemainingMilkDTO | ||
import dev.atedeg.mdm.utils.monads.ServerAction | ||
|
||
object RemainingQuintalsOfMilkEndpoint: | ||
private val handler: ServerAction[DBClient, String, RemainingMilkDTO] = remaningQuintalsOfMilkHandler | ||
|
||
@SuppressWarnings(Array("org.wartremover.warts.Any")) | ||
val remainingQuintalsOfMilkEndpoint: PublicEndpoint[Unit, String, RemainingMilkDTO, Any] = | ||
endpoint.get | ||
.in("remaining-quintals-of-milk") | ||
.out(jsonBody[RemainingMilkDTO].description("The quintals of milk remaining in stock")) | ||
.errorOut(stringBody) | ||
|
||
val remainingQuintalsOfMilkRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes( | ||
remainingQuintalsOfMilkEndpoint.serverLogic(_ => handler.value.run(DBClient())), | ||
) |