From d3eb581d94732c01bcbb201b1738e395c5fe565f Mon Sep 17 00:00:00 2001 From: jini Date: Tue, 7 Mar 2023 21:18:07 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20datastore-mariadb-reactive=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../build.gradle.kts | 11 ++++++++ .../demohx/persistence/notice/NoticeEntity.kt | 27 +++++++++++++++++++ .../notice/NoticePersistenceAdapter.kt | 21 +++++++++++++++ .../persistence/notice/NoticeRepository.kt | 11 ++++++++ settings.gradle.kts | 9 +++---- 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 infrastructure/datastore-mariadb-reactive/build.gradle.kts create mode 100644 infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeEntity.kt create mode 100644 infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticePersistenceAdapter.kt create mode 100644 infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeRepository.kt diff --git a/infrastructure/datastore-mariadb-reactive/build.gradle.kts b/infrastructure/datastore-mariadb-reactive/build.gradle.kts new file mode 100644 index 0000000..0aac8f9 --- /dev/null +++ b/infrastructure/datastore-mariadb-reactive/build.gradle.kts @@ -0,0 +1,11 @@ +dependencies { + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("io.projectreactor.kotlin:reactor-kotlin-extensions") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") + + implementation("org.springframework.boot:spring-boot-starter-data-r2dbc") + runtimeOnly("org.mariadb:r2dbc-mariadb:1.1.3") + + implementation(project(":util:common-util")) + implementation(project(":core:demo-reactive-core")) +} \ No newline at end of file diff --git a/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeEntity.kt b/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeEntity.kt new file mode 100644 index 0000000..713b722 --- /dev/null +++ b/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeEntity.kt @@ -0,0 +1,27 @@ +package me.jiniworld.demohx.persistence.notice + +import me.jiniworld.demohx.application.notice.domain.Notice +import org.springframework.data.annotation.CreatedDate +import org.springframework.data.annotation.Id +import org.springframework.data.annotation.LastModifiedDate +import org.springframework.data.relational.core.mapping.Table +import java.time.LocalDateTime + +@Table("notice") +internal class NoticeDocument { + @Id + var id: String = "" + + var title: String = "" + + var content: String = "" + + @CreatedDate + var createdAt: LocalDateTime = LocalDateTime.now() + + @LastModifiedDate + var updatedAt: LocalDateTime? = null + + fun mapToNotice() = + Notice(id = id, title = title, content = content, createdAt = createdAt) +} \ No newline at end of file diff --git a/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticePersistenceAdapter.kt b/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticePersistenceAdapter.kt new file mode 100644 index 0000000..78db876 --- /dev/null +++ b/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticePersistenceAdapter.kt @@ -0,0 +1,21 @@ +package me.jiniworld.demohx.persistence.notice + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import me.jiniworld.demohx.annotation.PersistenceAdapter +import me.jiniworld.demohx.application.notice.domain.Notice +import me.jiniworld.demohx.application.notice.port.output.LoadNoticePort +import org.springframework.data.domain.Pageable + +@PersistenceAdapter +internal class NoticePersistenceAdapter( + private val noticeRepository: NoticeRepository, +) : LoadNoticePort { + override fun loadNotices(pageable: Pageable): Flow { + return noticeRepository.findAllBy(pageable).map { it.mapToNotice() } + } + + override suspend fun loadNotice(id: String): Notice? { + return noticeRepository.findById(id)?.mapToNotice() + } +} \ No newline at end of file diff --git a/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeRepository.kt b/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeRepository.kt new file mode 100644 index 0000000..15fa8c4 --- /dev/null +++ b/infrastructure/datastore-mariadb-reactive/src/main/kotlin/me/jiniworld/demohx/persistence/notice/NoticeRepository.kt @@ -0,0 +1,11 @@ +package me.jiniworld.demohx.persistence.notice + +import kotlinx.coroutines.flow.Flow +import org.springframework.data.domain.Pageable +import org.springframework.data.repository.kotlin.CoroutineCrudRepository +import org.springframework.stereotype.Repository + +@Repository +internal interface NoticeRepository: CoroutineCrudRepository { + fun findAllBy(pageable: Pageable): Flow +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index d26287f..416c1a1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,13 +3,12 @@ rootProject.name = "demo-hexagonal" include( "core:demo-core", + "core:demo-reactive-core", "infrastructure:datastore-mariadb", "infrastructure:datastore-mongodb-reactive", + "infrastructure:datastore-mariadb-reactive", "server:demo-app", + "server:demo-reactive-app", "util:common-util", "server:demo-all-in-one-app" -) -include("server:demo-reactive-app") -findProject(":server:demo-reactive-app")?.name = "demo-reactive-app" -include("core:demo-reactive-core") -findProject(":core:demo-reactive-core")?.name = "demo-reactive-core" +) \ No newline at end of file