diff --git a/project/build.properties b/project/build.properties index 46e43a9..abbbce5 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.8.2 +sbt.version=1.9.8 diff --git a/src/main/g8/build.sbt b/src/main/g8/build.sbt index c1ead85..a16b7e0 100644 --- a/src/main/g8/build.sbt +++ b/src/main/g8/build.sbt @@ -1,13 +1,13 @@ -val zioVersion = "2.0.13" -val zioJsonVersion = "0.5.0" -val zioConfigVersion = "3.0.7" -val zioLoggingVersion = "2.1.11" +val zioVersion = "2.0.21" +val zioJsonVersion = "0.6.2" +val zioConfigVersion = "4.0.1" +val zioLoggingVersion = "2.1.16" val logbackClassicVersion = "1.4.7" val postgresqlVersion = "42.6.0" val testContainersVersion = "0.40.15" -val zioMockVersion = "1.0.0-RC11" -val zioHttpVersion = "3.0.0-RC1" -val quillVersion = "4.6.0.1" +val zioMockVersion = "1.0.0-RC12" +val zioHttpVersion = "3.0.0-RC4" +val quillVersion = "4.8.0" lazy val root = (project in file(".")) .settings( diff --git a/src/main/g8/default.properties b/src/main/g8/default.properties index 7caa90e..5a9d7b6 100644 --- a/src/main/g8/default.properties +++ b/src/main/g8/default.properties @@ -1,5 +1,5 @@ name=zio-scala3-quickstart description=This is a seed project that creates Scala 3 based ZIO application. -scala_version=3.2.2 +scala_version=3.3.1 organization=com.example package=$organization$ diff --git a/src/main/g8/project/build.properties b/src/main/g8/project/build.properties index 46e43a9..abbbce5 100644 --- a/src/main/g8/project/build.properties +++ b/src/main/g8/project/build.properties @@ -1 +1 @@ -sbt.version=1.8.2 +sbt.version=1.9.8 diff --git a/src/main/g8/src/main/scala/$package$/api/Extensions.scala b/src/main/g8/src/main/scala/$package$/api/Extensions.scala index fadfcd6..4a46bb5 100644 --- a/src/main/g8/src/main/scala/$package$/api/Extensions.scala +++ b/src/main/g8/src/main/scala/$package$/api/Extensions.scala @@ -20,7 +20,7 @@ private[api] object Extensions: def toResponseZIO(implicit ev: JsonEncoder[T]): UIO[Response] = toResponseZIO(Status.Ok) def toResponseZIO(status: Status)(implicit ev: JsonEncoder[T]): UIO[Response] = ZIO.succeed { - Response.json(data.toJson).withStatus(status) + Response.json(data.toJson).status(status) } def toEmptyResponseZIO: UIO[Response] = toEmptyResponseZIO(Status.NoContent) diff --git a/src/main/g8/src/main/scala/$package$/api/HealthCheckRoutes.scala b/src/main/g8/src/main/scala/$package$/api/HealthCheckRoutes.scala index 1bdce2a..442e78c 100644 --- a/src/main/g8/src/main/scala/$package$/api/HealthCheckRoutes.scala +++ b/src/main/g8/src/main/scala/$package$/api/HealthCheckRoutes.scala @@ -6,17 +6,16 @@ import zio.http._ object HealthCheckRoutes: - val app: HttpApp[HealthCheckService, Nothing] = Http.collectZIO { - - case Method.HEAD -> !! / "healthcheck" => + val app: HttpApp[HealthCheckService] = Routes( + Method.HEAD / "healthcheck" -> handler { (_: Request) => ZIO.succeed { Response.status(Status.NoContent) } - - case Method.GET -> !! / "healthcheck" => + }, + Method.GET / "healthcheck" -> handler { (_: Request) => HealthCheckService.check.map { dbStatus => if (dbStatus.status) Response.ok else Response.status(Status.InternalServerError) } - - } + }, + ).toHttpApp diff --git a/src/main/g8/src/main/scala/$package$/api/HttpRoutes.scala b/src/main/g8/src/main/scala/$package$/api/HttpRoutes.scala index 29c58f6..1d5661e 100644 --- a/src/main/g8/src/main/scala/$package$/api/HttpRoutes.scala +++ b/src/main/g8/src/main/scala/$package$/api/HttpRoutes.scala @@ -11,14 +11,15 @@ import zio.json._ object HttpRoutes extends JsonSupport: - val app: HttpApp[ItemRepository, Nothing] = Http.collectZIO { - case Method.GET -> !! / "items" => + val app: HttpApp[ItemRepository] = Routes( + Method.GET / "items" -> handler { (_: Request) => val effect: ZIO[ItemRepository, DomainError, List[Item]] = ItemService.getAllItems() effect.foldZIO(Utils.handleError, _.toResponseZIO) - case Method.GET -> !! / "items" / itemId => + }, + Method.GET / "items" / string("itemId") -> handler { (itemId: String, _: Request) => val effect: ZIO[ItemRepository, DomainError, Item] = for { id <- Utils.extractLong(itemId) @@ -30,7 +31,8 @@ object HttpRoutes extends JsonSupport: effect.foldZIO(Utils.handleError, _.toResponseZIO) - case Method.DELETE -> !! / "items" / itemId => + }, + Method.DELETE / "items" / string("itemId") -> handler { (itemId: String, _: Request) => val effect: ZIO[ItemRepository, DomainError, Unit] = for { id <- Utils.extractLong(itemId) @@ -41,7 +43,8 @@ object HttpRoutes extends JsonSupport: effect.foldZIO(Utils.handleError, _.toEmptyResponseZIO) - case req @ Method.POST -> !! / "items" => + }, + Method.POST / "items" -> handler { (req: Request) => val effect: ZIO[ItemRepository, DomainError, Item] = for { createItem <- req.jsonBodyAs[CreateItemRequest] @@ -50,7 +53,8 @@ object HttpRoutes extends JsonSupport: effect.foldZIO(Utils.handleError, _.toResponseZIO(Status.Created)) - case req @ Method.PUT -> !! / "items" / itemId => + }, + Method.PUT / "items" / string("itemId") -> handler { (itemId: String, req: Request) => val effect: ZIO[ItemRepository, DomainError, Item] = for { id <- Utils.extractLong(itemId) @@ -63,7 +67,8 @@ object HttpRoutes extends JsonSupport: effect.foldZIO(Utils.handleError, _.toResponseZIO) - case req @ Method.PATCH -> !! / "items" / itemId => + }, + Method.PATCH / "items" / string("itemId") -> handler { (itemId: String, req: Request) => val effect: ZIO[ItemRepository, DomainError, Item] = for { id <- Utils.extractLong(itemId) @@ -79,5 +84,5 @@ object HttpRoutes extends JsonSupport: } yield item effect.foldZIO(Utils.handleError, _.toResponseZIO) - - } + }, + ).toHttpApp diff --git a/src/main/g8/src/main/scala/$package$/config/Configuration.scala b/src/main/g8/src/main/scala/$package$/config/Configuration.scala index 7d9afd1..98f02de 100644 --- a/src/main/g8/src/main/scala/$package$/config/Configuration.scala +++ b/src/main/g8/src/main/scala/$package$/config/Configuration.scala @@ -3,8 +3,9 @@ package $package$.config import com.typesafe.config.ConfigFactory import zio._ import zio.config._ -import zio.config.ConfigDescriptor._ -import zio.config.typesafe.TypesafeConfigSource +import zio.config.typesafe._ +import zio.Config._ +import zio.config.typesafe.TypesafeConfigProvider object Configuration: @@ -12,17 +13,16 @@ object Configuration: object ApiConfig: - private val serverConfigDescription = - nested("api") { - string("host") <*> - int("port") - }.to[ApiConfig] + private val serverConfigDescription: Config[ApiConfig] = + (string("host") zip int("port")) + .nested("api") + .to[ApiConfig] val layer = ZLayer( read( serverConfigDescription.from( - TypesafeConfigSource.fromTypesafeConfig( - ZIO.attempt(ConfigFactory.defaultApplication()) + TypesafeConfigProvider.fromTypesafeConfig( + ConfigFactory.defaultApplication() ) ) ) diff --git a/src/main/g8/src/test/scala/$package$/api/HealthCheckRoutes.scala b/src/main/g8/src/test/scala/$package$/api/HealthCheckRoutes.scala index 7240f02..f5290d6 100644 --- a/src/main/g8/src/test/scala/$package$/api/HealthCheckRoutes.scala +++ b/src/main/g8/src/test/scala/$package$/api/HealthCheckRoutes.scala @@ -11,7 +11,7 @@ object HealthCheckRoutesSpec extends ZIOSpecDefault: suite("health check")( test("ok status") { val actual = - HealthCheckRoutes.app.runZIO(Request.get(URL(!! / "healthcheck"))) + HealthCheckRoutes.app.runZIO(Request.get(URL(Path("healthcheck")))) assertZIO(actual)(equalTo(Response(Status.Ok, Headers.empty, Body.empty))) } )