Skip to content

Commit

Permalink
#86 fix : 홈 내 리스트 필터 api 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yy0ung committed Dec 14, 2023
1 parent d2e683a commit d60dcbf
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data class MyRestaurantItem(
@SerializedName("restaurant_address") val address: String,
@SerializedName("restaurant_category") val category: String,
@SerializedName("restaurant_id") val id: Int,
@SerializedName("created_at") val createdAt: String,
@SerializedName("created_at") val createdAt: String?,
@SerializedName("restaurant_location") val location: Location,
@SerializedName("restaurant_name") val name: String,
@SerializedName("restaurant_phoneNumber") val phoneNumber: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ interface RestaurantApi {
// 내 맛집 리스트
@GET("api/user/restaurant")
suspend fun myRestaurantList(
@Query("longitude") longitude: String? = null,
@Query("latitude") latitude: String? = null,
@Query("limit") limit: Int? = null,
@Query("page") page: Int? = null,
@Query("sort") sort: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import com.avengers.nibobnebob.data.model.response.WishRestaurantResponse.Compan
import com.avengers.nibobnebob.data.model.runRemote
import com.avengers.nibobnebob.data.remote.RestaurantApi
import com.avengers.nibobnebob.domain.model.MyRestaurantData
import com.avengers.nibobnebob.domain.model.RecommendRestaurantData
import com.avengers.nibobnebob.domain.model.RestaurantDetailData
import com.avengers.nibobnebob.domain.model.RestaurantIsWishData
import com.avengers.nibobnebob.domain.model.RestaurantItemsData
import com.avengers.nibobnebob.domain.model.ReviewSortData
import com.avengers.nibobnebob.domain.model.SearchRestaurantData
import com.avengers.nibobnebob.domain.model.WishRestaurantData
import com.avengers.nibobnebob.domain.model.base.BaseState
import com.avengers.nibobnebob.domain.model.RecommendRestaurantData
import com.avengers.nibobnebob.domain.model.base.StatusCode
import com.avengers.nibobnebob.domain.repository.RestaurantRepository
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -140,12 +140,15 @@ class RestaurantRepositoryImpl @Inject constructor(
}

override fun myRestaurantList(
longitude: String?,
latitude: String?,
limit: Int?,
page: Int?,
sort: String?
): Flow<BaseState<MyRestaurantData>> =
flow {
when (val result = runRemote { api.myRestaurantList(limit, page, sort) }) {
when (val result =
runRemote { api.myRestaurantList(longitude, latitude, limit, page, sort) }) {
is BaseState.Success -> {
result.data.body?.let { body ->
emit(BaseState.Success(body.toDomainModel()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class MyRestaurantItemData(
val address: String,
val category: String,
val id: Int,
val createdAt : String,
val createdAt: String?,
val location: LocationData,
val name: String,
val phoneNumber: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ interface RestaurantRepository {
): Flow<BaseState<Unit>>

fun myRestaurantList(
longitude: String? = null,
latitude: String? = null,
limit: Int? = null,
page: Int? = null,
sort: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ class GetMyRestaurantListUseCase @Inject constructor(
private val repository: RestaurantRepository
) {
operator fun invoke(
longitude: String? = null,
latitude: String? = null,
limit: Int? = null,
page: Int? = null,
sort: String? = null,
): Flow<BaseState<MyRestaurantData>> = repository.myRestaurantList(limit, page, sort)
): Flow<BaseState<MyRestaurantData>> =
repository.myRestaurantList(longitude, latitude, limit, page, sort)
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class HomeViewModel @Inject constructor(
}

private fun myRestaurantList() {
myRestaurantListUseCase().onEach {
myRestaurantListUseCase(longitude = DEFAULT_LONGITUDE, latitude = DEFAULT_LATITUDE).onEach {
_events.emit(HomeEvents.RemoveMarkers)
when (it) {
is BaseState.Success -> {
Expand Down Expand Up @@ -470,4 +470,9 @@ class HomeViewModel @Inject constructor(
}
}

companion object {
const val DEFAULT_LATITUDE = "37.55"
const val DEFAULT_LONGITUDE = "126.9"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.avengers.nibobnebob.presentation.ui.main.mypage.mapper
import android.os.Build
import androidx.annotation.RequiresApi
import com.avengers.nibobnebob.domain.model.MyRestaurantItemData
import com.avengers.nibobnebob.domain.model.RestaurantItemsData
import com.avengers.nibobnebob.presentation.ui.main.mypage.model.UiMyListData
import com.avengers.nibobnebob.presentation.ui.toCreateDateString

Expand All @@ -12,5 +11,5 @@ fun MyRestaurantItemData.toUiMyListData(): UiMyListData = UiMyListData(
id = id,
name = name,
address = address,
date = createdAt.toCreateDateString()
date = createdAt?.toCreateDateString()
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ data class UiMyListData(
val id: Int,
val name: String,
val address: String,
val date: String
val date: String?
)

0 comments on commit d60dcbf

Please sign in to comment.