Skip to content

Commit

Permalink
refactor(model/content): rename from ReadContentDbRow to `ContentRe…
Browse files Browse the repository at this point in the history
…adModel`
  • Loading branch information
yoshinorin committed Nov 5, 2024
1 parent d7c6b7e commit ab86388
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ object ResponseContent {
)
given codecResponseContents: JsonValueCodec[Seq[ResponseContent]] = JsonCodecMaker.make
}
final case class ReadContentDbRow(

final case class ContentReadModel(
id: ContentId,
title: String,
robotsAttributes: Attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ContentService[F[_]: Monad](
}
}

def findByPathWithMetaCont(path: Path): ContT[F, Option[ReadContentDbRow], Option[ReadContentDbRow]] = {
ContT.apply[F, Option[ReadContentDbRow], Option[ReadContentDbRow]] { next =>
def findByPathWithMetaCont(path: Path): ContT[F, Option[ContentReadModel], Option[ContentReadModel]] = {
ContT.apply[F, Option[ContentReadModel], Option[ContentReadModel]] { next =>
contentRepository.findByPathWithMeta(path)
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ class ContentService[F[_]: Monad](
executer.transact(findByIdCont(id))
}

def findBy[A](data: A)(f: A => ContT[F, Option[ReadContentDbRow], Option[ReadContentDbRow]]): IO[Option[ResponseContent]] = {
def findBy[A](data: A)(f: A => ContT[F, Option[ContentReadModel], Option[ContentReadModel]]): IO[Option[ResponseContent]] = {
executer.transact(f(data)).flatMap {
case None => IO(None)
case Some(x) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ContentQuery {
.query[Content]
}

def findByPathWithMeta(path: Path): Read[ReadContentDbRow] ?=> Query0[ReadContentDbRow] = {
def findByPathWithMeta(path: Path): Read[ContentReadModel] ?=> Query0[ContentReadModel] = {
sql"""
SELECT
contents.id AS id,
Expand Down Expand Up @@ -67,7 +67,7 @@ object ContentQuery {
HAVING
COUNT(*) > 0
"""
.query[ReadContentDbRow]
.query[ContentReadModel]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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[ReadContentDbRow]]
def findByPathWithMeta(path: Path): F[Option[ContentReadModel]]
def delete(id: ContentId): F[Unit]
}

Expand Down Expand Up @@ -54,7 +54,7 @@ object ContentRepository {
)
}

given contentDbRawRead: Read[ReadContentDbRow] =
given contentDbRawRead: Read[ContentReadModel] =
Read[(String, String, String, Option[String], Option[String], Option[String], Option[String], String, String, Long, Long)].map {
case (
id,
Expand All @@ -69,7 +69,7 @@ object ContentRepository {
publishedAt,
updatedAt
) =>
ReadContentDbRow(
ContentReadModel(
ContentId(id),
title,
Attributes(robotsAttributes),
Expand Down Expand Up @@ -109,7 +109,7 @@ object ContentRepository {
override def findByPath(path: Path): ConnectionIO[Option[Content]] = {
ContentQuery.findByPath(path).option
}
override def findByPathWithMeta(path: Path): ConnectionIO[Option[ReadContentDbRow]] = {
override def findByPathWithMeta(path: Path): ConnectionIO[Option[ContentReadModel]] = {
// NOTE: use `.option` instead of `.query[Option[T]].unique`
// https://stackoverflow.com/questions/57873699/sql-null-read-at-column-1-jdbc-type-null-but-mapping-is-to-a-non-option-type
ContentQuery.findByPathWithMeta(path).option
Expand Down

0 comments on commit ab86388

Please sign in to comment.