diff --git a/app/src/main/java/com/spoony/spoony/data/repositoryimpl/ExploreRepositoryImpl.kt b/app/src/main/java/com/spoony/spoony/data/repositoryimpl/ExploreRepositoryImpl.kt index f9c8ba64..56f84a23 100644 --- a/app/src/main/java/com/spoony/spoony/data/repositoryimpl/ExploreRepositoryImpl.kt +++ b/app/src/main/java/com/spoony/spoony/data/repositoryimpl/ExploreRepositoryImpl.kt @@ -1,6 +1,7 @@ package com.spoony.spoony.data.repositoryimpl import com.spoony.spoony.domain.entity.CategoryEntity +import com.spoony.spoony.domain.entity.FeedEntity import com.spoony.spoony.domain.repository.ExploreRepository import javax.inject.Inject @@ -63,4 +64,89 @@ class ExploreRepositoryImpl @Inject constructor() : ExploreRepository { ) ) ) + + override suspend fun getFeedList( + userId: Int, + categoryId: Int, + locationQuery: String, + sortBy: String + ): Result> = Result.success( + listOf( + FeedEntity( + userId = 3, + userName = "두더지", + userRegion = "용산구", + postId = 3, + title = "스타벅스 삼성역섬유센터R점 리뷰", + categoryInfo = CategoryEntity( + categoryId = 2, + categoryName = "카페", + iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/cafe_color.png", + textColor = "FFE4E5", + backgroundColor = "FF7E84" + ), + zzimCount = 1 + ), + FeedEntity( + userId = 3, + userName = "두더지", + userRegion = "용산구", + postId = 4, + title = "스타벅스 삼성역섬유센터R점 리뷰", + categoryInfo = CategoryEntity( + categoryId = 2, + categoryName = "카페", + iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/cafe_color.png", + textColor = "FFE4E5", + backgroundColor = "FF7E84" + ), + zzimCount = 1 + ), + FeedEntity( + userId = 3, + userName = "두더지", + userRegion = "용산구", + postId = 5, + title = "스타벅스 삼성역섬유센터R점 리뷰", + categoryInfo = CategoryEntity( + categoryId = 2, + categoryName = "카페", + iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/cafe_color.png", + textColor = "FFE4E5", + backgroundColor = "FF7E84" + ), + zzimCount = 1 + ), + FeedEntity( + userId = 3, + userName = "두더지", + userRegion = "용산구", + postId = 6, + title = "스타벅스 삼성역섬유센터R점 리뷰", + categoryInfo = CategoryEntity( + categoryId = 2, + categoryName = "카페", + iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/cafe_color.png", + textColor = "FFE4E5", + backgroundColor = "FF7E84" + ), + zzimCount = 1 + ), + FeedEntity( + userId = 3, + userName = "두더지", + userRegion = "용산구", + postId = 7, + title = "스타벅스 삼성역섬유센터R점 리뷰", + categoryInfo = CategoryEntity( + categoryId = 2, + categoryName = "카페", + iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/cafe_color.png", + textColor = "FFE4E5", + backgroundColor = "FF7E84" + ), + zzimCount = 1 + ) + ) + ) } diff --git a/app/src/main/java/com/spoony/spoony/domain/entity/FeedEntity.kt b/app/src/main/java/com/spoony/spoony/domain/entity/FeedEntity.kt index eb3370ad..2cc6d745 100644 --- a/app/src/main/java/com/spoony/spoony/domain/entity/FeedEntity.kt +++ b/app/src/main/java/com/spoony/spoony/domain/entity/FeedEntity.kt @@ -2,5 +2,10 @@ package com.spoony.spoony.domain.entity data class FeedEntity( val userId: Int, - val userName + val userName: String, + val userRegion: String, + val postId: Int, + val title: String, + val categoryInfo: CategoryEntity, + val zzimCount: Int ) diff --git a/app/src/main/java/com/spoony/spoony/domain/repository/ExploreRepository.kt b/app/src/main/java/com/spoony/spoony/domain/repository/ExploreRepository.kt index 84a0ab98..4054eceb 100644 --- a/app/src/main/java/com/spoony/spoony/domain/repository/ExploreRepository.kt +++ b/app/src/main/java/com/spoony/spoony/domain/repository/ExploreRepository.kt @@ -1,7 +1,15 @@ package com.spoony.spoony.domain.repository import com.spoony.spoony.domain.entity.CategoryEntity +import com.spoony.spoony.domain.entity.FeedEntity interface ExploreRepository { suspend fun getCategoryList(): Result> + + suspend fun getFeedList( + userId: Int, + categoryId: Int, + locationQuery: String, + sortBy: String + ): Result> } diff --git a/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreScreen.kt b/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreScreen.kt index f24fb2ed..a6ca5e98 100644 --- a/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreScreen.kt +++ b/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreScreen.kt @@ -1,6 +1,5 @@ package com.spoony.spoony.presentation.explore -import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -81,7 +80,6 @@ fun ExploreRoute( } } -@OptIn(ExperimentalFoundationApi::class) @Composable private fun ExploreScreen( paddingValues: PaddingValues, diff --git a/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreViewModel.kt b/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreViewModel.kt index 862d997f..ab907621 100644 --- a/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreViewModel.kt +++ b/app/src/main/java/com/spoony/spoony/presentation/explore/ExploreViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.spoony.spoony.core.state.UiState import com.spoony.spoony.domain.repository.ExploreRepository +import com.spoony.spoony.presentation.explore.model.toModel import com.spoony.spoony.presentation.explore.type.SortingOption import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject @@ -23,6 +24,12 @@ class ExploreViewModel @Inject constructor( init { getCategoryList() + getFeedList( + userId = 1, + categoryId = 2, + locationQuery = "강남", + sortBy = "latest" + ) } private fun getCategoryList() { @@ -47,6 +54,41 @@ class ExploreViewModel @Inject constructor( } } + fun getFeedList( + userId: Int, + categoryId: Int, + locationQuery: String, + sortBy: String + ) { + viewModelScope.launch { + runCatching { + exploreRepository.getFeedList( + userId = userId, + categoryId = categoryId, + locationQuery = locationQuery, + sortBy = sortBy + ).onSuccess { response -> + _state.update { + it.copy( + feedList = UiState.Success( + response.map { feed -> + feed.toModel() + }.toImmutableList() + ) + ) + } + } + .onFailure { + _state.update { + it.copy( + feedList = UiState.Failure("피드 목록 조회 실패") + ) + } + } + } + } + } + fun updateSelectedSortingOption(sortingOption: SortingOption) { _state.update { it.copy( diff --git a/app/src/main/java/com/spoony/spoony/presentation/explore/model/FeedModel.kt b/app/src/main/java/com/spoony/spoony/presentation/explore/model/FeedModel.kt index aa984e74..148f5f33 100644 --- a/app/src/main/java/com/spoony/spoony/presentation/explore/model/FeedModel.kt +++ b/app/src/main/java/com/spoony/spoony/presentation/explore/model/FeedModel.kt @@ -1,6 +1,7 @@ package com.spoony.spoony.presentation.explore.model import com.spoony.spoony.domain.entity.CategoryEntity +import com.spoony.spoony.domain.entity.FeedEntity data class FeedModel( val feedId: Int, @@ -11,3 +12,13 @@ data class FeedModel( val categoryEntity: CategoryEntity, val addMapCount: Int ) + +fun FeedEntity.toModel(): FeedModel = FeedModel( + feedId = this.postId, + userId = this.userId, + username = this.userName, + userRegion = this.userRegion, + title = this.title, + categoryEntity = this.categoryInfo, + addMapCount = this.zzimCount +)