From de3e7884af947596eb6f0b484ccb1fe7abe27555 Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 12 Dec 2023 09:52:15 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:sparkles:=20ParticipantDao=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nito/core/database/di/DatabaseModule.kt | 6 ++ .../database/participant/ParticipantDao.kt | 32 ++++++++++ .../participant/SqlDelightParticipantDao.kt | 63 +++++++++++++++++++ .../adapter/ParticipantStatus.kt | 2 +- .../participant/model/LocalParticipant.kt | 24 +++++++ .../club/nito/core/database/Participants.sq | 21 +++++-- .../domain/extension/ParticipantExtensions.kt | 2 +- .../core/domain/model/ParticipantSchedule.kt | 1 + .../model/participant}/ParticipantUser.kt | 3 +- .../nito/core/ui/ParticipantScheduleItem.kt | 4 +- .../schedule/detail/ScheduleDetailIntent.kt | 2 +- .../schedule/detail/ScheduleDetailScreen.kt | 2 +- 12 files changed, 150 insertions(+), 12 deletions(-) create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/participant/ParticipantDao.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/participant/SqlDelightParticipantDao.kt rename core/database/src/commonMain/kotlin/club/nito/core/database/{ => participant}/adapter/ParticipantStatus.kt (87%) create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/participant/model/LocalParticipant.kt rename core/{domain/src/commonMain/kotlin/club/nito/core/domain/model => model/src/commonMain/kotlin/club/nito/core/model/participant}/ParticipantUser.kt (91%) diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt index d0f557b7..613691e4 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt @@ -2,8 +2,12 @@ package club.nito.core.database.di import club.nito.core.database.DriverFactory import club.nito.core.database.createDatabase +import club.nito.core.database.participant.ParticipantDao +import club.nito.core.database.participant.SqlDelightParticipantDao import org.koin.core.module.Module +import org.koin.core.module.dsl.singleOf import org.koin.core.scope.Scope +import org.koin.dsl.bind import org.koin.dsl.module public val databaseModule: Module = module { @@ -12,6 +16,8 @@ public val databaseModule: Module = module { driverFactory = createDriverFactory(), ) } + + singleOf(::SqlDelightParticipantDao) bind ParticipantDao::class } internal expect fun Scope.createDriverFactory(): DriverFactory diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/participant/ParticipantDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/ParticipantDao.kt new file mode 100644 index 00000000..cd03daa3 --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/ParticipantDao.kt @@ -0,0 +1,32 @@ +package club.nito.core.database.participant + +import club.nito.core.model.participant.Participant +import club.nito.core.model.participant.ParticipantStatus +import club.nito.core.model.participant.ParticipantUser +import kotlinx.coroutines.flow.Flow + +public interface ParticipantDao { + /** + * 該当の予定の参加情報のストリームを取得する + * + * @param scheduleId 参加情報を取得するスケジュールID + */ + public fun participantUsersStream(scheduleId: String): Flow> + + /** + * 該当の予定の参加情報のストリームを取得する + * + * @param scheduleId 参加情報を取得するスケジュールID + */ + public fun participantStatusStream(scheduleId: String, userId: String): Flow + + /** + * 参加者を登録 / 更新する + */ + public fun upsert(entities: List) + + /** + * 参加者を登録 / 更新する + */ + public fun upsert(entity: Participant) +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/participant/SqlDelightParticipantDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/SqlDelightParticipantDao.kt new file mode 100644 index 00000000..c4c4ca5b --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/SqlDelightParticipantDao.kt @@ -0,0 +1,63 @@ +package club.nito.core.database.participant + +import app.cash.sqldelight.coroutines.asFlow +import app.cash.sqldelight.coroutines.mapToList +import app.cash.sqldelight.coroutines.mapToOneOrNull +import club.nito.core.common.NitoCoroutineDispatchers +import club.nito.core.database.Database +import club.nito.core.database.ParticipantUsersByScheduleId +import club.nito.core.database.participant.model.toModel +import club.nito.core.model.participant.Participant +import club.nito.core.model.participant.ParticipantStatus +import club.nito.core.model.participant.ParticipantUser +import club.nito.core.model.schedule.ScheduleId +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +internal class SqlDelightParticipantDao( + private val database: Database, + private val dispatchers: NitoCoroutineDispatchers, +) : ParticipantDao { + override fun participantUsersStream(scheduleId: ScheduleId): Flow> { + return database.participantsQueries.participantUsersByScheduleId(scheduleId) + .asFlow() + .mapToList(dispatchers.io) + .map { + it.map(ParticipantUsersByScheduleId::toModel) + } + } + + override fun participantStatusStream(scheduleId: String, userId: String): Flow = database + .participantsQueries + .participantStatusByUserId( + schedule_id = scheduleId, + user_id = userId, + ) + .asFlow() + .mapToOneOrNull(dispatchers.io) + .map { + it ?: ParticipantStatus.NONE + } + + override fun upsert(entities: List) { + database.transaction { + for (entity in entities) { + upsertParticipant(entity) + } + } + } + + override fun upsert(entity: Participant) { + database.transaction { + upsertParticipant(entity) + } + } + + private fun upsertParticipant(entity: Participant) { + database.participantsQueries.upsert( + schedule_id = entity.scheduleId, + user_id = entity.userId, + status = entity.status, + ) + } +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/adapter/ParticipantStatus.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/adapter/ParticipantStatus.kt similarity index 87% rename from core/database/src/commonMain/kotlin/club/nito/core/database/adapter/ParticipantStatus.kt rename to core/database/src/commonMain/kotlin/club/nito/core/database/participant/adapter/ParticipantStatus.kt index c7603e72..5b07882f 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/adapter/ParticipantStatus.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/adapter/ParticipantStatus.kt @@ -1,4 +1,4 @@ -package club.nito.core.database.adapter +package club.nito.core.database.participant.adapter import app.cash.sqldelight.ColumnAdapter import club.nito.core.model.participant.ParticipantStatus diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/participant/model/LocalParticipant.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/model/LocalParticipant.kt new file mode 100644 index 00000000..7ec0b735 --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/participant/model/LocalParticipant.kt @@ -0,0 +1,24 @@ +package club.nito.core.database.participant.model + +import club.nito.core.model.UserProfile +import club.nito.core.model.participant.Participant +import club.nito.core.model.participant.ParticipantUser +import club.nito.core.database.ParticipantUsersByScheduleId as LocalParticipantUser +import club.nito.core.database.Participants as LocalParticipant + +internal fun LocalParticipant.toModel(): Participant = Participant( + scheduleId = schedule_id, + userId = user_id, + status = status, +) + +internal fun LocalParticipantUser.toModel(): ParticipantUser = ParticipantUser( + profile = UserProfile( + id = id, + username = username, + displayName = display_name, + avatarUrl = avatar_url, + website = website, + ), + status = status, +) diff --git a/core/database/src/commonMain/sqldelight/club/nito/core/database/Participants.sq b/core/database/src/commonMain/sqldelight/club/nito/core/database/Participants.sq index 80eb56bd..09b05fce 100644 --- a/core/database/src/commonMain/sqldelight/club/nito/core/database/Participants.sq +++ b/core/database/src/commonMain/sqldelight/club/nito/core/database/Participants.sq @@ -1,12 +1,12 @@ import club.nito.core.model.participant.ParticipantStatus; -CREATE TABLE `participants` ( +CREATE TABLE IF NOT EXISTS `participants` ( `schedule_id` TEXT NOT NULL, `user_id` TEXT NOT NULL, `status` TEXT AS ParticipantStatus NOT NULL ); -CREATE UNIQUE INDEX `participants_pkey` ON `participants` (`schedule_id`, `user_id`); +CREATE UNIQUE INDEX IF NOT EXISTS `participants_pkey` ON `participants` (`schedule_id`, `user_id`); participantsByScheduleId: SELECT * @@ -18,10 +18,23 @@ SELECT * FROM participants WHERE user_id = ?; +participantStatusByUserId: +SELECT status +FROM participants +WHERE schedule_id = :schedule_id AND user_id = :user_id; + +participantUsersByScheduleId: +SELECT participants.status, profiles.* FROM participants +INNER JOIN profiles ON participants.user_id = profiles.id +WHERE participants.schedule_id = :schedule_id; + +participantUsersByScheduleIds: +SELECT participants.status, profiles.* FROM participants +INNER JOIN profiles ON participants.user_id = profiles.id +WHERE participants.schedule_id IN :schedule_id; + upsert { UPDATE participants SET - `schedule_id` = :schedule_id, - `user_id` = :user_id, `status` = :status WHERE schedule_id = :schedule_id AND user_id = :user_id; diff --git a/core/domain/src/commonMain/kotlin/club/nito/core/domain/extension/ParticipantExtensions.kt b/core/domain/src/commonMain/kotlin/club/nito/core/domain/extension/ParticipantExtensions.kt index 2e454381..9aa954dc 100644 --- a/core/domain/src/commonMain/kotlin/club/nito/core/domain/extension/ParticipantExtensions.kt +++ b/core/domain/src/commonMain/kotlin/club/nito/core/domain/extension/ParticipantExtensions.kt @@ -1,6 +1,6 @@ package club.nito.core.domain.extension -import club.nito.core.domain.model.ParticipantUser +import club.nito.core.model.participant.ParticipantUser import club.nito.core.model.UserProfile import club.nito.core.model.participant.Participant diff --git a/core/domain/src/commonMain/kotlin/club/nito/core/domain/model/ParticipantSchedule.kt b/core/domain/src/commonMain/kotlin/club/nito/core/domain/model/ParticipantSchedule.kt index 4184eabb..d8554f30 100644 --- a/core/domain/src/commonMain/kotlin/club/nito/core/domain/model/ParticipantSchedule.kt +++ b/core/domain/src/commonMain/kotlin/club/nito/core/domain/model/ParticipantSchedule.kt @@ -1,5 +1,6 @@ package club.nito.core.domain.model +import club.nito.core.model.participant.ParticipantUser import club.nito.core.model.place.Place import club.nito.core.model.schedule.ScheduleId import kotlinx.datetime.Instant diff --git a/core/domain/src/commonMain/kotlin/club/nito/core/domain/model/ParticipantUser.kt b/core/model/src/commonMain/kotlin/club/nito/core/model/participant/ParticipantUser.kt similarity index 91% rename from core/domain/src/commonMain/kotlin/club/nito/core/domain/model/ParticipantUser.kt rename to core/model/src/commonMain/kotlin/club/nito/core/model/participant/ParticipantUser.kt index 173dc303..b70d6fdb 100644 --- a/core/domain/src/commonMain/kotlin/club/nito/core/domain/model/ParticipantUser.kt +++ b/core/model/src/commonMain/kotlin/club/nito/core/model/participant/ParticipantUser.kt @@ -1,7 +1,6 @@ -package club.nito.core.domain.model +package club.nito.core.model.participant import club.nito.core.model.UserProfile -import club.nito.core.model.participant.ParticipantStatus /** * 参加ユーザー diff --git a/core/ui/src/commonMain/kotlin/club/nito/core/ui/ParticipantScheduleItem.kt b/core/ui/src/commonMain/kotlin/club/nito/core/ui/ParticipantScheduleItem.kt index f4481a6f..298e23e6 100644 --- a/core/ui/src/commonMain/kotlin/club/nito/core/ui/ParticipantScheduleItem.kt +++ b/core/ui/src/commonMain/kotlin/club/nito/core/ui/ParticipantScheduleItem.kt @@ -17,8 +17,8 @@ import androidx.compose.ui.unit.dp import club.nito.core.common.NitoDateFormatter import club.nito.core.designsystem.component.Text import club.nito.core.domain.model.ParticipantSchedule -import club.nito.core.domain.model.filterIsAttendance -import club.nito.core.domain.model.toUserProfileList +import club.nito.core.model.participant.filterIsAttendance +import club.nito.core.model.participant.toUserProfileList @Composable public fun ParticipantScheduleItem( diff --git a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailIntent.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailIntent.kt index f4b9c0a9..e10a3ebb 100644 --- a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailIntent.kt +++ b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailIntent.kt @@ -1,7 +1,7 @@ package club.nito.feature.schedule.detail import club.nito.core.domain.model.ParticipantSchedule -import club.nito.core.domain.model.ParticipantUser +import club.nito.core.model.participant.ParticipantUser import club.nito.core.model.participant.ParticipantStatus public sealed class ScheduleDetailIntent { diff --git a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailScreen.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailScreen.kt index 417abb34..89db74ea 100644 --- a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailScreen.kt +++ b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/detail/ScheduleDetailScreen.kt @@ -52,9 +52,9 @@ import club.nito.core.designsystem.component.CenterAlignedTopAppBar import club.nito.core.designsystem.component.Scaffold import club.nito.core.designsystem.component.Text import club.nito.core.domain.model.ParticipantSchedule -import club.nito.core.domain.model.ParticipantUser import club.nito.core.model.FetchSingleContentResult import club.nito.core.model.participant.ParticipantStatus +import club.nito.core.model.participant.ParticipantUser import club.nito.core.model.schedule.ScheduleId import club.nito.core.ui.ProfileImage import club.nito.core.ui.koinStateMachine From b24e9f4fef640f8310d8ade1e3c87483e41f73c4 Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 12 Dec 2023 09:52:32 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:sparkles:=20ProfileDao=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nito/core/database/di/DatabaseModule.kt | 3 + .../nito/core/database/profile/ProfileDao.kt | 30 ++++++++++ .../database/profile/SqlDelightProfileDao.kt | 59 +++++++++++++++++++ .../profile/model/LocalUserProfile.kt | 12 ++++ .../club/nito/core/database/Profiles.sq | 46 +++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/profile/ProfileDao.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/profile/SqlDelightProfileDao.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/profile/model/LocalUserProfile.kt create mode 100644 core/database/src/commonMain/sqldelight/club/nito/core/database/Profiles.sq diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt index 613691e4..c9a5122c 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt @@ -4,6 +4,8 @@ import club.nito.core.database.DriverFactory import club.nito.core.database.createDatabase import club.nito.core.database.participant.ParticipantDao import club.nito.core.database.participant.SqlDelightParticipantDao +import club.nito.core.database.profile.ProfileDao +import club.nito.core.database.profile.SqlDelightProfileDao import org.koin.core.module.Module import org.koin.core.module.dsl.singleOf import org.koin.core.scope.Scope @@ -18,6 +20,7 @@ public val databaseModule: Module = module { } singleOf(::SqlDelightParticipantDao) bind ParticipantDao::class + singleOf(::SqlDelightProfileDao) bind ProfileDao::class } internal expect fun Scope.createDriverFactory(): DriverFactory diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/profile/ProfileDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/profile/ProfileDao.kt new file mode 100644 index 00000000..52f67e7d --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/profile/ProfileDao.kt @@ -0,0 +1,30 @@ +package club.nito.core.database.profile + +import club.nito.core.model.UserProfile +import kotlinx.coroutines.flow.Flow + +public interface ProfileDao { + /** + * ユーザー情報のストリームを取得する + * + * @param userId 取得するユーザーの ID + */ + public fun profileStream(userId: String): Flow + + /** + * ユーザー情報のストリームを取得する + * + * @param userIds 取得するユーザーの ID 配列 + */ + public fun profilesStream(userIds: List): Flow> + + /** + * ユーザー一覧を登録 / 更新する + */ + public fun upsert(entities: List) + + /** + * ユーザーを登録 / 更新する + */ + public fun upsert(entity: UserProfile) +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/profile/SqlDelightProfileDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/profile/SqlDelightProfileDao.kt new file mode 100644 index 00000000..023c1004 --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/profile/SqlDelightProfileDao.kt @@ -0,0 +1,59 @@ +package club.nito.core.database.profile + +import app.cash.sqldelight.coroutines.asFlow +import app.cash.sqldelight.coroutines.mapToList +import app.cash.sqldelight.coroutines.mapToOneOrNull +import club.nito.core.common.NitoCoroutineDispatchers +import club.nito.core.database.Database +import club.nito.core.database.Profiles +import club.nito.core.database.profile.model.toModel +import club.nito.core.model.UserProfile +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +internal class SqlDelightProfileDao( + private val database: Database, + private val dispatchers: NitoCoroutineDispatchers, +) : ProfileDao { + override fun profileStream(userId: String): Flow { + return database.profilesQueries.profileById(userId) + .asFlow() + .mapToOneOrNull(dispatchers.io) + .map { + it?.toModel() + } + } + + override fun profilesStream(userIds: List): Flow> { + return database.profilesQueries.profileByIds(userIds) + .asFlow() + .mapToList(dispatchers.io) + .map { + it.map(Profiles::toModel) + } + } + + override fun upsert(entities: List) { + database.transaction { + for (entity in entities) { + upsertUserProfile(entity) + } + } + } + + override fun upsert(entity: UserProfile) { + database.transaction { + upsertUserProfile(entity) + } + } + + private fun upsertUserProfile(entity: UserProfile) { + database.profilesQueries.upsert( + id = entity.id, + username = entity.username, + display_name = entity.displayName, + avatar_url = entity.avatarUrl, + website = entity.website, + ) + } +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/profile/model/LocalUserProfile.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/profile/model/LocalUserProfile.kt new file mode 100644 index 00000000..4db0e6ae --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/profile/model/LocalUserProfile.kt @@ -0,0 +1,12 @@ +package club.nito.core.database.profile.model + +import club.nito.core.model.UserProfile +import club.nito.core.database.Profiles as LocalUserProfile + +internal fun LocalUserProfile.toModel(): UserProfile = UserProfile( + id = id, + username = username, + displayName = display_name, + avatarUrl = avatar_url, + website = website, +) diff --git a/core/database/src/commonMain/sqldelight/club/nito/core/database/Profiles.sq b/core/database/src/commonMain/sqldelight/club/nito/core/database/Profiles.sq new file mode 100644 index 00000000..6c44e9f8 --- /dev/null +++ b/core/database/src/commonMain/sqldelight/club/nito/core/database/Profiles.sq @@ -0,0 +1,46 @@ +CREATE TABLE IF NOT EXISTS `profiles` ( + `id` TEXT PRIMARY KEY NOT NULL, + `username` TEXT NOT NULL, + `display_name` TEXT NOT NULL, + `avatar_url` TEXT NOT NULL, + `website` TEXT NOT NULL +); + +-- indices + +CREATE UNIQUE INDEX IF NOT EXISTS `profiles_pkey` ON `profiles` (`id`); + +-- queries + +profileById: +SELECT * +FROM profiles +WHERE id = ?; + +profileByIds: +SELECT * +FROM profiles +WHERE id IN ?; + +upsert { + UPDATE profiles SET + `username` = :username, + `display_name` = :display_name, + `avatar_url` = :avatar_url, + `website` = :website + WHERE `id` = :id; + + INSERT OR IGNORE INTO profiles ( + `id`, + `username`, + `display_name`, + `avatar_url`, + `website` + ) VALUES ( + :id, + :username, + :display_name, + :avatar_url, + :website + ); +} From f002a39cb3bb414957360d19ee1bee25ee6f4ec0 Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 12 Dec 2023 09:52:48 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:sparkles:=20PlaceDao=20=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nito/core/database/di/DatabaseModule.kt | 3 + .../club/nito/core/database/place/PlaceDao.kt | 35 ++++++++++ .../core/database/place/SqlDelightPlaceDao.kt | 69 +++++++++++++++++++ .../core/database/place/model/LocalPlace.kt | 13 ++++ .../club/nito/core/database/Places.sq | 54 +++++++++++++++ .../club/nito/core/model/place/Place.kt | 2 + .../core/network/place/model/NetworkPlace.kt | 5 ++ 7 files changed, 181 insertions(+) create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/place/model/LocalPlace.kt create mode 100644 core/database/src/commonMain/sqldelight/club/nito/core/database/Places.sq diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt index c9a5122c..1c87a5c0 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt @@ -4,6 +4,8 @@ import club.nito.core.database.DriverFactory import club.nito.core.database.createDatabase import club.nito.core.database.participant.ParticipantDao import club.nito.core.database.participant.SqlDelightParticipantDao +import club.nito.core.database.place.PlaceDao +import club.nito.core.database.place.SqlDelightPlaceDao import club.nito.core.database.profile.ProfileDao import club.nito.core.database.profile.SqlDelightProfileDao import org.koin.core.module.Module @@ -20,6 +22,7 @@ public val databaseModule: Module = module { } singleOf(::SqlDelightParticipantDao) bind ParticipantDao::class + singleOf(::SqlDelightPlaceDao) bind PlaceDao::class singleOf(::SqlDelightProfileDao) bind ProfileDao::class } diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt new file mode 100644 index 00000000..5932716c --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt @@ -0,0 +1,35 @@ +package club.nito.core.database.place + +import club.nito.core.model.place.Place +import kotlinx.coroutines.flow.Flow + +public interface PlaceDao { + /** + * 場所一覧のストリームを取得する + */ + public val placesStream: Flow> + + /** + * 場所のストリームを取得する + * + * @param placeId 取得する場所の ID + */ + public fun placeStream(placeId: String): Flow + + /** + * 場所一覧のストリームを取得する + * + * @param placeIds 取得する場所の ID 配列 + */ + public fun placesStream(placeIds: List): Flow> + + /** + * スケジュール一覧を登録 / 更新する + */ + public fun upsert(entities: List) + + /** + * スケジュールを登録 / 更新する + */ + public fun upsert(entity: Place) +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt new file mode 100644 index 00000000..e5c38210 --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt @@ -0,0 +1,69 @@ +package club.nito.core.database.place + +import app.cash.sqldelight.coroutines.asFlow +import app.cash.sqldelight.coroutines.mapToList +import app.cash.sqldelight.coroutines.mapToOneOrNull +import club.nito.core.common.NitoCoroutineDispatchers +import club.nito.core.database.Database +import club.nito.core.database.Places +import club.nito.core.database.place.model.toModel +import club.nito.core.model.place.Place +import club.nito.core.model.schedule.ScheduleId +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +internal class SqlDelightPlaceDao( + private val database: Database, + private val dispatchers: NitoCoroutineDispatchers, +) : PlaceDao { + override val placesStream: Flow> + get() = database.placesQueries.places() + .asFlow() + .mapToList(dispatchers.io) + .map { + it.map(Places::toModel) + } + + override fun placeStream(placeId: ScheduleId): Flow { + return database.placesQueries.placeById(placeId) + .asFlow() + .mapToOneOrNull(dispatchers.io) + .map { + it?.toModel() + } + } + + override fun placesStream(placeIds: List): Flow> { + return database.placesQueries.placesByIds(placeIds) + .asFlow() + .mapToList(dispatchers.io) + .map { + it.map(Places::toModel) + } + } + + override fun upsert(entities: List) { + database.transaction { + for (entity in entities) { + upsertUserProfile(entity) + } + } + } + + override fun upsert(entity: Place) { + database.transaction { + upsertUserProfile(entity) + } + } + + private fun upsertUserProfile(entity: Place) { + database.placesQueries.upsert( + id = entity.id, + name = entity.name, + url = entity.url, + description = entity.description, + map_url = entity.mapUrl, + image_url = entity.imageUrl, + ) + } +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/place/model/LocalPlace.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/place/model/LocalPlace.kt new file mode 100644 index 00000000..fb78f50e --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/place/model/LocalPlace.kt @@ -0,0 +1,13 @@ +package club.nito.core.database.place.model + +import club.nito.core.model.place.Place +import club.nito.core.database.Places as LocalPlace + +internal fun LocalPlace.toModel(): Place = Place( + id = id, + name = name, + url = url, + description = description, + mapUrl = map_url, + imageUrl = image_url, +) diff --git a/core/database/src/commonMain/sqldelight/club/nito/core/database/Places.sq b/core/database/src/commonMain/sqldelight/club/nito/core/database/Places.sq new file mode 100644 index 00000000..a3ef0339 --- /dev/null +++ b/core/database/src/commonMain/sqldelight/club/nito/core/database/Places.sq @@ -0,0 +1,54 @@ +CREATE TABLE IF NOT EXISTS `places` ( + `id` TEXT PRIMARY KEY NOT NULL, + `name` TEXT NOT NULL, + `url` TEXT NOT NULL, + `map_url` TEXT NOT NULL, + `image_url` TEXT NOT NULL, + `description` TEXT NOT NULL +); + +-- indices + +CREATE UNIQUE INDEX IF NOT EXISTS `places_pkey` ON `places` (`id`); + +-- queries + +places: +SELECT * +FROM places; + +placesByIds: +SELECT * +FROM places +WHERE id IN ?; + +placeById: +SELECT * +FROM places +WHERE id = ?; + +upsert { + UPDATE places SET + `name` = :name, + `url` = :url, + `map_url` = :map_url, + `image_url` = :image_url, + `description` = :description + WHERE `id` = :id; + + INSERT OR IGNORE INTO places ( + `id`, + `name`, + `url`, + `map_url`, + `image_url`, + `description` + ) VALUES ( + :id, + :name, + :url, + :map_url, + :image_url, + :description + ); +} diff --git a/core/model/src/commonMain/kotlin/club/nito/core/model/place/Place.kt b/core/model/src/commonMain/kotlin/club/nito/core/model/place/Place.kt index 53429b30..17ae189b 100644 --- a/core/model/src/commonMain/kotlin/club/nito/core/model/place/Place.kt +++ b/core/model/src/commonMain/kotlin/club/nito/core/model/place/Place.kt @@ -4,6 +4,7 @@ package club.nito.core.model.place * 場所 * @param id ID * @param name 名前 + * @param url URL * @param description 説明文 * @param mapUrl 地図URL * @param imageUrl 画像URL @@ -11,6 +12,7 @@ package club.nito.core.model.place public data class Place( val id: PlaceId, val name: String, + val url: String, val description: String, val mapUrl: String, val imageUrl: String, diff --git a/core/network/src/commonMain/kotlin/club/nito/core/network/place/model/NetworkPlace.kt b/core/network/src/commonMain/kotlin/club/nito/core/network/place/model/NetworkPlace.kt index db70c923..55afbcd8 100644 --- a/core/network/src/commonMain/kotlin/club/nito/core/network/place/model/NetworkPlace.kt +++ b/core/network/src/commonMain/kotlin/club/nito/core/network/place/model/NetworkPlace.kt @@ -7,6 +7,7 @@ import kotlinx.serialization.Serializable * 場所 * @param id ID * @param name 名前 + * @param url URL * @param description 説明文 * @param mapUrl 地図URL * @param imageUrl 画像URL @@ -15,6 +16,7 @@ import kotlinx.serialization.Serializable public data class NetworkPlace internal constructor( val id: String, val name: String, + val url: String, val description: String, val mapUrl: String, val imageUrl: String, @@ -22,6 +24,7 @@ public data class NetworkPlace internal constructor( internal fun toPlace() = Place( id = id, name = name, + url = url, description = description.replace("\\n", "\n"), mapUrl = mapUrl, imageUrl = imageUrl, @@ -31,12 +34,14 @@ public data class NetworkPlace internal constructor( internal fun createFakeNetworkPlace( id: String = "bbe00d24-d840-460d-a127-f23f9e472cc6", name: String = "レイクタウン", + url: String = "https://www.google.com", description: String = "レイクタウンは、埼玉県越谷市にある複合商業施設である。2008年(平成20年)3月14日に開業した。運営は三井不動産商業マネジメントが行っている。", mapUrl: String = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3239.919508821314!2d139.790403315258!3d35.89174898014363!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x6018f3b0b0b0b0b1%3A0x1b0b0b0b0b0b0b0b!2z44CSMzUwLTAwMjQg5p2x5Lqs6YO95riv5Yy65Y2X6YCa5L2c5a2Q5bGx77yR5LiB55uu77yR77yR4oiS77yR!5e0!3m2!1sja!2sjp!4v1629788517009!5m2!1sja!2sjp", imageUrl: String = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Laketown_outside.jpg/1200px-Laketown_outside.jpg", ) = NetworkPlace( id = id, name = name, + url = url, description = description, mapUrl = mapUrl, imageUrl = imageUrl, From e1bd891af84cb40362874872e334c34b5540825b Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 12 Dec 2023 09:55:10 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:sparkles:=20ScheduleDao=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/nito/core/database/Database.kt | 5 ++ .../adapter/InstantLongColumnAdapter.kt | 9 +++ .../nito/core/database/di/DatabaseModule.kt | 3 + .../core/database/schedule/ScheduleDao.kt | 44 +++++++++++ .../schedule/SqlDelightScheduleDao.kt | 79 +++++++++++++++++++ .../database/schedule/model/LocalSchedule.kt | 39 +++++++++ .../club/nito/core/database/Schedules.sq | 76 ++++++++++++++++++ .../core/model/schedule/ScheduleWithPlace.kt | 13 +++ 8 files changed, 268 insertions(+) create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/adapter/InstantLongColumnAdapter.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/schedule/ScheduleDao.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt create mode 100644 core/database/src/commonMain/kotlin/club/nito/core/database/schedule/model/LocalSchedule.kt create mode 100644 core/database/src/commonMain/sqldelight/club/nito/core/database/Schedules.sq create mode 100644 core/model/src/commonMain/kotlin/club/nito/core/model/schedule/ScheduleWithPlace.kt diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/Database.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/Database.kt index 2cd38947..a675bbf3 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/Database.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/Database.kt @@ -2,6 +2,7 @@ package club.nito.core.database import app.cash.sqldelight.EnumColumnAdapter import app.cash.sqldelight.db.SqlDriver +import club.nito.core.database.adapter.InstantLongColumnAdapter internal expect class DriverFactory { fun createDriver(): SqlDriver @@ -16,6 +17,10 @@ internal fun createDatabase(driverFactory: DriverFactory): Database { participantsAdapter = Participants.Adapter( statusAdapter = EnumColumnAdapter(), ), + schedulesAdapter = Schedules.Adapter( + scheduled_atAdapter = InstantLongColumnAdapter, + met_atAdapter = InstantLongColumnAdapter, + ), ) // Do more work with the database (see below). diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/adapter/InstantLongColumnAdapter.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/adapter/InstantLongColumnAdapter.kt new file mode 100644 index 00000000..273d5e91 --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/adapter/InstantLongColumnAdapter.kt @@ -0,0 +1,9 @@ +package club.nito.core.database.adapter + +import app.cash.sqldelight.ColumnAdapter +import kotlinx.datetime.Instant + +internal object InstantLongColumnAdapter : ColumnAdapter { + override fun decode(databaseValue: Long): Instant = Instant.fromEpochMilliseconds(databaseValue) + override fun encode(value: Instant): Long = value.toEpochMilliseconds() +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt index 1c87a5c0..3e6e5cba 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt @@ -8,6 +8,8 @@ import club.nito.core.database.place.PlaceDao import club.nito.core.database.place.SqlDelightPlaceDao import club.nito.core.database.profile.ProfileDao import club.nito.core.database.profile.SqlDelightProfileDao +import club.nito.core.database.schedule.ScheduleDao +import club.nito.core.database.schedule.SqlDelightScheduleDao import org.koin.core.module.Module import org.koin.core.module.dsl.singleOf import org.koin.core.scope.Scope @@ -24,6 +26,7 @@ public val databaseModule: Module = module { singleOf(::SqlDelightParticipantDao) bind ParticipantDao::class singleOf(::SqlDelightPlaceDao) bind PlaceDao::class singleOf(::SqlDelightProfileDao) bind ProfileDao::class + singleOf(::SqlDelightScheduleDao) bind ScheduleDao::class } internal expect fun Scope.createDriverFactory(): DriverFactory diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/ScheduleDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/ScheduleDao.kt new file mode 100644 index 00000000..a6dbe94f --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/ScheduleDao.kt @@ -0,0 +1,44 @@ +package club.nito.core.database.schedule + +import club.nito.core.model.schedule.Schedule +import club.nito.core.model.schedule.ScheduleId +import club.nito.core.model.schedule.ScheduleWithPlace +import kotlinx.coroutines.flow.Flow + +public interface ScheduleDao { + /** + * スケジュールのストリームを取得する + */ + public val schedulesStream: Flow> + + /** + * スケジュールのストリームを取得する + * + * @param scheduleId 取得するスケジュールの ID + */ + public fun scheduleStream(scheduleId: ScheduleId): Flow + + /** + * 場所情報付きスケジュールのストリームを取得する + * + * @param scheduleId 取得するスケジュールの ID + */ + public fun scheduleWithPlaceStream(scheduleId: ScheduleId): Flow + + /** + * スケジュールのストリームを取得する + * + * @param scheduleIds 取得するスケジュールの ID 配列 + */ + public fun schedulesStream(scheduleIds: List): Flow> + + /** + * スケジュール一覧を登録 / 更新する + */ + public fun upsert(entities: List) + + /** + * スケジュールを登録 / 更新する + */ + public fun upsert(entity: Schedule) +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt new file mode 100644 index 00000000..6aa29e45 --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt @@ -0,0 +1,79 @@ +package club.nito.core.database.schedule + +import app.cash.sqldelight.coroutines.asFlow +import app.cash.sqldelight.coroutines.mapToList +import app.cash.sqldelight.coroutines.mapToOneOrNull +import club.nito.core.common.NitoCoroutineDispatchers +import club.nito.core.database.Database +import club.nito.core.database.Schedules +import club.nito.core.database.schedule.model.toModel +import club.nito.core.model.schedule.Schedule +import club.nito.core.model.schedule.ScheduleId +import club.nito.core.model.schedule.ScheduleWithPlace +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +internal class SqlDelightScheduleDao( + private val database: Database, + private val dispatchers: NitoCoroutineDispatchers, +) : ScheduleDao { + override val schedulesStream: Flow> + get() = database.schedulesQueries.schedules() + .asFlow() + .mapToList(dispatchers.io) + .map { + it.map(Schedules::toModel) + } + + override fun scheduleStream(scheduleId: ScheduleId): Flow { + return database.schedulesQueries.scheduleById(scheduleId) + .asFlow() + .mapToOneOrNull(dispatchers.io) + .map { + it?.toModel() + } + } + + override fun scheduleWithPlaceStream(scheduleId: ScheduleId): Flow { + return database.schedulesQueries.scheduleWithPlace(scheduleId) + .asFlow() + .mapToOneOrNull(dispatchers.io) + .map { + it?.toModel() + } + } + + override fun schedulesStream(scheduleIds: List): Flow> { + return database.schedulesQueries.schedulesByIds(scheduleIds) + .asFlow() + .mapToList(dispatchers.io) + .map { + it.map(Schedules::toModel) + } + } + + override fun upsert(entities: List) { + database.transaction { + for (entity in entities) { + upsertUserProfile(entity) + } + } + } + + override fun upsert(entity: Schedule) { + database.transaction { + upsertUserProfile(entity) + } + } + + private fun upsertUserProfile(entity: Schedule) { + database.schedulesQueries.upsert( + id = entity.id, + scheduled_at = entity.scheduledAt, + met_at = entity.metAt, + venue_id = entity.venueId, + meet_id = entity.meetId, + description = entity.description, + ) + } +} diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/model/LocalSchedule.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/model/LocalSchedule.kt new file mode 100644 index 00000000..cecc1728 --- /dev/null +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/model/LocalSchedule.kt @@ -0,0 +1,39 @@ +package club.nito.core.database.schedule.model + +import club.nito.core.model.place.Place +import club.nito.core.model.schedule.Schedule +import club.nito.core.model.schedule.ScheduleWithPlace +import club.nito.core.database.ScheduleWithPlace as LocalScheduleWithPlace +import club.nito.core.database.Schedules as LocalSchedule + +internal fun LocalSchedule.toModel(): Schedule = Schedule( + id = id, + scheduledAt = scheduled_at, + metAt = met_at, + venueId = venue_id, + meetId = meet_id, + description = description, +) + +internal fun LocalScheduleWithPlace.toModel(): ScheduleWithPlace = ScheduleWithPlace( + id = id, + scheduledAt = scheduled_at, + metAt = met_at, + venue = Place( + id = venue_id, + name = name, + url = url, + description = description_, + mapUrl = map_url, + imageUrl = image_url, + ), + meet = Place( + id = meet_id, + name = name_, + url = url_, + description = description__, + mapUrl = map_url_, + imageUrl = image_url_, + ), + description = description, +) diff --git a/core/database/src/commonMain/sqldelight/club/nito/core/database/Schedules.sq b/core/database/src/commonMain/sqldelight/club/nito/core/database/Schedules.sq new file mode 100644 index 00000000..6c83ca58 --- /dev/null +++ b/core/database/src/commonMain/sqldelight/club/nito/core/database/Schedules.sq @@ -0,0 +1,76 @@ +import kotlinx.datetime.Instant; + +CREATE TABLE IF NOT EXISTS `schedules` ( + `id` TEXT PRIMARY KEY NOT NULL, + `scheduled_at` INTEGER AS Instant NOT NULL, + `venue_id` TEXT NOT NULL, + `meet_id` TEXT NOT NULL, + `met_at` INTEGER AS Instant NOT NULL, + `description` TEXT NOT NULL +); + +-- indices + +CREATE UNIQUE INDEX IF NOT EXISTS `schedules_pkey` ON `schedules` (`id`); + +-- queries + +schedules: +SELECT * +FROM schedules; + +schedulesByIds: +SELECT * +FROM schedules +WHERE id IN ?; + +scheduleById: +SELECT * +FROM schedules +WHERE id = ?; + +schedulesWithPlace: +SELECT + schedules.*, + venue.*, + meet.* +FROM schedules +INNER JOIN places venue ON schedules.venue_id = venue.id +INNER JOIN places meet ON schedules.meet_id = meet.id +WHERE schedules.id IN :schedule_id; + +scheduleWithPlace: +SELECT + schedules.*, + venue.*, + meet.* +FROM schedules +INNER JOIN places venue ON schedules.venue_id = venue.id +INNER JOIN places meet ON schedules.meet_id = meet.id +WHERE schedules.id = :schedule_id; + +upsert { + UPDATE schedules SET + `scheduled_at` = :scheduled_at, + `venue_id` = :venue_id, + `meet_id` = :meet_id, + `description` = :description, + `met_at` = :met_at + WHERE `id` = :id; + + INSERT OR IGNORE INTO schedules ( + `id`, + `scheduled_at`, + `venue_id`, + `meet_id`, + `description`, + `met_at` + ) VALUES ( + :id, + :scheduled_at, + :venue_id, + :meet_id, + :description, + :met_at + ); +} diff --git a/core/model/src/commonMain/kotlin/club/nito/core/model/schedule/ScheduleWithPlace.kt b/core/model/src/commonMain/kotlin/club/nito/core/model/schedule/ScheduleWithPlace.kt new file mode 100644 index 00000000..2797384b --- /dev/null +++ b/core/model/src/commonMain/kotlin/club/nito/core/model/schedule/ScheduleWithPlace.kt @@ -0,0 +1,13 @@ +package club.nito.core.model.schedule + +import club.nito.core.model.place.Place +import kotlinx.datetime.Instant + +public data class ScheduleWithPlace( + val id: ScheduleId, + val scheduledAt: Instant, + val metAt: Instant, + val venue: Place, + val meet: Place, + val description: String, +) From 81270976734a3fb19b448538cc6872f528f539a9 Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 12 Dec 2023 10:14:47 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:recycle:=20=E6=8C=87=E6=91=98=E7=AE=87?= =?UTF-8?q?=E6=89=80=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/club/nito/core/database/place/PlaceDao.kt | 4 ++-- .../club/nito/core/database/place/SqlDelightPlaceDao.kt | 6 +++--- .../nito/core/database/schedule/SqlDelightScheduleDao.kt | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt index 5932716c..ced2dbd0 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/place/PlaceDao.kt @@ -24,12 +24,12 @@ public interface PlaceDao { public fun placesStream(placeIds: List): Flow> /** - * スケジュール一覧を登録 / 更新する + * 場所一覧を登録 / 更新する */ public fun upsert(entities: List) /** - * スケジュールを登録 / 更新する + * 場所を登録 / 更新する */ public fun upsert(entity: Place) } diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt index e5c38210..5e4794b3 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/place/SqlDelightPlaceDao.kt @@ -45,18 +45,18 @@ internal class SqlDelightPlaceDao( override fun upsert(entities: List) { database.transaction { for (entity in entities) { - upsertUserProfile(entity) + upsertPlace(entity) } } } override fun upsert(entity: Place) { database.transaction { - upsertUserProfile(entity) + upsertPlace(entity) } } - private fun upsertUserProfile(entity: Place) { + private fun upsertPlace(entity: Place) { database.placesQueries.upsert( id = entity.id, name = entity.name, diff --git a/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt index 6aa29e45..39470c5d 100644 --- a/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt +++ b/core/database/src/commonMain/kotlin/club/nito/core/database/schedule/SqlDelightScheduleDao.kt @@ -55,18 +55,18 @@ internal class SqlDelightScheduleDao( override fun upsert(entities: List) { database.transaction { for (entity in entities) { - upsertUserProfile(entity) + upsertSchedule(entity) } } } override fun upsert(entity: Schedule) { database.transaction { - upsertUserProfile(entity) + upsertSchedule(entity) } } - private fun upsertUserProfile(entity: Schedule) { + private fun upsertSchedule(entity: Schedule) { database.schedulesQueries.upsert( id = entity.id, scheduled_at = entity.scheduledAt,