Skip to content

Commit

Permalink
Refactor acquire action out
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Nov 21, 2023
1 parent 8a1de0a commit 783342e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 11 additions & 12 deletions app/src/main/scala/http/FishnetRoutes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ final class FishnetRoutes(executor: Executor) extends Http4sDsl[IO]:

case req @ POST -> Root / "acquire" =>
req
.decode[Fishnet.Acquire]: acquire =>
executor
.acquire(acquire.fishnet.apikey)
.map(_.map(_.toResponse))
.flatMap(_.fold(NoContent())(Ok(_)))
.recoverWith:
case x => InternalServerError(x.getMessage().nn)
.decode[Fishnet.Acquire]: input =>
acquire(input.fishnet.apikey)

case req @ POST -> Root / "move" / WorkIdVar(id) =>
req
.decode[Fishnet.PostMove]: move =>
executor.move(id, move.fishnet.apikey, move.move.bestmove)
>> executor.acquire(move.fishnet.apikey)
.map(_.map(_.toResponse))
.flatMap(_.fold(NoContent())(Ok(_)))
.recoverWith:
case x => InternalServerError(x.getMessage().nn)
>> acquire(move.fishnet.apikey)

def acquire(key: ClientKey): IO[Response[IO]] =
executor
.acquire(key)
.map(_.map(_.toResponse))
.flatMap(_.fold(NoContent())(Ok(_)))
.recoverWith:
case x => InternalServerError(x.getMessage().nn)

val routes: HttpRoutes[IO] = Router(prefixPath -> httpRoutes)

Expand Down
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy val app = project
.in(file("app"))
.settings(
scalacOptions -= "-Xfatal-warnings",
scalacOptions ++= Seq("-source:future", "-rewrite", "-indent", "-explain", "-Wunused:all"),
scalacOptions ++= Seq("-source:future", "-rewrite", "-indent", "-explain", "-Wunused:all", "-release:21"),
resolvers ++= Seq(Dependencies.lilaMaven),
libraryDependencies ++= Seq(
catsCore,
Expand Down Expand Up @@ -41,7 +41,6 @@ lazy val app = project
munitScalacheck,
weaver,
weaverScalaCheck,
http4sClient,
circeLiteral,
),
)
Expand Down

0 comments on commit 783342e

Please sign in to comment.