From 138a18a15f716ec6b645189d4dffc4f56e82a500 Mon Sep 17 00:00:00 2001 From: HahyunKang Date: Thu, 28 Nov 2024 11:13:09 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FollowerGalleryThumbnailPagingSource.kt | 1 - .../com/kolown/data/di/DataSourceModule.kt | 7 -- .../data/repository/FollowerRepository.kt | 94 +++++++++++++++---- 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/core/data/src/main/java/com/kolown/data/datasource/paging/FollowerGalleryThumbnailPagingSource.kt b/core/data/src/main/java/com/kolown/data/datasource/paging/FollowerGalleryThumbnailPagingSource.kt index cc2e4d54..59904c01 100644 --- a/core/data/src/main/java/com/kolown/data/datasource/paging/FollowerGalleryThumbnailPagingSource.kt +++ b/core/data/src/main/java/com/kolown/data/datasource/paging/FollowerGalleryThumbnailPagingSource.kt @@ -3,7 +3,6 @@ package com.kolown.data.datasource.paging import android.util.Log import androidx.paging.PagingSource import androidx.paging.PagingState -import com.kolown.data.datasource.fake.FollowerDataSource import com.kolown.data.datasource.remote.AuthDataSource import com.kolown.data.datasource.remote.FollowDataSource import com.kolown.data.datasource.remote.PostDataSource diff --git a/core/data/src/main/java/com/kolown/data/di/DataSourceModule.kt b/core/data/src/main/java/com/kolown/data/di/DataSourceModule.kt index 8df8201a..94ef41c3 100644 --- a/core/data/src/main/java/com/kolown/data/di/DataSourceModule.kt +++ b/core/data/src/main/java/com/kolown/data/di/DataSourceModule.kt @@ -1,8 +1,6 @@ package com.kolown.data.di -import com.kolown.data.datasource.fake.FakeFollowerDataSource import com.kolown.data.datasource.fake.FakeGalleryDataSource -import com.kolown.data.datasource.fake.FollowerDataSource import com.kolown.data.datasource.fake.GalleryDataSource import com.kolown.data.datasource.remote.AuthDataSource import com.kolown.data.datasource.remote.AuthDataSourceImpl @@ -71,9 +69,4 @@ abstract class DataSourceModule { followDataSource: FollowDataSourceImpl, ): FollowDataSource - @Binds - abstract fun provideFollowerDataSource( - followerDataSource: FakeFollowerDataSource, - ): FollowerDataSource - } diff --git a/core/data/src/main/java/com/kolown/data/repository/FollowerRepository.kt b/core/data/src/main/java/com/kolown/data/repository/FollowerRepository.kt index bb9cc147..2ef5a4a7 100644 --- a/core/data/src/main/java/com/kolown/data/repository/FollowerRepository.kt +++ b/core/data/src/main/java/com/kolown/data/repository/FollowerRepository.kt @@ -1,30 +1,84 @@ package com.kolown.data.repository +import android.util.Log import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData -import com.kolown.data.datasource.fake.FollowerDataSource import com.kolown.data.datasource.paging.FollowerGalleryThumbnailPagingDataSource +import com.kolown.data.datasource.remote.AuthDataSource +import com.kolown.data.datasource.remote.FollowDataSource import com.kolown.model.FollowerThumbnail import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.flow import javax.inject.Inject +import javax.inject.Named -//interface FollowerRepository { -// fun getFollowerDataSourcePagingFlow(userId: Long): Flow> -//} -// -//class FollowerRepositoryImpl @Inject constructor( -// private val dataSource: FollowerDataSource, -//) : FollowerRepository { -// -// override fun getFollowerDataSourcePagingFlow(userId: Long): Flow> { -// return Pager(config = PagingConfig( -// pageSize = PAGE_SIZE, -// enablePlaceholders = false, -// ), pagingSourceFactory = { FollowerGalleryThumbnailPagingDataSource(dataSource) }).flow -// } -// -// companion object { -// const val PAGE_SIZE = 40 -// } -//} \ No newline at end of file +interface FollowRepository { + fun getFollowerName(followerId: String): Flow + suspend fun unFollowUser(followerId: String): Flow + fun followUser(followerId: String, followerName: String): Flow + suspend fun getFollowerDataSourcePagingFlow(): Flow> +} + +class FollowRepositoryImpl @Inject constructor( + private val followDataSource: FollowDataSource, + @Named("google") private val googleAuthDataSource: AuthDataSource, + private val followerGalleryThumbnailPagingDataSource: FollowerGalleryThumbnailPagingDataSource, +) : FollowRepository { + + override fun getFollowerName(followerId: String): Flow = flow { + val currentUserId = googleAuthDataSource.getUserId() + + followDataSource.getFollowerName(currentUserId, followerId) + .collect { name -> + emit(name) + } + }.catch { e -> + Log.e("GetFollowerName", "repository: $e") + } + + override fun followUser( + followerId: String, + followerName: String, + ): Flow = flow { + val currentUserId = googleAuthDataSource.getUserId() + + followDataSource.uploadFollow( + userId = currentUserId, + followerId = followerId, + followerName = followerName + ).collect { success -> + emit(success) + } + } + + override suspend fun unFollowUser( + followerId: String, + ): Flow = flow { + val currentUserId = googleAuthDataSource.getUserId() + + followDataSource.removeFollow( + userId = currentUserId, + followerId = followerId + ).collect { success -> + emit(success) + } + } + + override suspend fun getFollowerDataSourcePagingFlow(): Flow> { + return Pager( + config = PagingConfig( + pageSize = FOLLOWER_PER_PAGE, + enablePlaceholders = false, + ), pagingSourceFactory = { + followerGalleryThumbnailPagingDataSource + } + ).flow + } + + companion object { + const val FOLLOWER_PER_PAGE = 5 + } + +} \ No newline at end of file