Skip to content

Commit

Permalink
refactor: better scope
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jul 20, 2024
1 parent 7da30ee commit a688372
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/main/scala/net/yoshinorin/qualtet/BootStrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ object BootStrap extends IOApp {
}

def run(args: List[String]): IO[ExitCode] = {
val host = Ipv4Address.fromString(Modules.config.http.host).getOrElse(ipv4"127.0.0.1")
val port = Port.fromInt(Modules.config.http.port).getOrElse(port"9001")

Modules.transactorResource.use { tx =>
val modules = new Modules(tx)
val host = Ipv4Address.fromString(modules.config.http.host).getOrElse(ipv4"127.0.0.1")
val port = Port.fromInt(modules.config.http.port).getOrElse(port"9001")
(for {
_ <- logger.info(ApplicationInfo.asJson)
_ <- IO(modules.migrator.migrate(modules.contentTypeService))
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/net/yoshinorin/qualtet/Modules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ import java.security.SecureRandom
import java.util.concurrent.TimeUnit

object Modules {
val config = ApplicationConfig.load
val doobieTransactor: DoobieTransactor[Aux] = summon[DoobieTransactor[Aux]]
private val config = ApplicationConfig.load
private val doobieTransactor: DoobieTransactor[Aux] = summon[DoobieTransactor[Aux]]

val transactorResource = doobieTransactor.make(config.db)
given log4catsLogger: Log4CatsLoggerFactory[IO] = Log4CatsSlf4jFactory.create[IO]
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/net/yoshinorin/qualtet/auth/JwtSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.time.Instant
class JwtSpec extends AnyWordSpec {

val mod = Modules(fixtureTx)
val config = Modules.config
val config = mod.config
val jc: JwtClaim = JwtClaim(
iss = config.jwt.iss,
aud = config.jwt.aud,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.yoshinorin.qualtet.config

import net.yoshinorin.qualtet.Modules.*
import net.yoshinorin.qualtet.fixture.Fixture.config
import org.scalatest.wordspec.AnyWordSpec

// testOnly net.yoshinorin.qualtet.config.ConfigSpec
Expand Down
12 changes: 7 additions & 5 deletions src/test/scala/net/yoshinorin/qualtet/fixture/Fixture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.typelevel.log4cats.slf4j.{Slf4jFactory => Log4CatsSlf4jFactory}
import com.github.benmanes.caffeine.cache.Caffeine
import com.github.benmanes.caffeine.cache.{Cache => CaffeineCache}
import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
import net.yoshinorin.qualtet.config.ApplicationConfig
import net.yoshinorin.qualtet.http.AuthProvider
import net.yoshinorin.qualtet.http.CorsProvider
import net.yoshinorin.qualtet.cache.CacheModule
Expand Down Expand Up @@ -53,15 +54,16 @@ object Fixture {
ULID.newULIDString.toLower
}

val h: String = Modules.config.http.host
val p: String = Modules.config.http.port.toString()
val config = ApplicationConfig.load
val h: String = config.http.host
val p: String = config.http.port.toString()
val host = Uri.unsafeFromString(s"http://${h}:${p}")

val fixtureTx = Transactor.fromDriverManager[IO](
driver = "org.mariadb.jdbc.Driver",
url = Modules.config.db.url,
user = Modules.config.db.user,
password = Modules.config.db.password,
url = config.db.url,
user = config.db.user,
password = config.db.password,
logHandler = None
)
private val modules = Modules(fixtureTx)
Expand Down

0 comments on commit a688372

Please sign in to comment.