diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contents/Content.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contents/Content.scala index 913e406e..27373048 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contents/Content.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contents/Content.scala @@ -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, 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 f710aee3..37aa78e1 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contents/ContentService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contents/ContentService.scala @@ -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) } } @@ -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) => diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala index 822ae5ac..e25ad127 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentQuery.scala @@ -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, @@ -67,7 +67,7 @@ object ContentQuery { HAVING COUNT(*) > 0 """ - .query[ReadContentDbRow] + .query[ContentReadModel] } } diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala index a24b9f80..c9b50de1 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/contents/repositories/ContentRepository.scala @@ -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] } @@ -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, @@ -69,7 +69,7 @@ object ContentRepository { publishedAt, updatedAt ) => - ReadContentDbRow( + ContentReadModel( ContentId(id), title, Attributes(robotsAttributes), @@ -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