Skip to content

Commit

Permalink
Fix: 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
HahyunKang authored and Bongpal-dev committed Nov 28, 2024
1 parent 8593b0d commit 138a18a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -71,9 +69,4 @@ abstract class DataSourceModule {
followDataSource: FollowDataSourceImpl,
): FollowDataSource

@Binds
abstract fun provideFollowerDataSource(
followerDataSource: FakeFollowerDataSource,
): FollowerDataSource

}
Original file line number Diff line number Diff line change
@@ -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<PagingData<FollowerThumbnail>>
//}
//
//class FollowerRepositoryImpl @Inject constructor(
// private val dataSource: FollowerDataSource,
//) : FollowerRepository {
//
// override fun getFollowerDataSourcePagingFlow(userId: Long): Flow<PagingData<FollowerThumbnail>> {
// return Pager(config = PagingConfig(
// pageSize = PAGE_SIZE,
// enablePlaceholders = false,
// ), pagingSourceFactory = { FollowerGalleryThumbnailPagingDataSource(dataSource) }).flow
// }
//
// companion object {
// const val PAGE_SIZE = 40
// }
//}
interface FollowRepository {
fun getFollowerName(followerId: String): Flow<String>
suspend fun unFollowUser(followerId: String): Flow<Boolean>
fun followUser(followerId: String, followerName: String): Flow<Boolean>
suspend fun getFollowerDataSourcePagingFlow(): Flow<PagingData<FollowerThumbnail>>
}

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<String> = 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<Boolean> = flow {
val currentUserId = googleAuthDataSource.getUserId()

followDataSource.uploadFollow(
userId = currentUserId,
followerId = followerId,
followerName = followerName
).collect { success ->
emit(success)
}
}

override suspend fun unFollowUser(
followerId: String,
): Flow<Boolean> = flow {
val currentUserId = googleAuthDataSource.getUserId()

followDataSource.removeFollow(
userId = currentUserId,
followerId = followerId
).collect { success ->
emit(success)
}
}

override suspend fun getFollowerDataSourcePagingFlow(): Flow<PagingData<FollowerThumbnail>> {
return Pager(
config = PagingConfig(
pageSize = FOLLOWER_PER_PAGE,
enablePlaceholders = false,
), pagingSourceFactory = {
followerGalleryThumbnailPagingDataSource
}
).flow
}

companion object {
const val FOLLOWER_PER_PAGE = 5
}

}

0 comments on commit 138a18a

Please sign in to comment.