Skip to content

Commit

Permalink
refactor: rename Transactor to Executer
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jun 7, 2024
1 parent e22125a commit 2989b04
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/net/yoshinorin/qualtet/Modules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import net.yoshinorin.qualtet.http.routes.v1.{
TagRoute => TagRouteV1
}
import net.yoshinorin.qualtet.infrastructure.db.Migrator
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter

import pdi.jwt.JwtAlgorithm
import java.security.SecureRandom
Expand All @@ -55,7 +55,7 @@ object Modules {
val config = ApplicationConfig.load

given log4catsLogger: Log4CatsLoggerFactory[IO] = Log4CatsSlf4jFactory.create[IO]
given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(config.db)
val migrator: Migrator = new Migrator(config.db)

// NOTE: for generate JWT. They are reset when re-boot application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.domains.contentTypes.ContentTypeService
import net.yoshinorin.qualtet.message.Fail.NotFound
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.domains.contentTypes.ContentTypeId
import net.yoshinorin.qualtet.syntax.*
import cats.Monad

class ArchiveService[F[_]: Monad](
archiveRepository: ArchiveRepository[F],
contentTypeService: ContentTypeService[F]
)(using transactor: Transactor[F, IO]) {
)(using transactor: Executer[F, IO]) {

def actions(contentTypeId: ContentTypeId): Action[Seq[ResponseArchive]] = {
Continue(archiveRepository.get(contentTypeId), Action.done[Seq[ResponseArchive]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import net.yoshinorin.qualtet.message.Fail.NotFound
import net.yoshinorin.qualtet.domains.tags.TagName
import net.yoshinorin.qualtet.domains.series.SeriesName
import net.yoshinorin.qualtet.http.ArticlesQueryParameter
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.syntax.*

class ArticleService[F[_]: Monad](
articleRepository: ArticleRepository[F],
contentTypeService: ContentTypeService[F]
)(using transactor: Transactor[F, IO]) {
)(using transactor: Executer[F, IO]) {

def actions(
contentTypeId: ContentTypeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package net.yoshinorin.qualtet.domains.authors
import cats.effect.IO
import cats.Monad
import net.yoshinorin.qualtet.message.Fail.InternalServerError
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.syntax.*

class AuthorService[F[_]: Monad](
authorRepository: AuthorRepository[F]
)(using transactor: Transactor[F, IO]) {
)(using transactor: Executer[F, IO]) {

def upsertActions(data: Author): Action[Int] = {
Continue(authorRepository.upsert(data), Action.done[Int])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.domains.contents.ContentId
import net.yoshinorin.qualtet.domains.tags.TagId
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer

class ContentTaggingService[F[_]: Monad](
contentTaggingRepository: ContentTaggingRepository[F]
)(using transactor: Transactor[F, IO]) {
)(using transactor: Executer[F, IO]) {

def findByTagIdActions(id: TagId): Action[Seq[ContentTagging]] = {
Continue(contentTaggingRepository.findByTagId(id), Action.done[Seq[ContentTagging]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.message.Fail.InternalServerError
import net.yoshinorin.qualtet.domains.Cacheable
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.syntax.*

class ContentTypeService[F[_]: Monad](
contentRepository: ContentTypeRepository[F],
cache: CacheModule[String, ContentType]
)(using transactor: Transactor[F, IO])
)(using transactor: Executer[F, IO])
extends Cacheable {

def upsertActions(data: ContentType): Action[Int] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import net.yoshinorin.qualtet.domains.contentTaggings.{ContentTagging, ContentTa
import net.yoshinorin.qualtet.domains.robots.{Attributes, Robots, RobotsService}
import net.yoshinorin.qualtet.domains.tags.{Tag, TagId, TagName, TagService}
import net.yoshinorin.qualtet.domains.series.{Series, SeriesName, SeriesService}
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.syntax.*

class ContentService[F[_]: Monad](
Expand All @@ -28,7 +28,7 @@ class ContentService[F[_]: Monad](
seriesService: SeriesService[F],
contentSerializingService: ContentSerializingService[F]
)(using
transactor: Transactor[F, IO]
transactor: Executer[F, IO]
) {

def upsertActions(data: Content): Action[Int] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cats.implicits.*
import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.config.SearchConfig
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.message.Fail.UnprocessableEntity
import net.yoshinorin.qualtet.message.{Error => Err}
import net.yoshinorin.qualtet.types.Points
Expand All @@ -17,7 +17,7 @@ import scala.annotation.tailrec
class SearchService[F[_]: Monad](
searchConfig: SearchConfig,
searchRepository: SearchRepository[F]
)(using transactor: Transactor[F, IO]) {
)(using transactor: Executer[F, IO]) {

def actions(query: List[String]): Action[Seq[(Int, ResponseSearch)]] = {
Continue(searchRepository.search(query), Action.done[Seq[(Int, ResponseSearch)]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import cats.Monad
import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.domains.articles.ArticleService
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.message.Fail.NotFound
import net.yoshinorin.qualtet.syntax.*
import wvlet.airframe.ulid.ULID

class SeriesService[F[_]: Monad](
seriesRepository: SeriesRepository[F],
articleService: ArticleService[F]
)(using transactor: Transactor[F, IO]) {
)(using transactor: Executer[F, IO]) {

def upsertActions(data: Series): Action[Int] = {
Continue(seriesRepository.upsert(data), Action.done[Int])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import cats.Monad
import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.cache.CacheModule
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.domains.Cacheable

class SitemapService[F[_]: Monad](
sitemapRepository: SitemapsRepository[F],
cache: CacheModule[String, Seq[Url]]
)(using transactor: Transactor[F, IO])
)(using transactor: Executer[F, IO])
extends Cacheable {

private val cacheKey = "sitemaps-full-cache"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import cats.implicits.*
import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.domains.contentTaggings.ContentTaggingService
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer
import net.yoshinorin.qualtet.message.Fail.NotFound
import net.yoshinorin.qualtet.domains.contents.ContentId
import net.yoshinorin.qualtet.syntax.*

class TagService[F[_]: Monad](
tagRepository: TagRepository[F],
contentTaggingService: ContentTaggingService[F]
)(using transactor: Transactor[F, IO]) {
)(using transactor: Executer[F, IO]) {

def bulkUpsertActions(data: Option[List[Tag]]): Action[Int] = {
data match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.yoshinorin.qualtet.infrastructure.db
import cats.Monad
import net.yoshinorin.qualtet.actions.Action

trait Transactor[F[_], G[_]: Monad] {
trait Executer[F[_], G[_]: Monad] {
def perform[R](a: Action[R]): F[R]
def transact[T](t: F[T]): G[T]
def transact[R](a: Action[R]): G[R]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import cats.effect.*
import cats.effect.IO
import net.yoshinorin.qualtet.actions.{Action, Continue, Done}
import net.yoshinorin.qualtet.config.DBConfig
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.infrastructure.db.Executer

class DoobieTransactor(config: DBConfig) extends Transactor[ConnectionIO, IO] {
class DoobieExecuter(config: DBConfig) extends Executer[ConnectionIO, IO] {

val executors: ExecutorService = Executors.newCachedThreadPool()
val executionContexts: ExecutionContextExecutor = scala.concurrent.ExecutionContext.fromExecutor(executors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import doobie.ConnectionIO
import org.slf4j.LoggerFactory
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import net.yoshinorin.qualtet.domains.authors.{Author, AuthorDisplayName, AuthorName, AuthorRepository, AuthorService, BCryptPassword}
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import net.yoshinorin.qualtet.Modules.*
import net.yoshinorin.qualtet.syntax.*
import net.yoshinorin.qualtet.domains.authors.ResponseAuthor
Expand All @@ -17,7 +17,7 @@ object CreateAuthor {

private val logger = LoggerFactory.getLogger(this.getClass)

given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(config.db)
val authorRepository: AuthorRepository[ConnectionIO] = summon[AuthorRepository[ConnectionIO]]
val authorService = new AuthorService(authorRepository)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import net.yoshinorin.qualtet.domains.authors.ResponseAuthor
import net.yoshinorin.qualtet.message.Fail.{NotFound, Unauthorized}
import net.yoshinorin.qualtet.Modules.*
import net.yoshinorin.qualtet.fixture.Fixture.*
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import org.scalatest.wordspec.AnyWordSpec
import cats.effect.unsafe.implicits.global

// testOnly net.yoshinorin.qualtet.auth.AuthServiceSpec
class AuthServiceSpec extends AnyWordSpec {

given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(config.db)

val a: ResponseAuthor = authorService.findByName(author.name).unsafeRunSync().get
val a2: ResponseAuthor = authorService.findByName(author2.name).unsafeRunSync().get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import net.yoshinorin.qualtet.domains.contents.{Path, RequestContent}
import net.yoshinorin.qualtet.domains.robots.Attributes
import net.yoshinorin.qualtet.domains.series.*
import net.yoshinorin.qualtet.fixture.Fixture.*
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import net.yoshinorin.qualtet.Modules.*
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.BeforeAndAfterAll
Expand All @@ -15,7 +15,7 @@ import org.scalatest.Ignore
@Ignore // TODO: write testcode when implement delete feature
class ContentSerializingServiceSpec extends AnyWordSpec with BeforeAndAfterAll {

given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(config.db)

val requestSeries: RequestSeries = RequestSeries(
title = "Content Serializing Service Spec",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.yoshinorin.qualtet.domains.contentTaggings
import net.yoshinorin.qualtet.domains.contents.{Path, RequestContent}
import net.yoshinorin.qualtet.domains.robots.Attributes
import net.yoshinorin.qualtet.fixture.Fixture.*
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import net.yoshinorin.qualtet.Modules.*
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.BeforeAndAfterAll
Expand All @@ -13,7 +13,7 @@ import cats.effect.unsafe.implicits.global
// testOnly net.yoshinorin.qualtet.domains.contentTaggings.ContentTaggingServiceSpec
class ContentTaggingServiceSpec extends AnyWordSpec with BeforeAndAfterAll {

given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(config.db)

val requestContents: List[RequestContent] = {
List(1, 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.yoshinorin.qualtet.domains.tags
import net.yoshinorin.qualtet.domains.contents.Path
import net.yoshinorin.qualtet.domains.series.{RequestSeries, SeriesName}
import net.yoshinorin.qualtet.fixture.Fixture.*
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import net.yoshinorin.qualtet.Modules.*
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.BeforeAndAfterAll
Expand All @@ -13,7 +13,7 @@ import cats.effect.unsafe.implicits.global
// testOnly net.yoshinorin.qualtet.domains.SeriesServiceSpec
class SeriesServiceSpec extends AnyWordSpec with BeforeAndAfterAll {

given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(config.db)

val requestSeries: List[RequestSeries] = List(
RequestSeries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.yoshinorin.qualtet.domains.tags

import net.yoshinorin.qualtet.domains.contents.Path
import net.yoshinorin.qualtet.fixture.Fixture.*
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import net.yoshinorin.qualtet.Modules.*
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.BeforeAndAfterAll
Expand All @@ -13,7 +13,7 @@ import cats.effect.unsafe.implicits.global
// testOnly net.yoshinorin.qualtet.domains.TagServiceSpec
class TagServiceSpec extends AnyWordSpec with BeforeAndAfterAll {

given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(config.db)

val requestContents = makeRequestContents(10, "tagService")

Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/net/yoshinorin/qualtet/fixture/Fixture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import net.yoshinorin.qualtet.domains.feeds.FeedService
import net.yoshinorin.qualtet.domains.articles.ResponseArticleWithCount
import net.yoshinorin.qualtet.Modules
import net.yoshinorin.qualtet.syntax.*
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import cats.effect.unsafe.implicits.global
import net.yoshinorin.qualtet.domains.series.{RequestSeries, SeriesName}

Expand All @@ -56,7 +56,7 @@ object Fixture {
val p: String = Modules.config.http.port.toString()
val host = Uri.unsafeFromString(s"http://${h}:${p}")

given dbContext: DoobieTransactor = new DoobieTransactor(Modules.config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(Modules.config.db)
given log4catsLogger: Log4CatsLoggerFactory[IO] = Log4CatsSlf4jFactory.create[IO]

// TODO: from config for cache options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package net.yoshinorin.qualtet.infrastructure.db

import net.yoshinorin.qualtet.fixture.Fixture.contentTypeService
import net.yoshinorin.qualtet.Modules
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter
import org.scalatest.wordspec.AnyWordSpec

import cats.effect.unsafe.implicits.global

// testOnly net.yoshinorin.qualtet.infrastructure.db.MigratorSpec
class MigratorSpec extends AnyWordSpec {

given dbContext: DoobieTransactor = new DoobieTransactor(Modules.config.db)
given dbContext: DoobieExecuter = new DoobieExecuter(Modules.config.db)

"Migrator" should {

Expand Down

0 comments on commit 2989b04

Please sign in to comment.