diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/archives/ArchiveService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/archives/ArchiveService.scala index 2a0f3e90..34d38333 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/archives/ArchiveService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/archives/ArchiveService.scala @@ -13,7 +13,7 @@ import cats.Monad class ArchiveService[F[_]: Monad]( archiveRepository: ArchiveRepository[F], contentTypeService: ContentTypeService[F] -)(using transactor: Executer[F, IO]) { +)(using executer: Executer[F, IO]) { def actions(contentTypeId: ContentTypeId): Action[Seq[ResponseArchive]] = { Continue(archiveRepository.get(contentTypeId), Action.done[Seq[ResponseArchive]]) @@ -22,7 +22,7 @@ class ArchiveService[F[_]: Monad]( def get: IO[Seq[ResponseArchive]] = { for { c <- contentTypeService.findByName("article").throwIfNone(NotFound(detail = "content-type not found: article")) - articles <- transactor.transact(actions(c.id)) + articles <- executer.transact(actions(c.id)) } yield articles } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/articles/ArticleService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/articles/ArticleService.scala index 0e0a2fc0..eaf5eb8a 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/articles/ArticleService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/articles/ArticleService.scala @@ -15,7 +15,7 @@ import net.yoshinorin.qualtet.syntax.* class ArticleService[F[_]: Monad]( articleRepository: ArticleRepository[F], contentTypeService: ContentTypeService[F] -)(using transactor: Executer[F, IO]) { +)(using executer: Executer[F, IO]) { def actions( contentTypeId: ContentTypeId, @@ -53,7 +53,7 @@ class ArticleService[F[_]: Monad]( )(f: (ContentTypeId, A, ArticlesQueryParameter) => Action[Seq[(Int, ResponseArticle)]]): IO[ResponseArticleWithCount] = { for { c <- contentTypeService.findByName("article").throwIfNone(NotFound(detail = "content-type not found: article")) - articlesWithCount <- transactor.transact(f(c.id, data, queryParam)) + articlesWithCount <- executer.transact(f(c.id, data, queryParam)) } yield if (articlesWithCount.nonEmpty) { ResponseArticleWithCount(articlesWithCount.map(_._1).headOption.getOrElse(0), articlesWithCount.map(_._2)) diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/authors/AuthorService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/authors/AuthorService.scala index 8e49fac7..745147f2 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/authors/AuthorService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/authors/AuthorService.scala @@ -10,7 +10,7 @@ import net.yoshinorin.qualtet.syntax.* class AuthorService[F[_]: Monad]( authorRepository: AuthorRepository[F] -)(using transactor: Executer[F, IO]) { +)(using executer: Executer[F, IO]) { def upsertActions(data: Author): Action[Int] = { Continue(authorRepository.upsert(data), Action.done[Int]) @@ -40,7 +40,7 @@ class AuthorService[F[_]: Monad]( */ def create(data: Author): IO[ResponseAuthor] = { for { - _ <- transactor.transact(upsertActions(data)) + _ <- executer.transact(upsertActions(data)) a <- this.findByName(data.name).throwIfNone(InternalServerError("user not found")) } yield a } @@ -51,7 +51,7 @@ class AuthorService[F[_]: Monad]( * @return Authors */ def getAll: IO[Seq[ResponseAuthor]] = { - transactor.transact(fetchActions) + executer.transact(fetchActions) } /** @@ -61,7 +61,7 @@ class AuthorService[F[_]: Monad]( * @return Author */ def findById(id: AuthorId): IO[Option[ResponseAuthor]] = { - transactor.transact(findByIdActions(id)) + executer.transact(findByIdActions(id)) } /** @@ -71,7 +71,7 @@ class AuthorService[F[_]: Monad]( * @return Author */ def findByIdWithPassword(id: AuthorId): IO[Option[Author]] = { - transactor.transact(findByIdWithPasswordActions(id)) + executer.transact(findByIdWithPasswordActions(id)) } /** @@ -81,7 +81,7 @@ class AuthorService[F[_]: Monad]( * @return Author */ def findByName(name: AuthorName): IO[Option[ResponseAuthor]] = { - transactor.transact(findByNameActions(name)) + executer.transact(findByNameActions(name)) } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/ContentTaggingService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/ContentTaggingService.scala index fc351076..6e807901 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/ContentTaggingService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contentTaggings/ContentTaggingService.scala @@ -10,7 +10,7 @@ import net.yoshinorin.qualtet.infrastructure.db.Executer class ContentTaggingService[F[_]: Monad]( contentTaggingRepository: ContentTaggingRepository[F] -)(using transactor: Executer[F, IO]) { +)(using executer: Executer[F, IO]) { def findByTagIdActions(id: TagId): Action[Seq[ContentTagging]] = { Continue(contentTaggingRepository.findByTagId(id), Action.done[Seq[ContentTagging]]) @@ -43,6 +43,6 @@ class ContentTaggingService[F[_]: Monad]( } def findByTagId(id: TagId): IO[Seq[ContentTagging]] = { - transactor.transact(findByTagIdActions(id)) + executer.transact(findByTagIdActions(id)) } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contentTypes/ContentTypeService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contentTypes/ContentTypeService.scala index 58881f7c..4fbe5ab3 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contentTypes/ContentTypeService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contentTypes/ContentTypeService.scala @@ -13,7 +13,7 @@ import net.yoshinorin.qualtet.syntax.* class ContentTypeService[F[_]: Monad]( contentRepository: ContentTypeRepository[F], cache: CacheModule[String, ContentType] -)(using transactor: Executer[F, IO]) +)(using executer: Executer[F, IO]) extends Cacheable { def upsertActions(data: ContentType): Action[Int] = { @@ -35,7 +35,7 @@ class ContentTypeService[F[_]: Monad]( case Some(x: ContentType) => IO(x) case None => for { - _ <- transactor.transact(upsertActions(data)) + _ <- executer.transact(upsertActions(data)) c <- this.findByName(data.name).throwIfNone(InternalServerError("contentType not found")) } yield c } @@ -56,7 +56,7 @@ class ContentTypeService[F[_]: Monad]( def fromDB(name: String): IO[Option[ContentType]] = { for { - x <- transactor.transact(actions(name)) + x <- executer.transact(actions(name)) } yield (x, cache.put(name, x))._1 } @@ -73,7 +73,7 @@ class ContentTypeService[F[_]: Monad]( * @return ContentTypes */ def getAll: IO[Seq[ContentType]] = { - transactor.transact(getAllActions) + executer.transact(getAllActions) } def invalidate(): IO[Unit] = { diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contents/ContentService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contents/ContentService.scala index 1e1f9fe4..e22761fa 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contents/ContentService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contents/ContentService.scala @@ -28,7 +28,7 @@ class ContentService[F[_]: Monad]( seriesService: SeriesService[F], contentSerializingService: ContentSerializingService[F] )(using - transactor: Executer[F, IO] + executer: Executer[F, IO] ) { def upsertActions(data: Content): Action[Int] = { @@ -124,16 +124,16 @@ class ContentService[F[_]: Monad]( val maybeExternalResources = externalResources.flatMap(a => a.values.map(v => ExternalResource(data.id, a.kind, v))) val queries = for { - contentUpsert <- transactor.perform(upsertActions(data)) - robotsUpsert <- transactor.perform(robotsService.upsertActions(Robots(data.id, robotsAttributes))) - currentTags <- transactor.perform(tagService.findByContentIdActions(data.id)) - tagsDiffDelete <- transactor.perform(contentTaggingService.bulkDeleteActions(data.id, currentTags.map(_.id).diff(tags.getOrElse(List()).map(t => t.id)))) - tagsBulkUpsert <- transactor.perform(tagService.bulkUpsertActions(tags)) + contentUpsert <- executer.perform(upsertActions(data)) + robotsUpsert <- executer.perform(robotsService.upsertActions(Robots(data.id, robotsAttributes))) + currentTags <- executer.perform(tagService.findByContentIdActions(data.id)) + tagsDiffDelete <- executer.perform(contentTaggingService.bulkDeleteActions(data.id, currentTags.map(_.id).diff(tags.getOrElse(List()).map(t => t.id)))) + tagsBulkUpsert <- executer.perform(tagService.bulkUpsertActions(tags)) // TODO: check diff and clean up contentTagging before upsert - contentTaggingBulkUpsert <- transactor.perform(contentTaggingService.bulkUpsertActions(contentTagging)) - contentSerializingUpsert <- transactor.perform(contentSerializingService.upsertActions(contentSerializing)) + contentTaggingBulkUpsert <- executer.perform(contentTaggingService.bulkUpsertActions(contentTagging)) + contentSerializingUpsert <- executer.perform(contentSerializingService.upsertActions(contentSerializing)) // TODO: check diff and clean up external_resources before upsert - externalResourceBulkUpsert <- transactor.perform(externalResourceService.bulkUpsertActions(maybeExternalResources)) + externalResourceBulkUpsert <- executer.perform(externalResourceService.bulkUpsertActions(maybeExternalResources)) } yield ( contentUpsert, currentTags, @@ -146,7 +146,7 @@ class ContentService[F[_]: Monad]( ) for { - _ <- transactor.transact8[Int, Seq[Tag], Unit, Int, Int, Int, Int, Int](queries) + _ <- executer.transact8[Int, Seq[Tag], Unit, Int, Int, Int, Int, Int](queries) c <- this.findByPath(data.path).throwIfNone(InternalServerError("content not found")) // NOTE: 404 is better? // TODO: Should return `ResponseContent` instead of `Content`. } yield c @@ -160,11 +160,11 @@ class ContentService[F[_]: Monad]( def delete(id: ContentId): IO[Unit] = { val queries = for { - externalResourcesDelete <- transactor.perform(externalResourceService.deleteActions(id)) + externalResourcesDelete <- executer.perform(externalResourceService.deleteActions(id)) // TODO: Tags should be deleted automatically after delete a content which are not refer from other contents. - contentTaggingDelete <- transactor.perform(contentTaggingService.deleteByContentIdActions(id)) - robotsDelete <- transactor.perform(robotsService.deleteActions(id)) - contentDelete <- transactor.perform(deleteActions(id)) + contentTaggingDelete <- executer.perform(contentTaggingService.deleteByContentIdActions(id)) + robotsDelete <- executer.perform(robotsService.deleteActions(id)) + contentDelete <- executer.perform(deleteActions(id)) } yield ( externalResourcesDelete, contentTaggingDelete, @@ -174,7 +174,7 @@ class ContentService[F[_]: Monad]( for { _ <- this.findById(id).throwIfNone(NotFound(detail = s"content not found: ${id}")) - _ <- transactor.transact4[Unit, Unit, Unit, Unit](queries) + _ <- executer.transact4[Unit, Unit, Unit, Unit](queries) } yield () } @@ -185,7 +185,7 @@ class ContentService[F[_]: Monad]( * @return ResponseContent instance */ def findByPath(path: Path): IO[Option[Content]] = { - transactor.transact(findByPathActions(path)) + executer.transact(findByPathActions(path)) } /** @@ -205,11 +205,11 @@ class ContentService[F[_]: Monad]( * @return ResponseContent instance */ def findById(id: ContentId): IO[Option[Content]] = { - transactor.transact(findByIdActions(id)) + executer.transact(findByIdActions(id)) } def findBy[A](data: A)(f: A => Action[Option[ReadContentDbRow]]): IO[Option[ResponseContent]] = { - transactor.transact(f(data)).flatMap { + executer.transact(f(data)).flatMap { case None => IO(None) case Some(x) => val stripedContent = x.content.stripHtmlTags.replaceAll("\n", "") diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/search/SearchService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/search/SearchService.scala index 8524710a..24623fb1 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/search/SearchService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/search/SearchService.scala @@ -17,7 +17,7 @@ import scala.annotation.tailrec class SearchService[F[_]: Monad]( searchConfig: SearchConfig, searchRepository: SearchRepository[F] -)(using transactor: Executer[F, IO]) { +)(using executer: Executer[F, IO]) { def actions(query: List[String]): Action[Seq[(Int, ResponseSearch)]] = { Continue(searchRepository.search(query), Action.done[Seq[(Int, ResponseSearch)]]) @@ -114,7 +114,7 @@ class SearchService[F[_]: Monad]( _ <- IO(if (accErrors.nonEmpty) { throw new UnprocessableEntity(detail = "Invalid search conditions. Please see error details.", errors = Some(accErrors)) }) - searchResult <- transactor.transact(actions(queryStrings)) + searchResult <- executer.transact(actions(queryStrings)) } yield if (searchResult.nonEmpty) { val r = searchResult.map { x => diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala index 08d3a2ef..8c4ed107 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala @@ -13,7 +13,7 @@ import wvlet.airframe.ulid.ULID class SeriesService[F[_]: Monad]( seriesRepository: SeriesRepository[F], articleService: ArticleService[F] -)(using transactor: Executer[F, IO]) { +)(using executer: Executer[F, IO]) { def upsertActions(data: Series): Action[Int] = { Continue(seriesRepository.upsert(data), Action.done[Int]) @@ -37,12 +37,12 @@ class SeriesService[F[_]: Monad]( this.findByName(data.name).flatMap { case Some(s: Series) => for { - _ <- transactor.transact(upsertActions(Series(s.id, s.name, data.title, data.description))) + _ <- executer.transact(upsertActions(Series(s.id, s.name, data.title, data.description))) s <- this.findByName(data.name).throwIfNone(NotFound(detail = "series not found")) } yield s case None => for { - _ <- transactor.transact(upsertActions(Series(SeriesId(ULID.newULIDString.toLower), data.name, data.title, data.description))) + _ <- executer.transact(upsertActions(Series(SeriesId(ULID.newULIDString.toLower), data.name, data.title, data.description))) s <- this.findByName(data.name).throwIfNone(NotFound(detail = "series not found")) } yield s } @@ -55,12 +55,12 @@ class SeriesService[F[_]: Monad]( * @return Series Instance */ def findByName(name: SeriesName): IO[Option[Series]] = { - transactor.transact(findByNameActions(name)) + executer.transact(findByNameActions(name)) } def get(name: SeriesName): IO[ResponseSeries] = { for { - series <- transactor.transact(findByNameActions(name)).throwIfNone(NotFound(detail = s"series not found: ${name.value}")) + series <- executer.transact(findByNameActions(name)).throwIfNone(NotFound(detail = s"series not found: ${name.value}")) seriesWithArticles <- articleService.getBySeriesName(series.name) } yield { ResponseSeries(series.id, series.name, series.title, series.description, seriesWithArticles.articles) @@ -73,7 +73,7 @@ class SeriesService[F[_]: Monad]( * @return Series */ def getAll: IO[Seq[Series]] = { - transactor.transact(fetchActions) + executer.transact(fetchActions) } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/sitemaps/SitemapService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/sitemaps/SitemapService.scala index 2f9cf367..f8ac0083 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/sitemaps/SitemapService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/sitemaps/SitemapService.scala @@ -11,7 +11,7 @@ import net.yoshinorin.qualtet.domains.Cacheable class SitemapService[F[_]: Monad]( sitemapRepository: SitemapsRepository[F], cache: CacheModule[String, Seq[Url]] -)(using transactor: Executer[F, IO]) +)(using executer: Executer[F, IO]) extends Cacheable { private val cacheKey = "sitemaps-full-cache" @@ -25,7 +25,7 @@ class SitemapService[F[_]: Monad]( case Some(x: Seq[Url]) => IO(x) case _ => for { - x <- transactor.transact(getActions) + x <- executer.transact(getActions) } yield (x, cache.put(cacheKey, x))._1 } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/tags/TagService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/tags/TagService.scala index 62b7d438..fe3736f1 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/tags/TagService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/tags/TagService.scala @@ -14,7 +14,7 @@ import net.yoshinorin.qualtet.syntax.* class TagService[F[_]: Monad]( tagRepository: TagRepository[F], contentTaggingService: ContentTaggingService[F] -)(using transactor: Executer[F, IO]) { +)(using executer: Executer[F, IO]) { def bulkUpsertActions(data: Option[List[Tag]]): Action[Int] = { data match { @@ -49,7 +49,7 @@ class TagService[F[_]: Monad]( * @return tags */ def getAll: IO[Seq[ResponseTag]] = { - transactor.transact(getAllActions) + executer.transact(getAllActions) } /** @@ -59,7 +59,7 @@ class TagService[F[_]: Monad]( * @return maybe Tag */ def findById(id: TagId): IO[Option[Tag]] = { - transactor.transact(findByIdActions(id)) + executer.transact(findByIdActions(id)) } /** @@ -69,7 +69,7 @@ class TagService[F[_]: Monad]( * @return maybe Tag */ def findByName(tagName: TagName): IO[Option[Tag]] = { - transactor.transact(findByNameActions(tagName)) + executer.transact(findByNameActions(tagName)) } /** @@ -105,13 +105,13 @@ class TagService[F[_]: Monad]( */ def delete(id: TagId): IO[Unit] = { val queries = for { - contentTaggingDelete <- transactor.perform(contentTaggingService.deleteByTagIdActions(id)) - tagDelete <- transactor.perform(deleteActions(id)) + contentTaggingDelete <- executer.perform(contentTaggingService.deleteByTagIdActions(id)) + tagDelete <- executer.perform(deleteActions(id)) } yield (contentTaggingDelete, tagDelete) for { _ <- this.findById(id).throwIfNone(NotFound(detail = s"tag not found: ${id}")) - _ <- transactor.transact2(queries) + _ <- executer.transact2(queries) } yield () } }