-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from 2rabs/rt/local-datasource
✨ Repository に Dao を追加
- Loading branch information
Showing
8 changed files
with
99 additions
and
17 deletions.
There are no files selected for viewing
29 changes: 23 additions & 6 deletions
29
core/data/src/commonMain/kotlin/club/nito/core/data/DefaultParticipantRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
package club.nito.core.data | ||
|
||
import club.nito.core.database.participant.ParticipantDao | ||
import club.nito.core.model.participant.Participant | ||
import club.nito.core.model.participant.ParticipantDeclaration | ||
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.network.participation.ParticipantRemoteDataSource | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
public class DefaultParticipantRepository( | ||
private val remoteDataSource: ParticipantRemoteDataSource, | ||
private val dao: ParticipantDao, | ||
) : ParticipantRepository { | ||
override fun participantUsersStream(scheduleId: String): Flow<List<ParticipantUser>> = | ||
dao.participantUsersStream(scheduleId = scheduleId) | ||
|
||
override suspend fun getParticipants(scheduleId: String): List<Participant> = | ||
remoteDataSource.getParticipants(scheduleId = scheduleId) | ||
remoteDataSource.getParticipants(scheduleId = scheduleId).also { | ||
dao.upsert(entities = it) | ||
} | ||
|
||
override suspend fun getParticipants(scheduleIds: List<String>): List<Participant> = | ||
remoteDataSource.getParticipants(scheduleIds = scheduleIds) | ||
remoteDataSource.getParticipants(scheduleIds = scheduleIds).also { | ||
dao.upsert(entities = it) | ||
} | ||
|
||
override suspend fun existParticipantByUserId(scheduleId: ScheduleId, userId: String): Boolean = | ||
remoteDataSource.existParticipantByUserId(scheduleId = scheduleId, userId = userId) | ||
|
||
override suspend fun fetchParticipantStatus(scheduleId: ScheduleId, userId: String): ParticipantStatus = | ||
remoteDataSource.fetchParticipantStatus(scheduleId = scheduleId, userId = userId) | ||
|
||
override suspend fun insertParticipate(declaration: ParticipantDeclaration): Participant = | ||
remoteDataSource.insertParticipate(declaration = declaration) | ||
override suspend fun insertParticipate(declaration: ParticipantDeclaration): Participant { | ||
val participant = remoteDataSource.insertParticipate(declaration = declaration) | ||
dao.upsert(participant) | ||
return participant | ||
} | ||
|
||
override suspend fun updateParticipate(declaration: ParticipantDeclaration): Participant = | ||
remoteDataSource.updateParticipate(declaration = declaration) | ||
override suspend fun updateParticipate(declaration: ParticipantDeclaration): Participant { | ||
val participant = remoteDataSource.updateParticipate(declaration = declaration) | ||
dao.upsert(participant) | ||
return participant | ||
} | ||
} |
9 changes: 8 additions & 1 deletion
9
core/data/src/commonMain/kotlin/club/nito/core/data/DefaultPlaceRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
package club.nito.core.data | ||
|
||
import club.nito.core.database.place.PlaceDao | ||
import club.nito.core.model.place.Place | ||
import club.nito.core.model.place.PlaceId | ||
import club.nito.core.network.place.PlaceRemoteDataSource | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
public class DefaultPlaceRepository( | ||
private val remoteDataSource: PlaceRemoteDataSource, | ||
private val placeDao: PlaceDao, | ||
) : PlaceRepository { | ||
override fun placeStream(placeId: PlaceId): Flow<Place?> = placeDao.placeStream(placeId) | ||
|
||
override suspend fun fetchPlaceList(vararg ids: PlaceId): List<Place> { | ||
return remoteDataSource.fetchPlaceList(ids.toList()) | ||
return remoteDataSource.fetchPlaceList(ids.toList()).also { | ||
placeDao.upsert(it) | ||
} | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
core/data/src/commonMain/kotlin/club/nito/core/data/DefaultUserRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
package club.nito.core.data | ||
|
||
import club.nito.core.database.profile.ProfileDao | ||
import club.nito.core.model.FetchSingleContentResult | ||
import club.nito.core.model.UserProfile | ||
import club.nito.core.network.user.UserRemoteDataSource | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
public class DefaultUserRepository( | ||
private val remoteDataSource: UserRemoteDataSource, | ||
private val profileDao: ProfileDao, | ||
) : UserRepository { | ||
override fun profilesStream(userIds: List<String>): Flow<List<UserProfile>> = | ||
profileDao.profilesStream(userIds = userIds) | ||
|
||
override suspend fun getProfile(userId: String): FetchSingleContentResult<UserProfile> { | ||
val profile = remoteDataSource.getProfile(userId = userId) | ||
return profile?.let { FetchSingleContentResult.Success(it) } | ||
?: FetchSingleContentResult.NoContent | ||
} | ||
|
||
override suspend fun getProfiles(userIds: List<String>): List<UserProfile> { | ||
return remoteDataSource.getProfiles(userIds = userIds) | ||
} | ||
override suspend fun getProfiles(userIds: List<String>): List<UserProfile> = remoteDataSource | ||
.getProfiles(userIds = userIds) | ||
.also(profileDao::upsert) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters