Skip to content

Commit

Permalink
refactor: use F[_] instead of M[_] for Higher-Kinded Types
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Nov 28, 2023
1 parent 2dd0778 commit 7a6cb89
Show file tree
Hide file tree
Showing 46 changed files with 180 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import net.yoshinorin.qualtet.message.Fail.{NotFound, Unauthorized}
import net.yoshinorin.qualtet.syntax.*
import org.slf4j.LoggerFactory

class AuthService[M[_]: Monad](authorService: AuthorService[M], jwt: Jwt) {
class AuthService[F[_]: Monad](authorService: AuthorService[F], jwt: Jwt) {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private[this] val bcryptPasswordEncoder = new BCryptPasswordEncoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import net.yoshinorin.qualtet.domains.contentTypes.ContentTypeService
import net.yoshinorin.qualtet.domains.feeds.FeedService
import org.slf4j.LoggerFactory

class CacheService[M[_]: Monad](
sitemapService: SitemapService[M],
contentTypeService: ContentTypeService[M],
feedService: FeedService[M]
class CacheService[F[_]: Monad](
sitemapService: SitemapService[F],
contentTypeService: ContentTypeService[F],
feedService: FeedService[F]
) {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package net.yoshinorin.qualtet.domains.archives

import net.yoshinorin.qualtet.domains.contentTypes.ContentTypeId

trait ArchiveRepository[M[_]] {
def get(contentTypeId: ContentTypeId): M[Seq[ResponseArchive]]
trait ArchiveRepository[F[_]] {
def get(contentTypeId: ContentTypeId): F[Seq[ResponseArchive]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import net.yoshinorin.qualtet.domains.contentTypes.ContentTypeId
import net.yoshinorin.qualtet.syntax.*
import cats.Monad

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

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 @@ -5,8 +5,8 @@ import net.yoshinorin.qualtet.domains.series.SeriesName
import net.yoshinorin.qualtet.domains.tags.TagName
import net.yoshinorin.qualtet.http.QueryParametersAliases.SqlParams

trait ArticleRepository[M[_]] {
def getWithCount(contentTypeId: ContentTypeId, sqlParams: SqlParams): M[Seq[(Int, ResponseArticle)]]
def findByTagNameWithCount(contentTypeId: ContentTypeId, tagName: TagName, sqlParams: SqlParams): M[Seq[(Int, ResponseArticle)]]
def findBySeriesNameWithCount(contentTypeId: ContentTypeId, seriesName: SeriesName): M[Seq[(Int, ResponseArticle)]]
trait ArticleRepository[F[_]] {
def getWithCount(contentTypeId: ContentTypeId, sqlParams: SqlParams): F[Seq[(Int, ResponseArticle)]]
def findByTagNameWithCount(contentTypeId: ContentTypeId, tagName: TagName, sqlParams: SqlParams): F[Seq[(Int, ResponseArticle)]]
def findBySeriesNameWithCount(contentTypeId: ContentTypeId, seriesName: SeriesName): F[Seq[(Int, ResponseArticle)]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import net.yoshinorin.qualtet.http.ArticlesQueryParameter
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.syntax.*

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

def actions(
contentTypeId: ContentTypeId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
package net.yoshinorin.qualtet.domains.authors

trait AuthorRepository[M[_]] {
trait AuthorRepository[F[_]] {

/**
* get all Author
*
* @return Authors
*/
def getAll(): M[Seq[ResponseAuthor]]
def getAll(): F[Seq[ResponseAuthor]]

/**
* create a authorName
*
* @param data Instance of Author
* @return dummy long id (Doobie return Int)
*/
def upsert(data: Author): M[Int]
def upsert(data: Author): F[Int]

/**
* find a Author by id
*
* @param id authorName's id
* @return Author
*/
def findById(id: AuthorId): M[Option[ResponseAuthor]]
def findById(id: AuthorId): F[Option[ResponseAuthor]]

/**
* find a Author by id
*
* @param id authorName's id
* @return Author
*/
def findByIdWithPassword(id: AuthorId): M[Option[Author]]
def findByIdWithPassword(id: AuthorId): F[Option[Author]]

/**
* find a Author by name
*
* @param name authorName's name
* @return Author
*/
def findByName(name: AuthorName): M[Option[ResponseAuthor]]
def findByName(name: AuthorName): F[Option[ResponseAuthor]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import net.yoshinorin.qualtet.actions.Action.*
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.syntax.*

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

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 @@ -3,14 +3,14 @@ package net.yoshinorin.qualtet.domains.contentSerializing
import net.yoshinorin.qualtet.domains.contents.ContentId
import net.yoshinorin.qualtet.domains.series.SeriesId

trait ContentSerializingRepository[M[_]] {
def upsert(data: ContentSerializing): M[Int]
def bulkUpsert(data: List[ContentSerializing]): M[Int]
def findBySeriesId(id: SeriesId): M[Seq[ContentSerializing]]
def deleteBySeriesId(id: SeriesId): M[Unit]
def deleteByContentId(id: ContentId): M[Unit]
def delete(seriesId: SeriesId, contentIds: Seq[ContentId]): M[Unit]
trait ContentSerializingRepository[F[_]] {
def upsert(data: ContentSerializing): F[Int]
def bulkUpsert(data: List[ContentSerializing]): F[Int]
def findBySeriesId(id: SeriesId): F[Seq[ContentSerializing]]
def deleteBySeriesId(id: SeriesId): F[Unit]
def deleteByContentId(id: ContentId): F[Unit]
def delete(seriesId: SeriesId, contentIds: Seq[ContentId]): F[Unit]
// TODO: generics
def fakeRequestInt: M[Int]
def fakeRequestUnit: M[Unit]
def fakeRequestInt: F[Int]
def fakeRequestUnit: F[Unit]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.domains.contents.ContentId
import net.yoshinorin.qualtet.domains.series.SeriesId

class ContentSerializingService[M[_]: Monad](
contentSerializingRepository: ContentSerializingRepository[M]
class ContentSerializingService[F[_]: Monad](
contentSerializingRepository: ContentSerializingRepository[F]
) {

def findBySeriesIdActions(id: SeriesId): Action[Seq[ContentSerializing]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package net.yoshinorin.qualtet.domains.contentTaggings
import net.yoshinorin.qualtet.domains.contents.ContentId
import net.yoshinorin.qualtet.domains.tags.TagId

trait ContentTaggingRepository[M[_]] {
def bulkUpsert(data: List[ContentTagging]): M[Int]
def findByTagId(id: TagId): M[Seq[ContentTagging]]
def deleteByContentId(id: ContentId): M[Unit]
def deleteByTagId(id: TagId): M[Unit]
def delete(contentId: ContentId, tagIds: Seq[TagId]): M[Unit]
trait ContentTaggingRepository[F[_]] {
def bulkUpsert(data: List[ContentTagging]): F[Int]
def findByTagId(id: TagId): F[Seq[ContentTagging]]
def deleteByContentId(id: ContentId): F[Unit]
def deleteByTagId(id: TagId): F[Unit]
def delete(contentId: ContentId, tagIds: Seq[TagId]): F[Unit]
// TODO: generics
def fakeRequestInt: M[Int]
def fakeRequestUnit: M[Unit]
def fakeRequestInt: F[Int]
def fakeRequestUnit: F[Unit]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import net.yoshinorin.qualtet.domains.contents.ContentId
import net.yoshinorin.qualtet.domains.tags.TagId
import net.yoshinorin.qualtet.infrastructure.db.Transactor

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

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
@@ -1,7 +1,7 @@
package net.yoshinorin.qualtet.domains.contentTypes

trait ContentTypeRepository[M[_]] {
def upsert(data: ContentType): M[Int]
def getAll(): M[Seq[ContentType]]
def findByName(name: String): M[Option[ContentType]]
trait ContentTypeRepository[F[_]] {
def upsert(data: ContentType): F[Int]
def getAll(): F[Seq[ContentType]]
def findByName(name: String): F[Option[ContentType]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import net.yoshinorin.qualtet.domains.Cacheable
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.syntax.*

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

def upsertActions(data: ContentType): Action[Int] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package net.yoshinorin.qualtet.domains.contents

import net.yoshinorin.qualtet.domains.contents.{ContentId, Path}

trait ContentRepository[M[_]] {
def upsert(data: Content): M[Int]
def findById(id: ContentId): M[Option[Content]]
def findByPath(path: Path): M[Option[Content]]
def findByPathWithMeta(path: Path): M[Option[ResponseContentDbRow]]
def delete(id: ContentId): M[Unit]
trait ContentRepository[F[_]] {
def upsert(data: Content): F[Int]
def findById(id: ContentId): F[Option[Content]]
def findByPath(path: Path): F[Option[Content]]
def findByPathWithMeta(path: Path): F[Option[ResponseContentDbRow]]
def delete(id: ContentId): F[Unit]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ import net.yoshinorin.qualtet.domains.series.{Series, SeriesName, SeriesService}
import net.yoshinorin.qualtet.infrastructure.db.Transactor
import net.yoshinorin.qualtet.syntax.*

class ContentService[M[_]: Monad](
contentRepository: ContentRepository[M],
tagService: TagService[M],
contentTaggingService: ContentTaggingService[M],
robotsService: RobotsService[M],
externalResourceService: ExternalResourceService[M],
authorService: AuthorService[M],
contentTypeService: ContentTypeService[M],
seriesService: SeriesService[M],
contentSerializingService: ContentSerializingService[M]
class ContentService[F[_]: Monad](
contentRepository: ContentRepository[F],
tagService: TagService[F],
contentTaggingService: ContentTaggingService[F],
robotsService: RobotsService[F],
externalResourceService: ExternalResourceService[F],
authorService: AuthorService[F],
contentTypeService: ContentTypeService[F],
seriesService: SeriesService[F],
contentSerializingService: ContentSerializingService[F]
)(using
transactor: Transactor[M]
transactor: Transactor[F]
) {

def upsertActions(data: Content): Action[Int] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package net.yoshinorin.qualtet.domains.externalResources

import net.yoshinorin.qualtet.domains.contents.ContentId

trait ExternalResourceRepository[M[_]] {
def bulkUpsert(data: List[ExternalResource]): M[Int]
def delete(contentId: ContentId): M[Unit]
def fakeRequest(): M[Int]
trait ExternalResourceRepository[F[_]] {
def bulkUpsert(data: List[ExternalResource]): F[Int]
def delete(contentId: ContentId): F[Unit]
def fakeRequest(): F[Int]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import cats.Monad
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.domains.contents.ContentId

class ExternalResourceService[M[_]: Monad](
externalResourceRepository: ExternalResourceRepository[M]
class ExternalResourceService[F[_]: Monad](
externalResourceRepository: ExternalResourceRepository[F]
) {

def bulkUpsertActions(data: List[ExternalResource]): Action[Int] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import net.yoshinorin.qualtet.http.ArticlesQueryParameter
import net.yoshinorin.qualtet.domains.articles.ResponseArticleWithCount
import net.yoshinorin.qualtet.domains.Cacheable

class FeedService[M[_]: Monad](
class FeedService[F[_]: Monad](
cache: CacheModule[String, ResponseArticleWithCount],
articleService: ArticleService[M]
articleService: ArticleService[F]
) extends Cacheable {

private val cacheKey = "feed-full-cache"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.yoshinorin.qualtet.domains.robots

import net.yoshinorin.qualtet.domains.contents.ContentId

trait RobotsRepository[M[_]] {
def upsert(data: Robots): M[Int]
def delete(contentId: ContentId): M[Unit]
trait RobotsRepository[F[_]] {
def upsert(data: Robots): F[Int]
def delete(contentId: ContentId): F[Unit]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import cats.Monad
import net.yoshinorin.qualtet.actions.{Action, Continue}
import net.yoshinorin.qualtet.domains.contents.ContentId

class RobotsService[M[_]: Monad](
robotsRepository: RobotsRepository[M]
class RobotsService[F[_]: Monad](
robotsRepository: RobotsRepository[F]
) {
def upsertActions(data: Robots): Action[Int] = {
Continue(robotsRepository.upsert(data), Action.done[Int])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package net.yoshinorin.qualtet.domains.search

trait SearchRepository[M[_]] {
def search(query: List[String]): M[Seq[(Int, ResponseSearch)]]
trait SearchRepository[F[_]] {
def search(query: List[String]): F[Seq[(Int, ResponseSearch)]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import net.yoshinorin.qualtet.syntax.*

import scala.annotation.tailrec

class SearchService[M[_]: Monad](
class SearchService[F[_]: Monad](
searchConfig: SearchConfig,
searchRepository: SearchRepository[M]
)(using transactor: Transactor[M]) {
searchRepository: SearchRepository[F]
)(using transactor: Transactor[F]) {

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
@@ -1,7 +1,7 @@
package net.yoshinorin.qualtet.domains.series

trait SeriesRepository[M[_]] {
def upsert(data: Series): M[Int]
def findByName(name: SeriesName): M[Option[Series]]
def getAll(): M[Seq[Series]]
trait SeriesRepository[F[_]] {
def upsert(data: Series): F[Int]
def findByName(name: SeriesName): F[Option[Series]]
def getAll(): F[Seq[Series]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import net.yoshinorin.qualtet.message.Fail.NotFound
import net.yoshinorin.qualtet.syntax.*
import wvlet.airframe.ulid.ULID

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

def upsertActions(data: Series): Action[Int] = {
Continue(seriesRepository.upsert(data), Action.done[Int])
Expand Down
Loading

0 comments on commit 7a6cb89

Please sign in to comment.