Skip to content

Commit

Permalink
Upgrade dependencies and scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sentenza committed Dec 21, 2023
1 parent e7752d7 commit 9b28f09
Show file tree
Hide file tree
Showing 23 changed files with 197 additions and 108 deletions.
83 changes: 72 additions & 11 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@
version = "3.5.9"

# Version https://scalameta.org/scalafmt/docs/configuration.html#version
version = 3.7.17
# Dialect https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects
runner.dialect = scala213source3
align.preset = more
style = defaultWithAlign
maxColumn = 115
docstrings.style = SpaceAsterisk
docstrings.removeEmpty = true
continuationIndent.callSite = 2
continuationIndent.defnSite = 4

# Top-level preset https://scalameta.org/scalafmt/docs/configuration.html#top-level-presets
preset = defaultWithAlign

# Common https://scalameta.org/scalafmt/docs/configuration.html#most-popular
maxColumn = 120
assumeStandardLibraryStripMargin = true

# Alignment https://scalameta.org/scalafmt/docs/configuration.html#alignment
align {
preset = more
allowOverflow = true
}

# Newlines https://scalameta.org/scalafmt/docs/configuration.html#newlines
newlines {
alwaysBeforeMultilineDef = false
implicitParamListModifierPrefer = before
beforeCurlyLambdaParams = multilineWithCaseOnly
inInterpolation = "avoid"
}

# Comment processing https://scalameta.org/scalafmt/docs/configuration.html#comment-processing
docstrings {
style = Asterisk
wrap = no
removeEmpty = true
}

# Spaces https://scalameta.org/scalafmt/docs/configuration.html#spaces
spaces {
inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy => zzz }
}

# Project https://scalameta.org/scalafmt/docs/configuration.html#project
project {
git = true
excludeFilters = ["target/"]
}

# Rewrite Rules https://scalameta.org/scalafmt/docs/configuration.html#rewrite-rules
rewrite {
rules = [
AvoidInfix, # https://scalameta.org/scalafmt/docs/configuration.html#avoidinfix
RedundantParens, # https://scalameta.org/scalafmt/docs/configuration.html#redundantparens
SortModifiers, # https://scalameta.org/scalafmt/docs/configuration.html#sortmodifiers
PreferCurlyFors, # https://scalameta.org/scalafmt/docs/configuration.html#prefercurlyfors
Imports, # https://scalameta.org/scalafmt/docs/configuration.html#imports
]
sortModifiers.order = ["private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy"]
imports {
expand = true
sort = original
groups = [["java(x)?\\..*"], ["scala\\..*"], ["sbt\\..*"]]
}
trailingCommas.style = keep # https://scalameta.org/scalafmt/docs/configuration.html#trailing-commas
}

fileOverride {
"glob:**/src/main/scala-3/**" {
runner.dialect = scala3
}
}

includeCurlyBraceInSelectChains = false
project.git = true
project.excludeFilters = ["target/"]

continuationIndent {
callSite = 2
defnSite = 4
}
28 changes: 14 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
val PureConfigVersion = "0.17.2"
val Http4sVersion = "0.23.11"
val CirceVersion = "0.14.2"
val EnumeratumVersion = "1.7.0"
val LogbackVersion = "1.2.12"
val ScalaTestVersion = "3.2.10"
val FlexmarkVersion = "0.64.0"
val FlywayVersion = "8.5.13"
val DoobieVersion = "1.0.0-RC2"
val PureConfigVersion = "0.17.4"
val Http4sVersion = "0.23.24"
val CirceVersion = "0.14.6"
val EnumeratumVersion = "1.7.3"
val LogbackVersion = "1.4.14"
val ScalaTestVersion = "3.2.17"
val FlexmarkVersion = "0.64.8"
val FlywayVersion = "10.4.0"
val DoobieVersion = "1.0.0-RC5"

lazy val root = (project in file("."))
.settings(
organization := "com.github.sentenza",
name := "cats-h4s",
version := "0.0.1-SNAPSHOT",
scalaVersion := "2.13.10",
scalaVersion := "2.13.12",
libraryDependencies ++= Seq(
// http4s
"org.http4s" %% "http4s-ember-server" % Http4sVersion,
Expand All @@ -37,10 +37,10 @@ lazy val root = (project in file("."))
"com.beachape" %% "enumeratum" % EnumeratumVersion,
"com.beachape" %% "enumeratum-circe" % EnumeratumVersion,
// scalatest
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"org.scalatestplus" %% "mockito-3-4" % (ScalaTestVersion + ".0") % Test,
"com.vladsch.flexmark" % "flexmark-all" % FlexmarkVersion % Test,
"org.typelevel" %% "cats-effect-testing-scalatest" % "1.5.0" % Test,
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"org.scalatestplus" %% "mockito-3-4" % "3.2.10.0" % Test,
"com.vladsch.flexmark" % "flexmark-all" % FlexmarkVersion % Test,
"org.typelevel" %% "cats-effect-testing-scalatest" % "1.5.0" % Test,
"ch.qos.logback" % "logback-classic" % LogbackVersion,
"org.scalameta" %% "svm-subs" % "20.2.0"
),
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.3
sbt.version=1.9.8
16 changes: 6 additions & 10 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// Easily manage scalac settings across scala versions with this
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.2")

// Makes our code tidy
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

// Revolver allows us to use re-start and work a lot faster!
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")

// To keep our dependencies up to date
addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "4.3.0")

// To enable test coverage analysis
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.7")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")

// To keep our dependencies up to date
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0")
3 changes: 2 additions & 1 deletion src/main/scala/com/github/sentenza/catsh4s/Main.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.sentenza.catsh4s

import cats.effect.{IO, IOApp}
import cats.effect.IO
import cats.effect.IOApp
import com.github.sentenza.catsh4s.infrastructure.Server

object Main extends IOApp.Simple {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.sentenza.catsh4s.config

import cats.effect.{Async, Resource}
import pureconfig.ConfigSource
import cats.effect.Async
import cats.effect.Resource
import pureconfig.generic.auto._
import pureconfig.module.catseffect.syntax._
import pureconfig.ConfigSource

case class ServerConfig(host: String, port: Int)
case class CmcConfig(baseUrl: String, apikey: String)
Expand Down
13 changes: 8 additions & 5 deletions src/main/scala/com/github/sentenza/catsh4s/db/Database.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.github.sentenza.catsh4s.db

import cats.effect.{Async, Resource, Sync}
import scala.concurrent.ExecutionContext

import cats.effect.Async
import cats.effect.Resource
import cats.effect.Sync
import cats.implicits.toFunctorOps
import com.github.sentenza.catsh4s.config.DatabaseConfig
import doobie.hikari.HikariTransactor
import org.flywaydb.core.Flyway

import scala.concurrent.ExecutionContext

object Database {
def transactor[F[_]: Async](
config: DatabaseConfig,
Expand All @@ -28,8 +30,9 @@ object Database {
S.delay(fw.migrate()).as(())
}

/** Runs the flyway migrations against the target database
*/
/**
* Runs the flyway migrations against the target database
*/
def initializeDb[F[_]](cfg: DatabaseConfig)(implicit S: Sync[F]): F[Unit] =
S.delay {
val fw: Flyway =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.github.sentenza.catsh4s.domain.crypto

/** Represents a Cryptocurrency
*
* @param symbol
* e.g. "BTC"
* @param name
* e.g. "Bitcoin"
* @param slug
* e.g. "bitcoin"
*/
/**
* Represents a Cryptocurrency
*
* @param symbol
* e.g. "BTC"
* @param name
* e.g. "Bitcoin"
* @param slug
* e.g. "bitcoin"
*/
case class CryptoCurrency(symbol: CryptoCurrency.Symbol, name: CryptoCurrency.Name, slug: CryptoCurrency.Slug)

object CryptoCurrency {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.github.sentenza.catsh4s.domain.crypto

import cats.Functor
import cats.data.EitherT
import cats.Functor
import com.github.sentenza.catsh4s.domain.CurrencyNotFoundError

class CryptoCurrencyService[F[_]](ccRepo: CryptoCurrencyRepositoryAlgebra[F]) {

def get(symbol: CryptoCurrency.Symbol)(implicit
F: Functor[F]
def get(symbol: CryptoCurrency.Symbol)(
implicit F: Functor[F]
): EitherT[F, CurrencyNotFoundError.type, CryptoCurrency] =
EitherT.fromOptionF(ccRepo.get(symbol), CurrencyNotFoundError)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.github.sentenza.catsh4s.infrastructure

import cats.effect.{Async, Resource}
import cats.effect.Async
import cats.effect.Resource
import com.comcast.ip4s._
import com.github.sentenza.catsh4s.config.AppConfig
import com.github.sentenza.catsh4s.db.Database
import com.github.sentenza.catsh4s.infrastructure.routes.{CoinMarketCapRoutes, HealthRoutes, MainApiRoutes}
import com.github.sentenza.catsh4s.infrastructure.service.{CoinMarketCapService, PingService}
import com.github.sentenza.catsh4s.infrastructure.routes.CoinMarketCapRoutes
import com.github.sentenza.catsh4s.infrastructure.routes.HealthRoutes
import com.github.sentenza.catsh4s.infrastructure.routes.MainApiRoutes
import com.github.sentenza.catsh4s.infrastructure.service.CoinMarketCapService
import com.github.sentenza.catsh4s.infrastructure.service.PingService
import doobie.ExecutionContexts
import org.http4s.HttpApp
import fs2.io.net.Network
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.server.middleware.Logger
import org.http4s.HttpApp

object Server {

def run[F[_]: Async]: F[Nothing] = {
def run[F[_]: Async: Network]: F[Nothing] = {
import cats.syntax.semigroupk._ // to be able to combine routes
(for {
client <- EmberClientBuilder.default[F].build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.github.sentenza.catsh4s.infrastructure
import com.github.sentenza.catsh4s.domain.crypto.CryptoCurrency
import com.github.sentenza.catsh4s.domain.generic.Pong
import io.circe.generic.semiauto.deriveDecoder
import io.circe.{Decoder, Encoder, Json}
import org.http4s.EntityEncoder
import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
import org.http4s.circe.jsonEncoderOf
import org.http4s.EntityEncoder

package object json {
// Cryptocurrency
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.sentenza.catsh4s.infrastructure.repository.doobie

import cats.effect.Async
import com.github.sentenza.catsh4s.domain.crypto.{CryptoCurrency, CryptoCurrencyRepositoryAlgebra}
import com.github.sentenza.catsh4s.domain.crypto.CryptoCurrency
import com.github.sentenza.catsh4s.domain.crypto.CryptoCurrencyRepositoryAlgebra
import doobie.implicits._
import doobie.util.query.Query0
import doobie.util.transactor.Transactor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.github.sentenza.catsh4s.infrastructure.routes

import cats.effect.Sync
import com.github.sentenza.catsh4s.infrastructure.service.CoinMarketCapService
import org.http4s.HttpRoutes
import org.http4s.dsl.Http4sDsl
import cats.implicits._
import com.github.sentenza.catsh4s.domain.crypto.CryptoCurrency
import com.github.sentenza.catsh4s.infrastructure.service.CoinMarketCapService
import org.http4s.dsl.Http4sDsl
import org.http4s.HttpRoutes

object CoinMarketCapRoutes {
def cmcRoutes[F[_]: Sync](CMC: CoinMarketCapService[F]): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {}
import dsl._

HttpRoutes.of[F] { case GET -> Root / "cmc" / "quote" / currencySymbol =>
for {
currency <- CMC.getLatestQuote(CryptoCurrency.Symbol(currencySymbol))
response <- Ok(currency.toString)
} yield response
HttpRoutes.of[F] {
case GET -> Root / "cmc" / "quote" / currencySymbol =>
for {
currency <- CMC.getLatestQuote(CryptoCurrency.Symbol(currencySymbol))
response <- Ok(currency.toString)
} yield response
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.sentenza.catsh4s.infrastructure.routes

import cats.effect.Sync
import org.http4s.HttpRoutes
import org.http4s.dsl.Http4sDsl
import org.http4s.HttpRoutes

object HealthRoutes {
def healthRoutes[F[_]: Sync]: HttpRoutes[F] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import cats.effect.Sync
import cats.implicits._
import com.github.sentenza.catsh4s.infrastructure.json._
import com.github.sentenza.catsh4s.infrastructure.service.PingService
import org.http4s.HttpRoutes
import org.http4s.dsl.Http4sDsl
import org.http4s.HttpRoutes

object MainApiRoutes {
def essentialRoutes[F[_]: Sync](H: PingService[F]): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {}
import dsl._

HttpRoutes.of[F] { case GET -> Root / "api" / "ping" / name =>
for {
message <- H.pong(name)
resp <- Ok(message)
} yield resp
HttpRoutes.of[F] {
case GET -> Root / "api" / "ping" / name =>
for {
message <- H.pong(name)
resp <- Ok(message)
} yield resp
}
}
}
Loading

0 comments on commit 9b28f09

Please sign in to comment.