diff --git a/build.sbt b/build.sbt index b9014bc..b7b41d4 100644 --- a/build.sbt +++ b/build.sbt @@ -10,12 +10,7 @@ val circeV = "0.14.6" lazy val common = project .in(file("common")) - .settings( - name := "todobackend-common", - libraryDependencies ++= Seq( - "io.circe" %% "circe-generic" % circeV - ) - ) + .settings(name := "todobackend-common") val http4sV = "1.0.0-M40" val logbackV = "1.4.11" @@ -31,6 +26,7 @@ lazy val `todobackend-http4s` = project "org.http4s" %% "http4s-ember-server" % http4sV, "org.http4s" %% "http4s-dsl" % http4sV, "org.http4s" %% "http4s-circe" % http4sV, + "io.circe" %% "circe-generic" % circeV, "ch.qos.logback" % "logback-classic" % logbackV, "org.scalameta" %% "munit" % munitV % Test, "org.typelevel" %% "munit-cats-effect" % munitCE3V % Test diff --git a/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoItem.scala b/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoItem.scala index 0d30824..6a4874e 100644 --- a/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoItem.scala +++ b/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoItem.scala @@ -1,8 +1,5 @@ package es.jesusmtnez.todobackend.domain -import io.circe.* -import io.circe.generic.semiauto.* - import java.util.UUID final case class TodoItem( @@ -13,8 +10,6 @@ final case class TodoItem( ) object TodoItem: - given Codec[TodoItem] = deriveCodec - private val baseUrl: String = "http://localhost:8080" def uncompleted(id: UUID, title: String, order: Int): TodoItem = diff --git a/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoRequest.scala b/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoRequest.scala new file mode 100644 index 0000000..1339c47 --- /dev/null +++ b/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoRequest.scala @@ -0,0 +1,6 @@ +package es.jesusmtnez.todobackend.domain + +final case class TodoRequest( + title: String, + order: Option[Int] +) diff --git a/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/domain/TodoUpdate.scala b/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoUpdate.scala similarity index 53% rename from todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/domain/TodoUpdate.scala rename to common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoUpdate.scala index b57bd84..966c07a 100644 --- a/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/domain/TodoUpdate.scala +++ b/common/src/main/scala/es/jesusmtnez/todobackend/domain/TodoUpdate.scala @@ -1,13 +1,7 @@ package es.jesusmtnez.todobackend.domain -import io.circe.Decoder -import io.circe.generic.semiauto.deriveDecoder - final case class TodoUpdate( title: Option[String], completed: Option[Boolean], order: Option[Int] ) - -object TodoUpdate: - given Decoder[TodoUpdate] = deriveDecoder diff --git a/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/TodoBackendRoutes.scala b/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/TodoBackendRoutes.scala index 2b4fa6a..480b6e8 100644 --- a/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/TodoBackendRoutes.scala +++ b/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/TodoBackendRoutes.scala @@ -4,6 +4,8 @@ import buildinfo.BuildInfo import cats.effect.* import cats.syntax.all.* import es.jesusmtnez.todobackend.domain.* +import io.circe.* +import io.circe.generic.semiauto.* import org.http4s.HttpRoutes import org.http4s.circe.* import org.http4s.dsl.Http4sDsl @@ -21,6 +23,10 @@ object TodoBackendRoutes: val dsl = new Http4sDsl[F] {} import dsl._ + implicit val todoItemCodec: Codec[TodoItem] = deriveCodec + implicit val todoRequestDecoder: Decoder[TodoRequest] = deriveDecoder + implicit val todoUpdateDecoder: Decoder[TodoUpdate] = deriveDecoder + import org.http4s.circe.CirceEntityCodec.* HttpRoutes.of[F]: diff --git a/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/domain/TodoRequest.scala b/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/domain/TodoRequest.scala deleted file mode 100644 index 305bac6..0000000 --- a/todobackend-http4s/src/main/scala/es/jesusmtnez/todobackend/domain/TodoRequest.scala +++ /dev/null @@ -1,12 +0,0 @@ -package es.jesusmtnez.todobackend.domain - -import io.circe.Decoder -import io.circe.generic.semiauto.deriveDecoder - -final case class TodoRequest( - title: String, - order: Option[Int] -) - -object TodoRequest: - given Decoder[TodoRequest] = deriveDecoder