TIL #109

loci·2024년 9월 3일
0

TIL

목록 보기
100/103

Error: Could not deserialize object. Failed to convert value of type java.lang.String to DocumentReference (found in field 'user')

-> 아이디로 피드를 찾아올때 user의 타입이 DocumentReference로 되어있어 바꿔주어야함 (nickname)

class FeedRemote @Inject constructor(
    private val firestore: FirebaseFirestore
) : GetFeedList {

    override suspend fun getFeedList(
        uid: String?,
        limit: Long?,
        startAfter: String?
    ): List<FeedModel> {
        val feedDocuments = firestore.collection("feed")
            .get()
            .await()
            .documents

        Log.d("FeedRemote", "getFeedList: $feedDocuments")

        return feedDocuments.mapNotNull { documentSnapshot ->
            val tagList = documentSnapshot.get("tagList") as? List<*>

            documentSnapshot.toObject(FeedModel::class.java)?.copy(
                feedId = documentSnapshot.id,
                tags = tagList?.filterIsInstance<String>() ?: emptyList()
            )
                ?.run {
                    val nickname =
                        (user as? DocumentReference)?.get()?.await()?.getString("nickname")

                    // 로그로 nickname 값을 출력하여 확인
                    Log.d("FeedRemote", "Fetched nickname: $nickname for user: ${user?.id}")

                    nickname?.let {
                        copy(nickname = it)
                    } ?: this
                }

        }

    }
profile
편리한 개발자

0개의 댓글