Skip to content

Commit

Permalink
[FEAT/#105] 피드 목록 조회 더미데이터
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyobeen-Park committed Jan 21, 2025
1 parent 80041bf commit 86b1211
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -63,4 +64,89 @@ class ExploreRepositoryImpl @Inject constructor() : ExploreRepository {
)
)
)

override suspend fun getFeedList(
userId: Int,
categoryId: Int,
locationQuery: String,
sortBy: String
): Result<List<FeedEntity>> = 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
)
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
@@ -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<List<CategoryEntity>>

suspend fun getFeedList(
userId: Int,
categoryId: Int,
locationQuery: String,
sortBy: String
): Result<List<FeedEntity>>
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -81,7 +80,6 @@ fun ExploreRoute(
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun ExploreScreen(
paddingValues: PaddingValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +24,12 @@ class ExploreViewModel @Inject constructor(

init {
getCategoryList()
getFeedList(
userId = 1,
categoryId = 2,
locationQuery = "강남",
sortBy = "latest"
)
}

private fun getCategoryList() {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
)

0 comments on commit 86b1211

Please sign in to comment.