From 6d62c4a3d147ab030aa9bbbe569cc9ad4e63aa32 Mon Sep 17 00:00:00 2001 From: SsongSik Date: Sun, 7 May 2023 01:18:59 +0900 Subject: [PATCH 01/11] =?UTF-8?q?[refact]=20:=20#83=20=EC=B0=9C=EA=BD=81?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A0=80=EC=9E=A5=20=ED=81=B4?= =?UTF-8?q?=EB=A6=B0=EC=95=84=ED=82=A4=ED=85=8D=EC=B2=98=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/model/kakao/Restaurant.kt | 33 ++++++++++++++++++- .../data/model/user/RequestUserData.kt | 2 +- .../data/model/user/ResponseUserData.kt | 2 +- .../data/repository/love/LoveRepository.kt | 8 +++++ .../repository/love/LoveRepositoryImpl.kt | 15 +++++++++ .../data/repository/user/UserRepository.kt | 4 +-- .../repository/user/UserRepositoryImpl.kt | 7 ++-- .../myongsikandroid/di/RepositoryModule.kt | 8 +++++ .../myongsikandroid/domain/UserCase.kt | 5 --- .../domain/model/love/InsertFoodEntity.kt | 17 ++++++++++ .../model/{ => user}/RequestUserEntity.kt | 2 +- .../model/{ => user}/ResponseUserEntity.kt | 2 +- .../usecase/love/InsertFoodDataUseCase.kt | 13 ++++++++ .../domain/usecase/love/LoveCase.kt | 5 +++ .../{ => usecase}/user/PostUserDataUseCase.kt | 5 ++- .../domain/usecase/user/UserCase.kt | 5 +++ .../viewmodel/food/SplashViewModel.kt | 2 +- .../viewmodel/search/LoveViewModel.kt | 8 +++-- .../myongsikandroid/util/FoodEvaluation.kt | 6 ---- 19 files changed, 119 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/UserCase.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt rename app/src/main/java/com/myongsik/myongsikandroid/domain/model/{ => user}/RequestUserEntity.kt (50%) rename app/src/main/java/com/myongsik/myongsikandroid/domain/model/{ => user}/ResponseUserEntity.kt (80%) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt rename app/src/main/java/com/myongsik/myongsikandroid/domain/{ => usecase}/user/PostUserDataUseCase.kt (65%) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/util/FoodEvaluation.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt index 87134083..d89548c2 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt @@ -4,6 +4,7 @@ package com.myongsik.myongsikandroid.data.model.kakao import android.os.Parcelable import androidx.room.Entity import androidx.room.PrimaryKey +import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity import com.squareup.moshi.Json import com.squareup.moshi.JsonClass import kotlinx.parcelize.Parcelize @@ -37,4 +38,34 @@ data class Restaurant( val x: String, @field:Json(name = "y") val y: String -) : Parcelable \ No newline at end of file +) : Parcelable + +fun InsertFoodEntity.toInsertFoodData() = Restaurant( + address_name = this.address_name, + category_group_code = this.category_group_code, + category_group_name = this.category_group_name, + category_name = this.category_name, + distance = this.distance, + id = this.id, + phone = this.phone, + place_name = this.place_name, + place_url = this.place_url, + road_address_name = this.road_address_name, + x = this.x, + y = this.y +) + +fun Restaurant.toInsertFoodEntity() = InsertFoodEntity( + address_name = this.address_name, + category_group_code = this.category_group_code, + category_group_name = this.category_group_name, + category_name = this.category_name, + distance = this.distance, + id = this.id, + phone = this.phone, + place_name = this.place_name, + place_url = this.place_url, + road_address_name = this.road_address_name, + x = this.x, + y = this.y +) \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/RequestUserData.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/RequestUserData.kt index 949534cc..e44097f9 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/RequestUserData.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/RequestUserData.kt @@ -1,6 +1,6 @@ package com.myongsik.myongsikandroid.data.model.user -import com.myongsik.myongsikandroid.domain.model.RequestUserEntity +import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity data class RequestUserData( diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/ResponseUserData.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/ResponseUserData.kt index 5926172b..f72d6ce2 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/ResponseUserData.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/model/user/ResponseUserData.kt @@ -1,6 +1,6 @@ package com.myongsik.myongsikandroid.data.model.user -import com.myongsik.myongsikandroid.domain.model.ResponseUserEntity +import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity data class ResponseUserData( val httpCode: Int, diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt new file mode 100644 index 00000000..1c6f3f7e --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt @@ -0,0 +1,8 @@ +package com.myongsik.myongsikandroid.data.repository.love + +import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity + +interface LoveRepository { + + suspend fun insertFood(insertFoodEntity: InsertFoodEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt new file mode 100644 index 00000000..e2395c3a --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.myongsik.myongsikandroid.data.repository.love + +import com.myongsik.myongsikandroid.data.db.RestaurantDatabase +import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData +import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity +import javax.inject.Inject + +class LoveRepositoryImpl @Inject constructor( + private val loveDb : RestaurantDatabase +) : LoveRepository { + + override suspend fun insertFood(insertFoodEntity: InsertFoodEntity) { + loveDb.restaurantDao().insertGoodFood(insertFoodEntity.toInsertFoodData()) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepository.kt index 84844edb..850546a4 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepository.kt @@ -1,7 +1,7 @@ package com.myongsik.myongsikandroid.data.repository.user -import com.myongsik.myongsikandroid.domain.model.RequestUserEntity -import com.myongsik.myongsikandroid.domain.model.ResponseUserEntity +import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity +import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity interface UserRepository { diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt index 93ef1e11..068847b4 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt @@ -1,13 +1,10 @@ package com.myongsik.myongsikandroid.data.repository.user import com.myongsik.myongsikandroid.data.api.UserApi -import com.myongsik.myongsikandroid.data.model.user.RequestUserData -import com.myongsik.myongsikandroid.data.model.user.ResponseUserData import com.myongsik.myongsikandroid.data.model.user.toRequestUserData import com.myongsik.myongsikandroid.data.model.user.toResponseUserEntity -import com.myongsik.myongsikandroid.domain.model.RequestUserEntity -import com.myongsik.myongsikandroid.domain.model.ResponseUserEntity -import retrofit2.Response +import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity +import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity import javax.inject.Inject class UserRepositoryImpl @Inject constructor(private val userApi: UserApi) : UserRepository { diff --git a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt index 6873fbe6..4ab70222 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt @@ -2,6 +2,8 @@ package com.myongsik.myongsikandroid.di import com.myongsik.myongsikandroid.data.repository.food.FoodRepository import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl +import com.myongsik.myongsikandroid.data.repository.love.LoveRepository +import com.myongsik.myongsikandroid.data.repository.love.LoveRepositoryImpl import com.myongsik.myongsikandroid.data.repository.search.SearchFoodRepository import com.myongsik.myongsikandroid.data.repository.search.SearchFoodRepositoryImpl import com.myongsik.myongsikandroid.data.repository.user.UserRepository @@ -33,4 +35,10 @@ abstract class RepositoryModule { abstract fun bindUserRepository( userRepositoryImpl: UserRepositoryImpl ): UserRepository + + @Singleton + @Binds + abstract fun bindLoveRepository( + loveRepositoryImpl: LoveRepositoryImpl + ): LoveRepository } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/UserCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/UserCase.kt deleted file mode 100644 index e038f300..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/UserCase.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.myongsik.myongsikandroid.domain - -interface UserCase { - -} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt new file mode 100644 index 00000000..874b9f99 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt @@ -0,0 +1,17 @@ +package com.myongsik.myongsikandroid.domain.model.love + +data class InsertFoodEntity( + val address_name: String, + val category_group_code: String, + val category_group_name: String, + val category_name: String, + val distance: String, + val id: String, + val phone: String, + val place_name: String, + val place_url: String, + val road_address_name: String, + val x: String, + val y: String +) + diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/RequestUserEntity.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/user/RequestUserEntity.kt similarity index 50% rename from app/src/main/java/com/myongsik/myongsikandroid/domain/model/RequestUserEntity.kt rename to app/src/main/java/com/myongsik/myongsikandroid/domain/model/user/RequestUserEntity.kt index 9fefbafa..47e8bbf8 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/RequestUserEntity.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/user/RequestUserEntity.kt @@ -1,4 +1,4 @@ -package com.myongsik.myongsikandroid.domain.model +package com.myongsik.myongsikandroid.domain.model.user data class RequestUserEntity( val phoneId: String diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/ResponseUserEntity.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/user/ResponseUserEntity.kt similarity index 80% rename from app/src/main/java/com/myongsik/myongsikandroid/domain/model/ResponseUserEntity.kt rename to app/src/main/java/com/myongsik/myongsikandroid/domain/model/user/ResponseUserEntity.kt index c031c90b..2a89d10e 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/ResponseUserEntity.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/user/ResponseUserEntity.kt @@ -1,4 +1,4 @@ -package com.myongsik.myongsikandroid.domain.model +package com.myongsik.myongsikandroid.domain.model.user data class ResponseUserEntity( val httpCode: Int, diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt new file mode 100644 index 00000000..976e2f01 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt @@ -0,0 +1,13 @@ +package com.myongsik.myongsikandroid.domain.usecase.love + +import com.myongsik.myongsikandroid.data.repository.love.LoveRepository +import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity +import javax.inject.Inject + +class InsertFoodDataUseCase @Inject constructor( + private val loveRepository : LoveRepository +) : LoveCase { + + suspend operator fun invoke(insertFoodEntity: InsertFoodEntity) = + loveRepository.insertFood(insertFoodEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt new file mode 100644 index 00000000..51216085 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt @@ -0,0 +1,5 @@ +package com.myongsik.myongsikandroid.domain.usecase.love + +interface LoveCase { + +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/user/PostUserDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/PostUserDataUseCase.kt similarity index 65% rename from app/src/main/java/com/myongsik/myongsikandroid/domain/user/PostUserDataUseCase.kt rename to app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/PostUserDataUseCase.kt index 703012f5..5c76022d 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/user/PostUserDataUseCase.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/PostUserDataUseCase.kt @@ -1,8 +1,7 @@ -package com.myongsik.myongsikandroid.domain.user +package com.myongsik.myongsikandroid.domain.usecase.user import com.myongsik.myongsikandroid.data.repository.user.UserRepository -import com.myongsik.myongsikandroid.domain.UserCase -import com.myongsik.myongsikandroid.domain.model.RequestUserEntity +import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity import javax.inject.Inject class PostUserDataUseCase @Inject constructor(private val userRepository: UserRepository) : UserCase { diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt new file mode 100644 index 00000000..fc1ad3d4 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt @@ -0,0 +1,5 @@ +package com.myongsik.myongsikandroid.domain.usecase.user + +interface UserCase { + +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/SplashViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/SplashViewModel.kt index e6274ce2..9162c485 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/SplashViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/food/SplashViewModel.kt @@ -7,7 +7,7 @@ import com.myongsik.myongsikandroid.data.model.user.RequestUserData import com.myongsik.myongsikandroid.data.model.user.ResponseUserData import com.myongsik.myongsikandroid.data.model.user.toRequestUserEntity import com.myongsik.myongsikandroid.data.model.user.toResponseUserData -import com.myongsik.myongsikandroid.domain.user.PostUserDataUseCase +import com.myongsik.myongsikandroid.domain.usecase.user.PostUserDataUseCase import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt index 2141d171..f5870ee7 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt @@ -9,7 +9,9 @@ import com.myongsik.myongsikandroid.BaseViewModel import com.myongsik.myongsikandroid.data.model.food.RequestScrap import com.myongsik.myongsikandroid.data.model.food.ResponseScrap import com.myongsik.myongsikandroid.data.model.kakao.Restaurant +import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodEntity import com.myongsik.myongsikandroid.data.repository.food.FoodRepository +import com.myongsik.myongsikandroid.domain.usecase.love.InsertFoodDataUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -18,19 +20,19 @@ import javax.inject.Inject @HiltViewModel class LoveViewModel @Inject constructor( - private val foodRepository: FoodRepository + private val foodRepository: FoodRepository, + private val insertFoodDataUseCase: InsertFoodDataUseCase ) : BaseViewModel() { //Room fun saveFoods(restaurant: Restaurant) = launch { - foodRepository.insertFoods(restaurant) + insertFoodDataUseCase(restaurant.toInsertFoodEntity()) } fun deleteFoods(restaurant: Restaurant) = launch { foodRepository.deleteFoods(restaurant) } - //Api private val _loveIs = MutableLiveData() val loveIs: LiveData get() = _loveIs diff --git a/app/src/main/java/com/myongsik/myongsikandroid/util/FoodEvaluation.kt b/app/src/main/java/com/myongsik/myongsikandroid/util/FoodEvaluation.kt deleted file mode 100644 index b8b63a06..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/util/FoodEvaluation.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.myongsik.myongsikandroid.util - -enum class FoodEvaluation(val value : String){ - GOOD("good"), - HATE("hate") -} \ No newline at end of file From 208a789e0f8d7fa466ede4f170565649ad7f3950 Mon Sep 17 00:00:00 2001 From: SsongSik Date: Sun, 7 May 2023 01:24:10 +0900 Subject: [PATCH 02/11] =?UTF-8?q?[refact]=20:=20#83=20=EA=B4=80=EC=8B=AC?= =?UTF-8?q?=EC=82=AC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myongsikandroid/data/repository/food/FoodRepository.kt | 2 -- .../data/repository/food/FoodRepositoryImpl.kt | 5 ----- 2 files changed, 7 deletions(-) diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt index 1ff1b65a..7f0dd153 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt @@ -54,8 +54,6 @@ interface FoodRepository { suspend fun getCurrentWidgetType(): Flow //Room - suspend fun insertFoods(restaurant: Restaurant) - suspend fun deleteFoods(restaurant: Restaurant) //Room PagingData diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt index ca9a8819..7c3e7ada 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt @@ -295,11 +295,6 @@ class FoodRepositoryImpl @Inject constructor( } } - //장소 찜꽁리스트에 저장 - override suspend fun insertFoods(restaurant: Restaurant) { - db.restaurantDao().insertGoodFood(restaurant) - } - //장소 찜콩리스트에서 삭제 override suspend fun deleteFoods(restaurant: Restaurant) { db.restaurantDao().deleteBook(restaurant) From 1149de7b55d51bc53b99b0822b1ac5e924277141 Mon Sep 17 00:00:00 2001 From: SsongSik Date: Mon, 8 May 2023 21:44:23 +0900 Subject: [PATCH 03/11] =?UTF-8?q?[refact]=20:=20#107=20=EC=B9=B4=EB=A9=9C?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4,=20=ED=95=A8=EC=88=98=EB=AA=85=20PR?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/model/kakao/Restaurant.kt | 34 +++++++++---------- .../data/repository/love/LoveRepository.kt | 8 ----- .../repository/love/LoveRepositoryImpl.kt | 15 -------- .../restaurant/RestaurantRepository.kt | 8 +++++ .../restaurant/RestaurantRepositoryImpl.kt | 15 ++++++++ .../myongsikandroid/di/RepositoryModule.kt | 8 ++--- .../domain/model/love/InsertFoodEntity.kt | 17 ---------- .../restaurant/InsertRestaurantEntity.kt | 17 ++++++++++ .../usecase/love/InsertFoodDataUseCase.kt | 13 ------- .../domain/usecase/love/LoveCase.kt | 5 --- .../restaurant/InsertRestaurantDataUseCase.kt | 13 +++++++ .../domain/usecase/restaurant/LoveCase.kt | 5 +++ .../viewmodel/search/LoveViewModel.kt | 6 ++-- 13 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepository.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/InsertRestaurantEntity.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt index d89548c2..ef167381 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt @@ -4,7 +4,7 @@ package com.myongsik.myongsikandroid.data.model.kakao import android.os.Parcelable import androidx.room.Entity import androidx.room.PrimaryKey -import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity import com.squareup.moshi.Json import com.squareup.moshi.JsonClass import kotlinx.parcelize.Parcelize @@ -40,32 +40,32 @@ data class Restaurant( val y: String ) : Parcelable -fun InsertFoodEntity.toInsertFoodData() = Restaurant( - address_name = this.address_name, - category_group_code = this.category_group_code, - category_group_name = this.category_group_name, - category_name = this.category_name, +fun InsertRestaurantEntity.toInsertFoodData() = Restaurant( + address_name = this.addressName, + category_group_code = this.categoryGroupCode, + category_group_name = this.categoryGroupName, + category_name = this.categoryName, distance = this.distance, id = this.id, phone = this.phone, - place_name = this.place_name, - place_url = this.place_url, - road_address_name = this.road_address_name, + place_name = this.placeName, + place_url = this.placeUrl, + road_address_name = this.roadAddressName, x = this.x, y = this.y ) -fun Restaurant.toInsertFoodEntity() = InsertFoodEntity( - address_name = this.address_name, - category_group_code = this.category_group_code, - category_group_name = this.category_group_name, - category_name = this.category_name, +fun Restaurant.toInsertFoodEntity() = InsertRestaurantEntity( + addressName = this.address_name, + categoryGroupCode = this.category_group_code, + categoryGroupName = this.category_group_name, + categoryName = this.category_name, distance = this.distance, id = this.id, phone = this.phone, - place_name = this.place_name, - place_url = this.place_url, - road_address_name = this.road_address_name, + placeName = this.place_name, + placeUrl = this.place_url, + roadAddressName = this.road_address_name, x = this.x, y = this.y ) \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt deleted file mode 100644 index 1c6f3f7e..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.myongsik.myongsikandroid.data.repository.love - -import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity - -interface LoveRepository { - - suspend fun insertFood(insertFoodEntity: InsertFoodEntity) -} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt deleted file mode 100644 index e2395c3a..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/love/LoveRepositoryImpl.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.myongsik.myongsikandroid.data.repository.love - -import com.myongsik.myongsikandroid.data.db.RestaurantDatabase -import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData -import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity -import javax.inject.Inject - -class LoveRepositoryImpl @Inject constructor( - private val loveDb : RestaurantDatabase -) : LoveRepository { - - override suspend fun insertFood(insertFoodEntity: InsertFoodEntity) { - loveDb.restaurantDao().insertGoodFood(insertFoodEntity.toInsertFoodData()) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepository.kt new file mode 100644 index 00000000..bf1acaa7 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepository.kt @@ -0,0 +1,8 @@ +package com.myongsik.myongsikandroid.data.repository.restaurant + +import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity + +interface RestaurantRepository { + + suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt new file mode 100644 index 00000000..805f8a74 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.myongsik.myongsikandroid.data.repository.restaurant + +import com.myongsik.myongsikandroid.data.db.RestaurantDatabase +import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData +import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import javax.inject.Inject + +class RestaurantRepositoryImpl @Inject constructor( + private val loveDb : RestaurantDatabase +) : RestaurantRepository { + + override suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) { + loveDb.restaurantDao().insertGoodFood(insertRestaurantEntity.toInsertFoodData()) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt index 4ab70222..6e1414f2 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt @@ -2,8 +2,8 @@ package com.myongsik.myongsikandroid.di import com.myongsik.myongsikandroid.data.repository.food.FoodRepository import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl -import com.myongsik.myongsikandroid.data.repository.love.LoveRepository -import com.myongsik.myongsikandroid.data.repository.love.LoveRepositoryImpl +import com.myongsik.myongsikandroid.data.repository.restaurant.RestaurantRepository +import com.myongsik.myongsikandroid.data.repository.restaurant.RestaurantRepositoryImpl import com.myongsik.myongsikandroid.data.repository.search.SearchFoodRepository import com.myongsik.myongsikandroid.data.repository.search.SearchFoodRepositoryImpl import com.myongsik.myongsikandroid.data.repository.user.UserRepository @@ -39,6 +39,6 @@ abstract class RepositoryModule { @Singleton @Binds abstract fun bindLoveRepository( - loveRepositoryImpl: LoveRepositoryImpl - ): LoveRepository + restaurantRepositoryImpl: RestaurantRepositoryImpl + ): RestaurantRepository } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt deleted file mode 100644 index 874b9f99..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/love/InsertFoodEntity.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.myongsik.myongsikandroid.domain.model.love - -data class InsertFoodEntity( - val address_name: String, - val category_group_code: String, - val category_group_name: String, - val category_name: String, - val distance: String, - val id: String, - val phone: String, - val place_name: String, - val place_url: String, - val road_address_name: String, - val x: String, - val y: String -) - diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/InsertRestaurantEntity.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/InsertRestaurantEntity.kt new file mode 100644 index 00000000..1f5f607f --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/InsertRestaurantEntity.kt @@ -0,0 +1,17 @@ +package com.myongsik.myongsikandroid.domain.model.restaurant + +data class InsertRestaurantEntity( + val addressName: String, + val categoryGroupCode: String, + val categoryGroupName: String, + val categoryName: String, + val distance: String, + val id: String, + val phone: String, + val placeName: String, + val placeUrl: String, + val roadAddressName: String, + val x: String, + val y: String +) + diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt deleted file mode 100644 index 976e2f01..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/InsertFoodDataUseCase.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.myongsik.myongsikandroid.domain.usecase.love - -import com.myongsik.myongsikandroid.data.repository.love.LoveRepository -import com.myongsik.myongsikandroid.domain.model.love.InsertFoodEntity -import javax.inject.Inject - -class InsertFoodDataUseCase @Inject constructor( - private val loveRepository : LoveRepository -) : LoveCase { - - suspend operator fun invoke(insertFoodEntity: InsertFoodEntity) = - loveRepository.insertFood(insertFoodEntity) -} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt deleted file mode 100644 index 51216085..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/love/LoveCase.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.myongsik.myongsikandroid.domain.usecase.love - -interface LoveCase { - -} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt new file mode 100644 index 00000000..3eb4093c --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt @@ -0,0 +1,13 @@ +package com.myongsik.myongsikandroid.domain.usecase.restaurant + +import com.myongsik.myongsikandroid.data.repository.restaurant.RestaurantRepository +import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import javax.inject.Inject + +class InsertRestaurantDataUseCase @Inject constructor( + private val restaurantRepository : RestaurantRepository +) : LoveCase { + + suspend operator fun invoke(insertRestaurantEntity: InsertRestaurantEntity) = + restaurantRepository.insertRestaurant(insertRestaurantEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt new file mode 100644 index 00000000..c8d3211a --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt @@ -0,0 +1,5 @@ +package com.myongsik.myongsikandroid.domain.usecase.restaurant + +interface LoveCase { + +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt index f5870ee7..4e4ab69a 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt @@ -11,7 +11,7 @@ import com.myongsik.myongsikandroid.data.model.food.ResponseScrap import com.myongsik.myongsikandroid.data.model.kakao.Restaurant import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodEntity import com.myongsik.myongsikandroid.data.repository.food.FoodRepository -import com.myongsik.myongsikandroid.domain.usecase.love.InsertFoodDataUseCase +import com.myongsik.myongsikandroid.domain.usecase.restaurant.InsertRestaurantDataUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -21,12 +21,12 @@ import javax.inject.Inject @HiltViewModel class LoveViewModel @Inject constructor( private val foodRepository: FoodRepository, - private val insertFoodDataUseCase: InsertFoodDataUseCase + private val insertRestaurantDataUseCase: InsertRestaurantDataUseCase ) : BaseViewModel() { //Room fun saveFoods(restaurant: Restaurant) = launch { - insertFoodDataUseCase(restaurant.toInsertFoodEntity()) + insertRestaurantDataUseCase(restaurant.toInsertFoodEntity()) } fun deleteFoods(restaurant: Restaurant) = launch { From 6515f313f2357eb519616970533209a969a67d62 Mon Sep 17 00:00:00 2001 From: SsongSik Date: Mon, 8 May 2023 22:03:08 +0900 Subject: [PATCH 04/11] =?UTF-8?q?[refact]=20:=20#83=20repository=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repository/restaurant/RestaurantRepositoryImpl.kt | 1 + .../data/repository/user/UserRepositoryImpl.kt | 1 + .../java/com/myongsik/myongsikandroid/di/RepositoryModule.kt | 4 ++-- .../repository/restaurant/RestaurantRepository.kt | 2 +- .../{data => domain}/repository/user/UserRepository.kt | 2 +- .../domain/usecase/restaurant/InsertRestaurantDataUseCase.kt | 4 ++-- .../myongsikandroid/domain/usecase/restaurant/LoveCase.kt | 5 ----- .../domain/usecase/user/PostUserDataUseCase.kt | 4 ++-- .../myongsik/myongsikandroid/domain/usecase/user/UserCase.kt | 5 ----- 9 files changed, 10 insertions(+), 18 deletions(-) rename app/src/main/java/com/myongsik/myongsikandroid/{data => domain}/repository/restaurant/RestaurantRepository.kt (75%) rename app/src/main/java/com/myongsik/myongsikandroid/{data => domain}/repository/user/UserRepository.kt (81%) delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt index 805f8a74..e507d481 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt @@ -3,6 +3,7 @@ package com.myongsik.myongsikandroid.data.repository.restaurant import com.myongsik.myongsikandroid.data.db.RestaurantDatabase import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository import javax.inject.Inject class RestaurantRepositoryImpl @Inject constructor( diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt index 068847b4..f916f655 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt @@ -5,6 +5,7 @@ import com.myongsik.myongsikandroid.data.model.user.toRequestUserData import com.myongsik.myongsikandroid.data.model.user.toResponseUserEntity import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity +import com.myongsik.myongsikandroid.domain.repository.user.UserRepository import javax.inject.Inject class UserRepositoryImpl @Inject constructor(private val userApi: UserApi) : UserRepository { diff --git a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt index 6e1414f2..6bf7e8fe 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt @@ -2,11 +2,11 @@ package com.myongsik.myongsikandroid.di import com.myongsik.myongsikandroid.data.repository.food.FoodRepository import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl -import com.myongsik.myongsikandroid.data.repository.restaurant.RestaurantRepository +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository import com.myongsik.myongsikandroid.data.repository.restaurant.RestaurantRepositoryImpl import com.myongsik.myongsikandroid.data.repository.search.SearchFoodRepository import com.myongsik.myongsikandroid.data.repository.search.SearchFoodRepositoryImpl -import com.myongsik.myongsikandroid.data.repository.user.UserRepository +import com.myongsik.myongsikandroid.domain.repository.user.UserRepository import com.myongsik.myongsikandroid.data.repository.user.UserRepositoryImpl import dagger.Binds import dagger.Module diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt similarity index 75% rename from app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepository.kt rename to app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt index bf1acaa7..e67e2ecf 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt @@ -1,4 +1,4 @@ -package com.myongsik.myongsikandroid.data.repository.restaurant +package com.myongsik.myongsikandroid.domain.repository.restaurant import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/user/UserRepository.kt similarity index 81% rename from app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepository.kt rename to app/src/main/java/com/myongsik/myongsikandroid/domain/repository/user/UserRepository.kt index 850546a4..40eda3fb 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/user/UserRepository.kt @@ -1,4 +1,4 @@ -package com.myongsik.myongsikandroid.data.repository.user +package com.myongsik.myongsikandroid.domain.repository.user import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt index 3eb4093c..c97cedfb 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt @@ -1,12 +1,12 @@ package com.myongsik.myongsikandroid.domain.usecase.restaurant -import com.myongsik.myongsikandroid.data.repository.restaurant.RestaurantRepository +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity import javax.inject.Inject class InsertRestaurantDataUseCase @Inject constructor( private val restaurantRepository : RestaurantRepository -) : LoveCase { +) { suspend operator fun invoke(insertRestaurantEntity: InsertRestaurantEntity) = restaurantRepository.insertRestaurant(insertRestaurantEntity) diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt deleted file mode 100644 index c8d3211a..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveCase.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.myongsik.myongsikandroid.domain.usecase.restaurant - -interface LoveCase { - -} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/PostUserDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/PostUserDataUseCase.kt index 5c76022d..ecde165f 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/PostUserDataUseCase.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/PostUserDataUseCase.kt @@ -1,9 +1,9 @@ package com.myongsik.myongsikandroid.domain.usecase.user -import com.myongsik.myongsikandroid.data.repository.user.UserRepository +import com.myongsik.myongsikandroid.domain.repository.user.UserRepository import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity import javax.inject.Inject -class PostUserDataUseCase @Inject constructor(private val userRepository: UserRepository) : UserCase { +class PostUserDataUseCase @Inject constructor(private val userRepository: UserRepository) { suspend operator fun invoke(requestUserEntity: RequestUserEntity) = userRepository.postUser(requestUserEntity) } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt deleted file mode 100644 index fc1ad3d4..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/user/UserCase.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.myongsik.myongsikandroid.domain.usecase.user - -interface UserCase { - -} \ No newline at end of file From 0a4af6f37460a204c2a4e22cb8bc8c9b4d524fca Mon Sep 17 00:00:00 2001 From: SsongSik Date: Mon, 8 May 2023 22:38:09 +0900 Subject: [PATCH 05/11] =?UTF-8?q?[refact]=20:=20#83=20DataSource=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/restaurant/RestaurantDataSource.kt | 8 ++++++++ .../restaurant/RestaurantDataSourceImpl.kt | 15 +++++++++++++++ .../restaurant/RestaurantRepositoryImpl.kt | 5 +++-- .../myongsikandroid/di/RepositoryModule.kt | 12 +++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt new file mode 100644 index 00000000..58d5cc59 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt @@ -0,0 +1,8 @@ +package com.myongsik.myongsikandroid.data.datasource.restaurant + +import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity + +interface RestaurantDataSource { + + suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt new file mode 100644 index 00000000..f02245ba --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt @@ -0,0 +1,15 @@ +package com.myongsik.myongsikandroid.data.datasource.restaurant + +import com.myongsik.myongsikandroid.data.db.RestaurantDatabase +import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData +import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import javax.inject.Inject + +class RestaurantDataSourceImpl @Inject constructor( + private val loveDb : RestaurantDatabase +) : RestaurantDataSource { + + override suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) { + loveDb.restaurantDao().insertGoodFood(insertRestaurantEntity.toInsertFoodData()) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt index e507d481..d69fa0c1 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt @@ -1,5 +1,6 @@ package com.myongsik.myongsikandroid.data.repository.restaurant +import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSource import com.myongsik.myongsikandroid.data.db.RestaurantDatabase import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity @@ -7,10 +8,10 @@ import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepos import javax.inject.Inject class RestaurantRepositoryImpl @Inject constructor( - private val loveDb : RestaurantDatabase + private val restaurantDataSource: RestaurantDataSource ) : RestaurantRepository { override suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) { - loveDb.restaurantDao().insertGoodFood(insertRestaurantEntity.toInsertFoodData()) + restaurantDataSource.insertRestaurant(insertRestaurantEntity) } } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt index 6bf7e8fe..70125ff9 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt @@ -1,5 +1,7 @@ package com.myongsik.myongsikandroid.di +import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSource +import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSourceImpl import com.myongsik.myongsikandroid.data.repository.food.FoodRepository import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository @@ -18,6 +20,7 @@ import javax.inject.Singleton @InstallIn(SingletonComponent::class) abstract class RepositoryModule { + //Repository @Singleton @Binds abstract fun bindFoodRepository( @@ -38,7 +41,14 @@ abstract class RepositoryModule { @Singleton @Binds - abstract fun bindLoveRepository( + abstract fun bindRestaurantRepository( restaurantRepositoryImpl: RestaurantRepositoryImpl ): RestaurantRepository + + //DataSource + @Singleton + @Binds + abstract fun bindRestaurantDataSource( + restaurantDataSource: RestaurantDataSourceImpl + ): RestaurantDataSource } \ No newline at end of file From 78b0f11c24a0fcb1b187e5ef25b1f562b1170a5e Mon Sep 17 00:00:00 2001 From: SsongSik Date: Tue, 9 May 2023 09:27:31 +0900 Subject: [PATCH 06/11] =?UTF-8?q?[refactor]=20:=20#83=20User=20DataSource?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/user/UserDataSource.kt | 9 +++++++ .../datasource/user/UserDataSourceImpl.kt | 25 +++++++++++++++++++ .../repository/user/UserRepositoryImpl.kt | 16 +++++------- .../myongsikandroid/di/RepositoryModule.kt | 8 ++++++ 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSource.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSource.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSource.kt new file mode 100644 index 00000000..8a517fbe --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSource.kt @@ -0,0 +1,9 @@ +package com.myongsik.myongsikandroid.data.datasource.user + +import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity +import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity + +interface UserDataSource { + + suspend fun postUser(requestUserEntity: RequestUserEntity): ResponseUserEntity? +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt new file mode 100644 index 00000000..91956ca2 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt @@ -0,0 +1,25 @@ +package com.myongsik.myongsikandroid.data.datasource.user + +import com.myongsik.myongsikandroid.data.api.UserApi +import com.myongsik.myongsikandroid.data.db.RestaurantDatabase +import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData +import com.myongsik.myongsikandroid.data.model.user.toRequestUserData +import com.myongsik.myongsikandroid.data.model.user.toResponseUserEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity +import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity +import javax.inject.Inject + +class UserDataSourceImpl @Inject constructor( + private val userApi: UserApi +) : UserDataSource { + + override suspend fun postUser(requestUserEntity: RequestUserEntity): ResponseUserEntity? { + val response = userApi.postUser(requestUserEntity.toRequestUserData()) + return if (response.isSuccessful) { + response.body()?.toResponseUserEntity() + } else { + null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt index f916f655..6acef086 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/user/UserRepositoryImpl.kt @@ -1,20 +1,16 @@ package com.myongsik.myongsikandroid.data.repository.user -import com.myongsik.myongsikandroid.data.api.UserApi -import com.myongsik.myongsikandroid.data.model.user.toRequestUserData -import com.myongsik.myongsikandroid.data.model.user.toResponseUserEntity +import com.myongsik.myongsikandroid.data.datasource.user.UserDataSource import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity import com.myongsik.myongsikandroid.domain.repository.user.UserRepository import javax.inject.Inject -class UserRepositoryImpl @Inject constructor(private val userApi: UserApi) : UserRepository { +class UserRepositoryImpl @Inject constructor( + private val userDataSource: UserDataSource +) : UserRepository { + override suspend fun postUser(requestUserEntity: RequestUserEntity): ResponseUserEntity? { - val response = userApi.postUser(requestUserEntity.toRequestUserData()) - return if (response.isSuccessful) { - response.body()?.toResponseUserEntity() - } else { - null - } + return userDataSource.postUser(requestUserEntity) } } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt index 70125ff9..401e7310 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/di/RepositoryModule.kt @@ -2,6 +2,8 @@ package com.myongsik.myongsikandroid.di import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSource import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSourceImpl +import com.myongsik.myongsikandroid.data.datasource.user.UserDataSource +import com.myongsik.myongsikandroid.data.datasource.user.UserDataSourceImpl import com.myongsik.myongsikandroid.data.repository.food.FoodRepository import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository @@ -51,4 +53,10 @@ abstract class RepositoryModule { abstract fun bindRestaurantDataSource( restaurantDataSource: RestaurantDataSourceImpl ): RestaurantDataSource + + @Singleton + @Binds + abstract fun bindUserDataSource( + userDataSourceImpl: UserDataSourceImpl + ): UserDataSource } \ No newline at end of file From 10ed1c2f6e34a001e658696b8de6078c0b51e8de Mon Sep 17 00:00:00 2001 From: SsongSik Date: Tue, 9 May 2023 15:24:56 +0900 Subject: [PATCH 07/11] =?UTF-8?q?[refactor]=20:=20#83=20=EC=B0=9C=EA=BD=81?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20Room=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=ED=81=B4=EB=A6=B0=EC=95=84=ED=82=A4=ED=85=8D=EC=B2=98=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restaurant/RestaurantDataSource.kt | 8 +++++-- .../restaurant/RestaurantDataSourceImpl.kt | 16 +++++++++---- .../datasource/user/UserDataSourceImpl.kt | 3 --- .../data/model/kakao/Restaurant.kt | 6 ++--- .../data/repository/food/FoodRepository.kt | 5 ---- .../repository/food/FoodRepositoryImpl.kt | 10 -------- .../restaurant/RestaurantRepositoryImpl.kt | 15 ++++++++---- ...estaurantEntity.kt => RestaurantEntity.kt} | 2 +- .../restaurant/RestaurantRepository.kt | 8 +++++-- .../restaurant/DeleteRestaurantDataUseCase.kt | 13 +++++++++++ .../restaurant/InsertRestaurantDataUseCase.kt | 6 ++--- .../restaurant/LoveIsRestaurantDataUseCase.kt | 11 +++++++++ .../viewmodel/search/LoveViewModel.kt | 23 +++++++++++-------- 13 files changed, 79 insertions(+), 47 deletions(-) rename app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/{InsertRestaurantEntity.kt => RestaurantEntity.kt} (91%) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/DeleteRestaurantDataUseCase.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveIsRestaurantDataUseCase.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt index 58d5cc59..1ea5c49f 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt @@ -1,8 +1,12 @@ package com.myongsik.myongsikandroid.data.datasource.restaurant -import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity interface RestaurantDataSource { - suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) + suspend fun insertRestaurant(restaurantEntity: RestaurantEntity) + + suspend fun deleteRestaurant(restaurantEntity: RestaurantEntity) + + suspend fun loveIs(id: String): RestaurantEntity } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt index f02245ba..bc46fa07 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt @@ -1,15 +1,23 @@ package com.myongsik.myongsikandroid.data.datasource.restaurant import com.myongsik.myongsikandroid.data.db.RestaurantDatabase -import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData -import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantData +import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import javax.inject.Inject class RestaurantDataSourceImpl @Inject constructor( private val loveDb : RestaurantDatabase ) : RestaurantDataSource { - override suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) { - loveDb.restaurantDao().insertGoodFood(insertRestaurantEntity.toInsertFoodData()) + override suspend fun insertRestaurant(restaurantEntity: RestaurantEntity) { + loveDb.restaurantDao().insertGoodFood(restaurantEntity.toRestaurantData()) } + + override suspend fun deleteRestaurant(restaurantEntity: RestaurantEntity) { + loveDb.restaurantDao().deleteBook(restaurantEntity.toRestaurantData()) + } + + override suspend fun loveIs(id: String): RestaurantEntity = loveDb.restaurantDao().loveIs(id).toRestaurantEntity() + } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt index 91956ca2..62e72d76 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt @@ -1,11 +1,8 @@ package com.myongsik.myongsikandroid.data.datasource.user import com.myongsik.myongsikandroid.data.api.UserApi -import com.myongsik.myongsikandroid.data.db.RestaurantDatabase -import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData import com.myongsik.myongsikandroid.data.model.user.toRequestUserData import com.myongsik.myongsikandroid.data.model.user.toResponseUserEntity -import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity import com.myongsik.myongsikandroid.domain.model.user.RequestUserEntity import com.myongsik.myongsikandroid.domain.model.user.ResponseUserEntity import javax.inject.Inject diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt index ef167381..083f252f 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/model/kakao/Restaurant.kt @@ -4,7 +4,7 @@ package com.myongsik.myongsikandroid.data.model.kakao import android.os.Parcelable import androidx.room.Entity import androidx.room.PrimaryKey -import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import com.squareup.moshi.Json import com.squareup.moshi.JsonClass import kotlinx.parcelize.Parcelize @@ -40,7 +40,7 @@ data class Restaurant( val y: String ) : Parcelable -fun InsertRestaurantEntity.toInsertFoodData() = Restaurant( +fun RestaurantEntity.toRestaurantData() = Restaurant( address_name = this.addressName, category_group_code = this.categoryGroupCode, category_group_name = this.categoryGroupName, @@ -55,7 +55,7 @@ fun InsertRestaurantEntity.toInsertFoodData() = Restaurant( y = this.y ) -fun Restaurant.toInsertFoodEntity() = InsertRestaurantEntity( +fun Restaurant.toRestaurantEntity() = RestaurantEntity( addressName = this.address_name, categoryGroupCode = this.category_group_code, categoryGroupName = this.category_group_name, diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt index 7f0dd153..cfb18e87 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt @@ -53,14 +53,9 @@ interface FoodRepository { suspend fun getCurrentWidgetType(): Flow - //Room - suspend fun deleteFoods(restaurant: Restaurant) - //Room PagingData fun getFoods(): Flow> - fun loveIs(id: String): Restaurant - fun updateLove(id: String): Boolean fun getLoveIsFood() : Flow> diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt index 7c3e7ada..77b5a588 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt @@ -295,16 +295,6 @@ class FoodRepositoryImpl @Inject constructor( } } - //장소 찜콩리스트에서 삭제 - override suspend fun deleteFoods(restaurant: Restaurant) { - db.restaurantDao().deleteBook(restaurant) - } - - //장소 현재 찜해두었는지 판단 - override fun loveIs(id: String): Restaurant { - return db.restaurantDao().loveIs(id) - } - override fun updateLove(id: String): Boolean { if (!db.restaurantDao().loveUpdate(id)) { return false diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt index d69fa0c1..dce48038 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt @@ -1,9 +1,7 @@ package com.myongsik.myongsikandroid.data.repository.restaurant import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSource -import com.myongsik.myongsikandroid.data.db.RestaurantDatabase -import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodData -import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository import javax.inject.Inject @@ -11,7 +9,14 @@ class RestaurantRepositoryImpl @Inject constructor( private val restaurantDataSource: RestaurantDataSource ) : RestaurantRepository { - override suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) { - restaurantDataSource.insertRestaurant(insertRestaurantEntity) + override suspend fun insertRestaurant(restaurantEntity: RestaurantEntity) { + restaurantDataSource.insertRestaurant(restaurantEntity) } + + override suspend fun deleteRestaurant(restaurantEntity: RestaurantEntity) { + restaurantDataSource.deleteRestaurant(restaurantEntity) + } + + override suspend fun loveIs(id: String): RestaurantEntity = restaurantDataSource.loveIs(id) + } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/InsertRestaurantEntity.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/RestaurantEntity.kt similarity index 91% rename from app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/InsertRestaurantEntity.kt rename to app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/RestaurantEntity.kt index 1f5f607f..9da3d211 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/InsertRestaurantEntity.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/RestaurantEntity.kt @@ -1,6 +1,6 @@ package com.myongsik.myongsikandroid.domain.model.restaurant -data class InsertRestaurantEntity( +data class RestaurantEntity( val addressName: String, val categoryGroupCode: String, val categoryGroupName: String, diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt index e67e2ecf..f6bb6a80 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt @@ -1,8 +1,12 @@ package com.myongsik.myongsikandroid.domain.repository.restaurant -import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity interface RestaurantRepository { - suspend fun insertRestaurant(insertRestaurantEntity: InsertRestaurantEntity) + suspend fun insertRestaurant(restaurantEntity: RestaurantEntity) + + suspend fun deleteRestaurant(restaurantEntity: RestaurantEntity) + + suspend fun loveIs(id : String) : RestaurantEntity } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/DeleteRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/DeleteRestaurantDataUseCase.kt new file mode 100644 index 00000000..aa896715 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/DeleteRestaurantDataUseCase.kt @@ -0,0 +1,13 @@ +package com.myongsik.myongsikandroid.domain.usecase.restaurant + +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository +import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity +import javax.inject.Inject + +class DeleteRestaurantDataUseCase @Inject constructor( + private val restaurantRepository : RestaurantRepository +) { + + suspend operator fun invoke(restaurantEntity: RestaurantEntity) = + restaurantRepository.deleteRestaurant(restaurantEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt index c97cedfb..a15d9c21 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/InsertRestaurantDataUseCase.kt @@ -1,13 +1,13 @@ package com.myongsik.myongsikandroid.domain.usecase.restaurant import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository -import com.myongsik.myongsikandroid.domain.model.restaurant.InsertRestaurantEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import javax.inject.Inject class InsertRestaurantDataUseCase @Inject constructor( private val restaurantRepository : RestaurantRepository ) { - suspend operator fun invoke(insertRestaurantEntity: InsertRestaurantEntity) = - restaurantRepository.insertRestaurant(insertRestaurantEntity) + suspend operator fun invoke(restaurantEntity: RestaurantEntity) = + restaurantRepository.insertRestaurant(restaurantEntity) } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveIsRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveIsRestaurantDataUseCase.kt new file mode 100644 index 00000000..84568499 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/LoveIsRestaurantDataUseCase.kt @@ -0,0 +1,11 @@ +package com.myongsik.myongsikandroid.domain.usecase.restaurant + +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository +import javax.inject.Inject + +class LoveIsRestaurantDataUseCase @Inject constructor( + private val restaurantRepository : RestaurantRepository +) { + + suspend operator fun invoke(id : String) = restaurantRepository.loveIs(id) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt index 4e4ab69a..7bf44ee7 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt @@ -9,28 +9,32 @@ import com.myongsik.myongsikandroid.BaseViewModel import com.myongsik.myongsikandroid.data.model.food.RequestScrap import com.myongsik.myongsikandroid.data.model.food.ResponseScrap import com.myongsik.myongsikandroid.data.model.kakao.Restaurant -import com.myongsik.myongsikandroid.data.model.kakao.toInsertFoodEntity +import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantData +import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantEntity import com.myongsik.myongsikandroid.data.repository.food.FoodRepository +import com.myongsik.myongsikandroid.domain.usecase.restaurant.DeleteRestaurantDataUseCase import com.myongsik.myongsikandroid.domain.usecase.restaurant.InsertRestaurantDataUseCase +import com.myongsik.myongsikandroid.domain.usecase.restaurant.LoveIsRestaurantDataUseCase import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class LoveViewModel @Inject constructor( private val foodRepository: FoodRepository, - private val insertRestaurantDataUseCase: InsertRestaurantDataUseCase + private val insertRestaurantDataUseCase: InsertRestaurantDataUseCase, + private val deleteRestaurantDataUseCase: DeleteRestaurantDataUseCase, + private val loveIsRestaurantDataUseCase: LoveIsRestaurantDataUseCase ) : BaseViewModel() { //Room fun saveFoods(restaurant: Restaurant) = launch { - insertRestaurantDataUseCase(restaurant.toInsertFoodEntity()) + insertRestaurantDataUseCase(restaurant.toRestaurantEntity()) } fun deleteFoods(restaurant: Restaurant) = launch { - foodRepository.deleteFoods(restaurant) + deleteRestaurantDataUseCase(restaurant.toRestaurantEntity()) } private val _loveIs = MutableLiveData() @@ -38,8 +42,9 @@ class LoveViewModel @Inject constructor( get() = _loveIs fun loveIs(restaurant: Restaurant) = launch { - val restaurantLove = foodRepository.loveIs(restaurant.id) - _loveIs.postValue(restaurantLove) + loveIsRestaurantDataUseCase(restaurant.id).let{ + _loveIs.postValue(it.toRestaurantData()) + } } val loveIsFood: StateFlow> = foodRepository.getLoveIsFood() From 502d049343635ccd518d460ea1127b33e3fdee99 Mon Sep 17 00:00:00 2001 From: SsongSik Date: Wed, 10 May 2023 01:34:33 +0900 Subject: [PATCH 08/11] =?UTF-8?q?[refactor]=20:=20#83=20Room=20PagingData?= =?UTF-8?q?=20=ED=81=B4=EB=A6=B0=EC=95=84=ED=82=A4=ED=85=8D=EC=B2=98=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restaurant/RestaurantDataSource.kt | 6 +++ .../restaurant/RestaurantDataSourceImpl.kt | 36 ++++++++++++++-- .../myongsikandroid/data/db/RestaurantDao.kt | 2 +- .../data/repository/food/FoodRepository.kt | 7 ---- .../repository/food/FoodRepositoryImpl.kt | 25 ----------- .../restaurant/RestaurantRepositoryImpl.kt | 8 ++++ .../restaurant/RestaurantRepository.kt | 6 +++ .../GetListRestaurantDataUseCase.kt | 11 +++++ .../GetPagingRestaurantDataUseCase.kt | 11 +++++ .../view/food/MapDetailBottomSheetDialog.kt | 19 +++++---- .../presentation/view/search/LoveFragment.kt | 6 ++- .../view/search/RestaurantFragment.kt | 21 ++++++---- .../viewmodel/search/LoveViewModel.kt | 41 +++++++++++++------ 13 files changed, 133 insertions(+), 66 deletions(-) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetListRestaurantDataUseCase.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetPagingRestaurantDataUseCase.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt index 1ea5c49f..9c6cd35d 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt @@ -1,6 +1,8 @@ package com.myongsik.myongsikandroid.data.datasource.restaurant +import androidx.paging.PagingData import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity +import kotlinx.coroutines.flow.Flow interface RestaurantDataSource { @@ -9,4 +11,8 @@ interface RestaurantDataSource { suspend fun deleteRestaurant(restaurantEntity: RestaurantEntity) suspend fun loveIs(id: String): RestaurantEntity + + suspend fun getLoveRestaurant(): Flow> + + suspend fun getLoveListRestaurant() : Flow> } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt index bc46fa07..06281ae4 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt @@ -1,13 +1,21 @@ package com.myongsik.myongsikandroid.data.datasource.restaurant +import androidx.paging.Pager +import androidx.paging.PagingConfig +import androidx.paging.PagingData +import androidx.paging.map import com.myongsik.myongsikandroid.data.db.RestaurantDatabase +import com.myongsik.myongsikandroid.data.model.kakao.Restaurant import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantData import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantEntity import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity +import com.myongsik.myongsikandroid.util.Constant +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map import javax.inject.Inject -class RestaurantDataSourceImpl @Inject constructor( - private val loveDb : RestaurantDatabase +class RestaurantDataSourceImpl @Inject constructor( + private val loveDb: RestaurantDatabase ) : RestaurantDataSource { override suspend fun insertRestaurant(restaurantEntity: RestaurantEntity) { @@ -18,6 +26,28 @@ class RestaurantDataSourceImpl @Inject constructor( loveDb.restaurantDao().deleteBook(restaurantEntity.toRestaurantData()) } - override suspend fun loveIs(id: String): RestaurantEntity = loveDb.restaurantDao().loveIs(id).toRestaurantEntity() + override suspend fun loveIs(id: String): RestaurantEntity = + loveDb.restaurantDao().loveIs(id).toRestaurantEntity() + + override suspend fun getLoveRestaurant(): Flow> { + val pagingSourceFactory = { + loveDb.restaurantDao().getFoods() + } + + return Pager( + config = PagingConfig( + pageSize = Constant.PAGING_SIZE, + enablePlaceholders = false, + maxSize = Constant.PAGING_SIZE * 3 + ), + pagingSourceFactory = pagingSourceFactory + ).flow + .map { pagingData -> pagingData.map { it.toRestaurantEntity() } } + } + + override suspend fun getLoveListRestaurant(): Flow> { + return loveDb.restaurantDao().getIsLoveFood() + .map { restaurantList -> restaurantList.map { it.toRestaurantEntity() } } + } } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/db/RestaurantDao.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/db/RestaurantDao.kt index adfc3252..179a7834 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/db/RestaurantDao.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/db/RestaurantDao.kt @@ -25,7 +25,7 @@ interface RestaurantDao { //관심목록에 담기를 클릭했을 때 이미 있는지 판단하는 쿼리 @Query("SELECT * FROM love_list WHERE id = :id") - fun loveIs(id : String) : Restaurant + suspend fun loveIs(id : String) : Restaurant //찜꽁 리스트에서 삭제하는 쿼리 @Delete diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt index cfb18e87..7b0af243 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt @@ -52,11 +52,4 @@ interface FoodRepository { suspend fun getCurrentSortType(): Flow suspend fun getCurrentWidgetType(): Flow - - //Room PagingData - fun getFoods(): Flow> - - fun updateLove(id: String): Boolean - - fun getLoveIsFood() : Flow> } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt index 77b5a588..4f99c299 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt @@ -294,29 +294,4 @@ class FoodRepositoryImpl @Inject constructor( prefs[DataStoreKey.WIDGET_TYPE] } } - - override fun updateLove(id: String): Boolean { - if (!db.restaurantDao().loveUpdate(id)) { - return false - } - return true - } - - override fun getLoveIsFood(): Flow> { - return db.restaurantDao().getIsLoveFood() - } - - //음식 조회 페이징 처리 - override fun getFoods(): Flow> { - val pagingSourceFactory = { db.restaurantDao().getFoods() } - - return Pager( - config = PagingConfig( - pageSize = Constant.PAGING_SIZE, - enablePlaceholders = false, - maxSize = Constant.PAGING_SIZE * 3 - ), - pagingSourceFactory = pagingSourceFactory - ).flow - } } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt index dce48038..f3f653dc 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt @@ -1,8 +1,10 @@ package com.myongsik.myongsikandroid.data.repository.restaurant +import androidx.paging.PagingData import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSource import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository +import kotlinx.coroutines.flow.Flow import javax.inject.Inject class RestaurantRepositoryImpl @Inject constructor( @@ -19,4 +21,10 @@ class RestaurantRepositoryImpl @Inject constructor( override suspend fun loveIs(id: String): RestaurantEntity = restaurantDataSource.loveIs(id) + override suspend fun getLoveRestaurant(): Flow> + = restaurantDataSource.getLoveRestaurant() + + override suspend fun getLoveListRestaurant(): Flow> + = restaurantDataSource.getLoveListRestaurant() + } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt index f6bb6a80..22da08ae 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt @@ -1,6 +1,8 @@ package com.myongsik.myongsikandroid.domain.repository.restaurant +import androidx.paging.PagingData import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity +import kotlinx.coroutines.flow.Flow interface RestaurantRepository { @@ -9,4 +11,8 @@ interface RestaurantRepository { suspend fun deleteRestaurant(restaurantEntity: RestaurantEntity) suspend fun loveIs(id : String) : RestaurantEntity + + suspend fun getLoveRestaurant(): Flow> + + suspend fun getLoveListRestaurant() : Flow> } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetListRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetListRestaurantDataUseCase.kt new file mode 100644 index 00000000..eb9e6868 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetListRestaurantDataUseCase.kt @@ -0,0 +1,11 @@ +package com.myongsik.myongsikandroid.domain.usecase.restaurant + +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository +import javax.inject.Inject + +class GetListRestaurantDataUseCase @Inject constructor( + private val restaurantRepository : RestaurantRepository +) { + + suspend operator fun invoke() = restaurantRepository.getLoveListRestaurant() +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetPagingRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetPagingRestaurantDataUseCase.kt new file mode 100644 index 00000000..795f97fa --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/GetPagingRestaurantDataUseCase.kt @@ -0,0 +1,11 @@ +package com.myongsik.myongsikandroid.domain.usecase.restaurant + +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository +import javax.inject.Inject + +class GetPagingRestaurantDataUseCase @Inject constructor( + private val restaurantRepository : RestaurantRepository +) { + + suspend operator fun invoke() = restaurantRepository.getLoveRestaurant() +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt index 7a4126b6..66e988f6 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt @@ -8,6 +8,7 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.viewModels +import androidx.lifecycle.lifecycleScope import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.myongsik.myongsikandroid.R @@ -19,6 +20,8 @@ import com.myongsik.myongsikandroid.presentation.viewmodel.search.LoveViewModel import com.myongsik.myongsikandroid.util.CommonUtil import com.myongsik.myongsikandroid.util.MyongsikApplication import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.launch @AndroidEntryPoint class MapDetailBottomSheetDialog(private val restaurantId: Int) : BottomSheetDialogFragment() { @@ -90,13 +93,15 @@ class MapDetailBottomSheetDialog(private val restaurantId: Int) : BottomSheetDia loveViewModel.loveIs(restaurant!!) } - loveViewModel.loveIs.observe(viewLifecycleOwner) { - if (it == null) { - dialogBottomLoveIv.visibility = View.VISIBLE - dialogBottomScrapIv.visibility = View.INVISIBLE - } else { - dialogBottomLoveIv.visibility = View.INVISIBLE - dialogBottomScrapIv.visibility = View.VISIBLE + viewLifecycleOwner.lifecycleScope.launch{ + loveViewModel.loveIs.collectLatest { + if (it == null) { + dialogBottomLoveIv.visibility = View.VISIBLE + dialogBottomScrapIv.visibility = View.INVISIBLE + } else { + dialogBottomLoveIv.visibility = View.INVISIBLE + dialogBottomScrapIv.visibility = View.VISIBLE + } } } diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/LoveFragment.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/LoveFragment.kt index 23311ebd..fd6b340f 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/LoveFragment.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/LoveFragment.kt @@ -40,6 +40,8 @@ class LoveFragment : BaseFragment(), OnSearchViewHolderClic } override fun initListener() { + loveViewModel.getLoveListRestaurant() + loveViewModel.getLoveRestaurant() getFavoriteRestaurant() settingBackPressedCallback(object : OnBackPressedCallback(true) { @@ -53,13 +55,13 @@ class LoveFragment : BaseFragment(), OnSearchViewHolderClic private fun getFavoriteRestaurant(){ viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED){ - loveViewModel.loveIsFood.collectLatest { + loveViewModel.loveListRestaurants.collectLatest { if(it.isEmpty()){ binding.favoriteEmptyLove.visibility = View.VISIBLE } else { binding.favoriteEmptyLove.visibility = View.INVISIBLE } - loveViewModel.loveFoods.collectLatest { pagedData -> + loveViewModel.loveRestaurants.collectLatest { pagedData -> loveFoodAdapter.submitData(pagedData) } } diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt index 7eee0a4a..129cdef6 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt @@ -8,6 +8,7 @@ import android.webkit.WebView import android.webkit.WebViewClient import androidx.activity.OnBackPressedCallback import androidx.fragment.app.viewModels +import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.google.android.material.snackbar.Snackbar @@ -17,6 +18,8 @@ import com.myongsik.myongsikandroid.databinding.FragmentRestaurantBinding import com.myongsik.myongsikandroid.presentation.viewmodel.search.LoveViewModel import com.myongsik.myongsikandroid.util.MyongsikApplication import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.launch //장소 상세화면 @AndroidEntryPoint @@ -102,14 +105,16 @@ class RestaurantFragment : BaseFragment() { } private fun favoriteRestaurantGet(){ - loveViewModel.loveIs.observe(viewLifecycleOwner){ - if(it == null){ - binding.fabFavorite.visibility = View.VISIBLE - binding.fabFavoriteLove.visibility = View.INVISIBLE - } - else{ - binding.fabFavorite.visibility = View.INVISIBLE - binding.fabFavoriteLove.visibility = View.VISIBLE + viewLifecycleOwner.lifecycleScope.launch{ + loveViewModel.loveIs.collectLatest { + if(it == null){ + binding.fabFavorite.visibility = View.VISIBLE + binding.fabFavoriteLove.visibility = View.INVISIBLE + } + else{ + binding.fabFavorite.visibility = View.INVISIBLE + binding.fabFavoriteLove.visibility = View.VISIBLE + } } } } diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt index 7bf44ee7..be5fefa7 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import androidx.paging.PagingData import androidx.paging.cachedIn +import androidx.paging.map import com.myongsik.myongsikandroid.BaseViewModel import com.myongsik.myongsikandroid.data.model.food.RequestScrap import com.myongsik.myongsikandroid.data.model.food.ResponseScrap @@ -12,12 +13,9 @@ import com.myongsik.myongsikandroid.data.model.kakao.Restaurant import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantData import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantEntity import com.myongsik.myongsikandroid.data.repository.food.FoodRepository -import com.myongsik.myongsikandroid.domain.usecase.restaurant.DeleteRestaurantDataUseCase -import com.myongsik.myongsikandroid.domain.usecase.restaurant.InsertRestaurantDataUseCase -import com.myongsik.myongsikandroid.domain.usecase.restaurant.LoveIsRestaurantDataUseCase +import com.myongsik.myongsikandroid.domain.usecase.restaurant.* import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.* -import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel @@ -25,7 +23,9 @@ class LoveViewModel @Inject constructor( private val foodRepository: FoodRepository, private val insertRestaurantDataUseCase: InsertRestaurantDataUseCase, private val deleteRestaurantDataUseCase: DeleteRestaurantDataUseCase, - private val loveIsRestaurantDataUseCase: LoveIsRestaurantDataUseCase + private val loveIsRestaurantDataUseCase: LoveIsRestaurantDataUseCase, + private val getListRestaurantDataUseCase: GetListRestaurantDataUseCase, + private val getPagingRestaurantDataUseCase: GetPagingRestaurantDataUseCase ) : BaseViewModel() { //Room @@ -37,23 +37,38 @@ class LoveViewModel @Inject constructor( deleteRestaurantDataUseCase(restaurant.toRestaurantEntity()) } - private val _loveIs = MutableLiveData() - val loveIs: LiveData - get() = _loveIs + private val _loveIs = MutableStateFlow(null) + val loveIs: StateFlow + get() = _loveIs.asStateFlow() fun loveIs(restaurant: Restaurant) = launch { loveIsRestaurantDataUseCase(restaurant.id).let{ - _loveIs.postValue(it.toRestaurantData()) + _loveIs.value = it.toRestaurantData() } } - val loveIsFood: StateFlow> = foodRepository.getLoveIsFood() - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), listOf()) + private val _loveListRestaurants = MutableStateFlow>(emptyList()) + val loveListRestaurants : StateFlow> = _loveListRestaurants.asStateFlow() - val loveFoods: StateFlow> = - foodRepository.getFoods() + fun getLoveListRestaurant() = launch { + getListRestaurantDataUseCase() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList()) + .collect { restaurantList -> + _loveListRestaurants.value = restaurantList.map { it.toRestaurantData()} + } + } + + private val _loveRestaurants = MutableStateFlow>(PagingData.empty()) + val loveRestaurants : StateFlow> = _loveRestaurants.asStateFlow() + + fun getLoveRestaurant() = launch { + getPagingRestaurantDataUseCase() .cachedIn(viewModelScope) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), PagingData.empty()) + .collect { restaurantPagingData -> + _loveRestaurants.value = restaurantPagingData.map { it.toRestaurantData() } + } + } private val _scrapRestaurant = MutableLiveData() val scrapRestaurant: LiveData From 7908bc55d79247ac98a9d71aacdbfc53ac57f8ef Mon Sep 17 00:00:00 2001 From: SsongSik Date: Wed, 10 May 2023 09:34:16 +0900 Subject: [PATCH 09/11] =?UTF-8?q?[refactor]=20:=20#83=20LoveViewModel=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myongsikandroid/data/api/HomeFoodApi.kt | 9 +-- .../myongsikandroid/data/api/RestaurantApi.kt | 15 +++++ .../restaurant/RestaurantDataSource.kt | 4 ++ .../restaurant/RestaurantDataSourceImpl.kt | 18 +++++- .../data/model/food/ResponseScrap.kt | 21 ------- .../data/model/restaurant/RequestScrap.kt | 45 +++++++++++++++ .../data/model/restaurant/ResponseScrap.kt | 57 +++++++++++++++++++ .../data/repository/food/FoodRepository.kt | 8 +-- .../repository/food/FoodRepositoryImpl.kt | 14 +---- .../restaurant/RestaurantRepositoryImpl.kt | 6 ++ .../myongsik/myongsikandroid/di/AppModule.kt | 12 ++++ .../model/restaurant/RequestScrapEntity.kt} | 4 +- .../model/restaurant/ResponseScrapEntity.kt | 17 ++++++ .../restaurant/RestaurantRepository.kt | 4 ++ .../PostScrapRestaurantDataUseCase.kt | 13 +++++ .../view/food/MapDetailBottomSheetDialog.kt | 2 +- .../view/search/RestaurantFragment.kt | 5 +- .../viewmodel/search/LoveViewModel.kt | 19 +++---- 18 files changed, 210 insertions(+), 63 deletions(-) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/api/RestaurantApi.kt delete mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/model/food/ResponseScrap.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/RequestScrap.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/ResponseScrap.kt rename app/src/main/java/com/myongsik/myongsikandroid/{data/model/food/RequestScrap.kt => domain/model/restaurant/RequestScrapEntity.kt} (75%) create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/ResponseScrapEntity.kt create mode 100644 app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/PostScrapRestaurantDataUseCase.kt diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt index de46ad03..3dbe70ec 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt @@ -2,10 +2,10 @@ package com.myongsik.myongsikandroid.data.api import com.myongsik.myongsikandroid.data.model.food.* +import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap +import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap import com.myongsik.myongsikandroid.data.model.review.RequestReviewData import com.myongsik.myongsikandroid.data.model.review.ResponseReviewData -import com.myongsik.myongsikandroid.data.model.user.RequestUserData -import com.myongsik.myongsikandroid.data.model.user.ResponseUserData import retrofit2.Response import retrofit2.http.* @@ -31,11 +31,6 @@ interface HomeFoodApi { @Body body: RequestMealData ): Response - @POST("/api/v2/scraps") - suspend fun postRestaurantScrap( - @Body body: RequestScrap - ): Response - @GET("/api/v2/scraps/store") suspend fun getRankRestaurant( @Query("sort") sort : String = "scrapCount,desc", diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/api/RestaurantApi.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/api/RestaurantApi.kt new file mode 100644 index 00000000..314b965b --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/api/RestaurantApi.kt @@ -0,0 +1,15 @@ +package com.myongsik.myongsikandroid.data.api + +import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap +import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap +import retrofit2.Response +import retrofit2.http.Body +import retrofit2.http.POST + +interface RestaurantApi { + + @POST("/api/v2/scraps") + suspend fun postRestaurantScrap( + @Body body: RequestScrap + ): Response +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt index 9c6cd35d..477cbb49 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt @@ -1,6 +1,8 @@ package com.myongsik.myongsikandroid.data.datasource.restaurant import androidx.paging.PagingData +import com.myongsik.myongsikandroid.domain.model.restaurant.RequestScrapEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.ResponseScrapEntity import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import kotlinx.coroutines.flow.Flow @@ -15,4 +17,6 @@ interface RestaurantDataSource { suspend fun getLoveRestaurant(): Flow> suspend fun getLoveListRestaurant() : Flow> + + suspend fun postScrapRestaurant(requestScrapEntity: RequestScrapEntity): ResponseScrapEntity? } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt index 06281ae4..8cee3acd 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt @@ -4,10 +4,14 @@ import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData import androidx.paging.map +import com.myongsik.myongsikandroid.data.api.RestaurantApi import com.myongsik.myongsikandroid.data.db.RestaurantDatabase -import com.myongsik.myongsikandroid.data.model.kakao.Restaurant import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantData import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantEntity +import com.myongsik.myongsikandroid.data.model.restaurant.toRequestScrapData +import com.myongsik.myongsikandroid.data.model.restaurant.toResponseScrapEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.RequestScrapEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.ResponseScrapEntity import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import com.myongsik.myongsikandroid.util.Constant import kotlinx.coroutines.flow.Flow @@ -15,7 +19,8 @@ import kotlinx.coroutines.flow.map import javax.inject.Inject class RestaurantDataSourceImpl @Inject constructor( - private val loveDb: RestaurantDatabase + private val loveDb: RestaurantDatabase, + private val restaurantApi: RestaurantApi ) : RestaurantDataSource { override suspend fun insertRestaurant(restaurantEntity: RestaurantEntity) { @@ -50,4 +55,13 @@ class RestaurantDataSourceImpl @Inject constructor( .map { restaurantList -> restaurantList.map { it.toRestaurantEntity() } } } + override suspend fun postScrapRestaurant(requestScrapEntity: RequestScrapEntity): ResponseScrapEntity? { + val response = restaurantApi.postRestaurantScrap(requestScrapEntity.toRequestScrapData()) + return if(response.isSuccessful) { + response.body()?.toResponseScrapEntity() + } else { + null + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/food/ResponseScrap.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/food/ResponseScrap.kt deleted file mode 100644 index 87371ea7..00000000 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/model/food/ResponseScrap.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.myongsik.myongsikandroid.data.model.food - -data class ResponseScrap( - val httpCode : Int, - val httpStatus : String, - val localDateTime : String, - val message : String, - val success : Boolean, - val data : ResponseScrapData -) { - data class ResponseScrapData( - val id: Int, - val address : String, - val category : String, - val code : String, - val contact : String, - val distance : String, - val name : String, - val urlAddress : String, - ) -} diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/RequestScrap.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/RequestScrap.kt new file mode 100644 index 00000000..9e5f3ac8 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/RequestScrap.kt @@ -0,0 +1,45 @@ +package com.myongsik.myongsikandroid.data.model.restaurant + +import com.myongsik.myongsikandroid.domain.model.restaurant.RequestScrapEntity + +data class RequestScrap( + val address : String, + val campus : String, + val category : String, + val code : String, + val contact : String, + val distance : String, + val name : String, + val phoneId : String, + val urlAddress : String, + val latitude : String, + val longitude : String +) + +fun RequestScrap.toRequestScrapEntity() = RequestScrapEntity( + address = this.address, + campus = this.campus, + category = this.category, + code = this.code, + contact = this.contact, + distance = this.distance, + name = this.name, + phoneId = this.phoneId, + urlAddress = this.urlAddress, + latitude = this.latitude, + longitude = this.longitude +) + +fun RequestScrapEntity.toRequestScrapData() = RequestScrap( + address = this.address, + campus = this.campus, + category = this.category, + code = this.code, + contact = this.contact, + distance = this.distance, + name = this.name, + phoneId = this.phoneId, + urlAddress = this.urlAddress, + latitude = this.latitude, + longitude = this.longitude +) diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/ResponseScrap.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/ResponseScrap.kt new file mode 100644 index 00000000..f9137fe0 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/ResponseScrap.kt @@ -0,0 +1,57 @@ +package com.myongsik.myongsikandroid.data.model.restaurant + +import com.myongsik.myongsikandroid.domain.model.restaurant.ResponseScrapEntity + +data class ResponseScrap( + val httpCode : Int, + val httpStatus : String, + val localDateTime : String, + val message : String, + val success : Boolean, + val data : ResponseScrapData +) { + data class ResponseScrapData( + val id: Int, + val address : String, + val category : String, + val code : String, + val contact : String, + val distance : String, + val name : String, + val urlAddress : String, + ) +} + +fun ResponseScrap.toResponseScrapEntity() = ResponseScrapEntity( + httpCode = this.httpCode, + httpStatus = this.httpStatus, + localDateTime = this.localDateTime, + message = this.message, + success = this.success, + id = this.data.id, + address = this.data.address, + category = this.data.category, + code = this.data.code, + contact = this.data.contact, + distance = this.data.distance, + name = this.data.name, + urlAddress = this.data.urlAddress +) + +fun ResponseScrapEntity.toResponseScrapData() = ResponseScrap( + httpCode = this.httpCode, + httpStatus = this.httpStatus, + localDateTime = this.localDateTime, + message = this.message, + success = this.success, + data = ResponseScrap.ResponseScrapData( + id = this.id, + address = this.address, + category = this.category, + code = this.code, + contact = this.contact, + distance = this.distance, + name = this.name, + urlAddress = this.urlAddress + ) +) \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt index 7b0af243..910a66b2 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt @@ -1,13 +1,11 @@ package com.myongsik.myongsikandroid.data.repository.food import androidx.datastore.preferences.core.Preferences -import androidx.paging.PagingData import com.myongsik.myongsikandroid.data.model.food.* -import com.myongsik.myongsikandroid.data.model.kakao.Restaurant +import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap +import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap import com.myongsik.myongsikandroid.data.model.review.RequestReviewData import com.myongsik.myongsikandroid.data.model.review.ResponseReviewData -import com.myongsik.myongsikandroid.data.model.user.RequestUserData -import com.myongsik.myongsikandroid.data.model.user.ResponseUserData import kotlinx.coroutines.flow.Flow import retrofit2.Response @@ -20,8 +18,6 @@ interface FoodRepository { suspend fun postReview(requestReviewData: RequestReviewData): Response - suspend fun postScrapRestaurant(requestScrap: RequestScrap): Response - suspend fun getRankRestaurant(sort : String, campus : String, size : Int) : Response suspend fun getOneRestaurant(storeId : Int) : Response diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt index 4f99c299..cea75b7a 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt @@ -6,17 +6,13 @@ import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.emptyPreferences import androidx.datastore.preferences.core.stringPreferencesKey -import androidx.paging.Pager -import androidx.paging.PagingConfig -import androidx.paging.PagingData import com.myongsik.myongsikandroid.data.api.HomeFoodApi import com.myongsik.myongsikandroid.data.db.RestaurantDatabase import com.myongsik.myongsikandroid.data.model.food.* -import com.myongsik.myongsikandroid.data.model.kakao.Restaurant +import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap +import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap import com.myongsik.myongsikandroid.data.model.review.RequestReviewData import com.myongsik.myongsikandroid.data.model.review.ResponseReviewData -import com.myongsik.myongsikandroid.data.model.user.RequestUserData -import com.myongsik.myongsikandroid.data.model.user.ResponseUserData import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.DINNER_EVALUATION import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.DINNER_EVALUATION_H import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.DINNER_EVALUATION_S @@ -24,7 +20,6 @@ import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.Pref import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.LUNCH_A_EVALUATION_S import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.LUNCH_B_EVALUATION import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.LUNCH_EVALUATION -import com.myongsik.myongsikandroid.util.Constant import com.myongsik.myongsikandroid.util.DataStoreKey import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch @@ -36,7 +31,6 @@ import javax.inject.Singleton @Singleton class FoodRepositoryImpl @Inject constructor( - private val db: RestaurantDatabase, private val dataStore: DataStore, private val api: HomeFoodApi, ) : FoodRepository { @@ -53,10 +47,6 @@ class FoodRepositoryImpl @Inject constructor( return api.postReview(requestReviewData) } - override suspend fun postScrapRestaurant(requestScrap: RequestScrap): Response { - return api.postRestaurantScrap(requestScrap) - } - override suspend fun getRankRestaurant(sort: String, campus: String, size : Int): Response { return api.getRankRestaurant(sort, campus, size) } diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt index f3f653dc..7082f80d 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/restaurant/RestaurantRepositoryImpl.kt @@ -2,6 +2,8 @@ package com.myongsik.myongsikandroid.data.repository.restaurant import androidx.paging.PagingData import com.myongsik.myongsikandroid.data.datasource.restaurant.RestaurantDataSource +import com.myongsik.myongsikandroid.domain.model.restaurant.RequestScrapEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.ResponseScrapEntity import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository import kotlinx.coroutines.flow.Flow @@ -27,4 +29,8 @@ class RestaurantRepositoryImpl @Inject constructor( override suspend fun getLoveListRestaurant(): Flow> = restaurantDataSource.getLoveListRestaurant() + override suspend fun postRestaurantScrap(requestScrapEntity: RequestScrapEntity): ResponseScrapEntity? { + return restaurantDataSource.postScrapRestaurant(requestScrapEntity) + } + } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/di/AppModule.kt b/app/src/main/java/com/myongsik/myongsikandroid/di/AppModule.kt index 06a2f43b..46cc3d8a 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/di/AppModule.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/di/AppModule.kt @@ -7,6 +7,7 @@ import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.preferencesDataStoreFile import androidx.room.Room import com.myongsik.myongsikandroid.data.api.HomeFoodApi +import com.myongsik.myongsikandroid.data.api.RestaurantApi import com.myongsik.myongsikandroid.data.api.SearchFoodApi import com.myongsik.myongsikandroid.data.api.UserApi import com.myongsik.myongsikandroid.data.db.RestaurantDatabase @@ -80,6 +81,17 @@ object AppModule { .build() .create() } + + @Singleton + @Provides + fun provideRestaurantApi(okHttpClient: OkHttpClient, gsonConverterFactory: GsonConverterFactory): RestaurantApi { + return Retrofit.Builder() + .baseUrl(Constant.MYONG_SIK_BASE_URL) + .client(okHttpClient) + .addConverterFactory(gsonConverterFactory) + .build() + .create() + } //Room @Singleton diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/model/food/RequestScrap.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/RequestScrapEntity.kt similarity index 75% rename from app/src/main/java/com/myongsik/myongsikandroid/data/model/food/RequestScrap.kt rename to app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/RequestScrapEntity.kt index df455ff2..a45e2e09 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/model/food/RequestScrap.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/RequestScrapEntity.kt @@ -1,6 +1,6 @@ -package com.myongsik.myongsikandroid.data.model.food +package com.myongsik.myongsikandroid.domain.model.restaurant -data class RequestScrap( +data class RequestScrapEntity( val address : String, val campus : String, val category : String, diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/ResponseScrapEntity.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/ResponseScrapEntity.kt new file mode 100644 index 00000000..5762791a --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/model/restaurant/ResponseScrapEntity.kt @@ -0,0 +1,17 @@ +package com.myongsik.myongsikandroid.domain.model.restaurant + +data class ResponseScrapEntity( + val httpCode : Int, + val httpStatus : String, + val localDateTime : String, + val message : String, + val success : Boolean, + val id: Int, + val address : String, + val category : String, + val code : String, + val contact : String, + val distance : String, + val name : String, + val urlAddress : String, +) \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt index 22da08ae..db95127e 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/repository/restaurant/RestaurantRepository.kt @@ -1,6 +1,8 @@ package com.myongsik.myongsikandroid.domain.repository.restaurant import androidx.paging.PagingData +import com.myongsik.myongsikandroid.domain.model.restaurant.RequestScrapEntity +import com.myongsik.myongsikandroid.domain.model.restaurant.ResponseScrapEntity import com.myongsik.myongsikandroid.domain.model.restaurant.RestaurantEntity import kotlinx.coroutines.flow.Flow @@ -15,4 +17,6 @@ interface RestaurantRepository { suspend fun getLoveRestaurant(): Flow> suspend fun getLoveListRestaurant() : Flow> + + suspend fun postRestaurantScrap(requestScrapEntity: RequestScrapEntity) : ResponseScrapEntity? } \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/PostScrapRestaurantDataUseCase.kt b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/PostScrapRestaurantDataUseCase.kt new file mode 100644 index 00000000..a3f2a150 --- /dev/null +++ b/app/src/main/java/com/myongsik/myongsikandroid/domain/usecase/restaurant/PostScrapRestaurantDataUseCase.kt @@ -0,0 +1,13 @@ +package com.myongsik.myongsikandroid.domain.usecase.restaurant + +import com.myongsik.myongsikandroid.domain.model.restaurant.RequestScrapEntity +import com.myongsik.myongsikandroid.domain.repository.restaurant.RestaurantRepository +import javax.inject.Inject + +class PostScrapRestaurantDataUseCase @Inject constructor( + private val restaurantRepository : RestaurantRepository +) { + + suspend operator fun invoke(requestScrapEntity: RequestScrapEntity) + = restaurantRepository.postRestaurantScrap(requestScrapEntity) +} \ No newline at end of file diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt index 66e988f6..88471d5d 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/food/MapDetailBottomSheetDialog.kt @@ -12,7 +12,7 @@ import androidx.lifecycle.lifecycleScope import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.myongsik.myongsikandroid.R -import com.myongsik.myongsikandroid.data.model.food.RequestScrap +import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap import com.myongsik.myongsikandroid.data.model.kakao.Restaurant import com.myongsik.myongsikandroid.databinding.DialogBottomRestaurantSheetBinding import com.myongsik.myongsikandroid.presentation.viewmodel.food.HomeViewModel diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt index 129cdef6..00787327 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/view/search/RestaurantFragment.kt @@ -13,7 +13,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.google.android.material.snackbar.Snackbar import com.myongsik.myongsikandroid.BaseFragment -import com.myongsik.myongsikandroid.data.model.food.RequestScrap +import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap import com.myongsik.myongsikandroid.databinding.FragmentRestaurantBinding import com.myongsik.myongsikandroid.presentation.viewmodel.search.LoveViewModel import com.myongsik.myongsikandroid.util.MyongsikApplication @@ -78,7 +78,8 @@ class RestaurantFragment : BaseFragment() { urlAddress = restaurant.place_url, latitude = restaurant.x, longitude = restaurant.y - )) + ) + ) Snackbar.make(binding.root, "찜 완료!", Snackbar.LENGTH_SHORT).show() } diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt index be5fefa7..b3cdeaa5 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt @@ -7,11 +7,13 @@ import androidx.paging.PagingData import androidx.paging.cachedIn import androidx.paging.map import com.myongsik.myongsikandroid.BaseViewModel -import com.myongsik.myongsikandroid.data.model.food.RequestScrap -import com.myongsik.myongsikandroid.data.model.food.ResponseScrap +import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap +import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap import com.myongsik.myongsikandroid.data.model.kakao.Restaurant import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantData import com.myongsik.myongsikandroid.data.model.kakao.toRestaurantEntity +import com.myongsik.myongsikandroid.data.model.restaurant.toRequestScrapEntity +import com.myongsik.myongsikandroid.data.model.restaurant.toResponseScrapData import com.myongsik.myongsikandroid.data.repository.food.FoodRepository import com.myongsik.myongsikandroid.domain.usecase.restaurant.* import dagger.hilt.android.lifecycle.HiltViewModel @@ -20,12 +22,12 @@ import javax.inject.Inject @HiltViewModel class LoveViewModel @Inject constructor( - private val foodRepository: FoodRepository, private val insertRestaurantDataUseCase: InsertRestaurantDataUseCase, private val deleteRestaurantDataUseCase: DeleteRestaurantDataUseCase, private val loveIsRestaurantDataUseCase: LoveIsRestaurantDataUseCase, private val getListRestaurantDataUseCase: GetListRestaurantDataUseCase, - private val getPagingRestaurantDataUseCase: GetPagingRestaurantDataUseCase + private val getPagingRestaurantDataUseCase: GetPagingRestaurantDataUseCase, + private val postScrapRestaurantDataUseCase: PostScrapRestaurantDataUseCase ) : BaseViewModel() { //Room @@ -38,8 +40,7 @@ class LoveViewModel @Inject constructor( } private val _loveIs = MutableStateFlow(null) - val loveIs: StateFlow - get() = _loveIs.asStateFlow() + val loveIs: StateFlow = _loveIs.asStateFlow() fun loveIs(restaurant: Restaurant) = launch { loveIsRestaurantDataUseCase(restaurant.id).let{ @@ -75,10 +76,8 @@ class LoveViewModel @Inject constructor( get() = _scrapRestaurant fun scarpRestaurant(requestScrap: RequestScrap) = launch { - val response = foodRepository.postScrapRestaurant(requestScrap) - - if (response.code() == 200) { - _scrapRestaurant.postValue(response.body()) + postScrapRestaurantDataUseCase(requestScrap.toRequestScrapEntity())?.let{ + _scrapRestaurant.postValue(it.toResponseScrapData()) } } } \ No newline at end of file From 62488c3a5c793a6f634f8da6ba30e8eb753ae19b Mon Sep 17 00:00:00 2001 From: SsongSik Date: Wed, 10 May 2023 09:36:38 +0900 Subject: [PATCH 10/11] =?UTF-8?q?[refactor]=20:=20#83=20StateFlow=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/viewmodel/search/LoveViewModel.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt index b3cdeaa5..4175a640 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/presentation/viewmodel/search/LoveViewModel.kt @@ -71,13 +71,12 @@ class LoveViewModel @Inject constructor( } } - private val _scrapRestaurant = MutableLiveData() - val scrapRestaurant: LiveData - get() = _scrapRestaurant + private val _scrapRestaurant = MutableStateFlow(null) + val scrapRestaurant: StateFlow = _scrapRestaurant.asStateFlow() fun scarpRestaurant(requestScrap: RequestScrap) = launch { postScrapRestaurantDataUseCase(requestScrap.toRequestScrapEntity())?.let{ - _scrapRestaurant.postValue(it.toResponseScrapData()) + _scrapRestaurant.value = it.toResponseScrapData() } } } \ No newline at end of file From 540168653ae5e076c42b7e6fb0298983a1a8299e Mon Sep 17 00:00:00 2001 From: SsongSik Date: Wed, 10 May 2023 10:33:08 +0900 Subject: [PATCH 11/11] =?UTF-8?q?[refactor]=20:=20#83=20=EC=95=88=EC=93=B0?= =?UTF-8?q?=EB=8A=94=20import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt | 7 ------- .../data/repository/food/FoodRepository.kt | 7 ++++--- .../data/repository/food/FoodRepositoryImpl.kt | 8 ++++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt index 3dbe70ec..a68435b1 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/api/HomeFoodApi.kt @@ -2,8 +2,6 @@ package com.myongsik.myongsikandroid.data.api import com.myongsik.myongsikandroid.data.model.food.* -import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap -import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap import com.myongsik.myongsikandroid.data.model.review.RequestReviewData import com.myongsik.myongsikandroid.data.model.review.ResponseReviewData import retrofit2.Response @@ -26,11 +24,6 @@ interface HomeFoodApi { @Body body: RequestReviewData ): Response - @POST("/api/v2/meals/evaluate") - suspend fun postMeal( - @Body body: RequestMealData - ): Response - @GET("/api/v2/scraps/store") suspend fun getRankRestaurant( @Query("sort") sort : String = "scrapCount,desc", diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt index 910a66b2..a7c838c6 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepository.kt @@ -1,9 +1,10 @@ package com.myongsik.myongsikandroid.data.repository.food import androidx.datastore.preferences.core.Preferences -import com.myongsik.myongsikandroid.data.model.food.* -import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap -import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap +import com.myongsik.myongsikandroid.data.model.food.DayFoodResponse +import com.myongsik.myongsikandroid.data.model.food.RankRestaurantResponse +import com.myongsik.myongsikandroid.data.model.food.ResponseOneRestaurant +import com.myongsik.myongsikandroid.data.model.food.WeekFoodResponse import com.myongsik.myongsikandroid.data.model.review.RequestReviewData import com.myongsik.myongsikandroid.data.model.review.ResponseReviewData import kotlinx.coroutines.flow.Flow diff --git a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt index cea75b7a..c3dff09d 100644 --- a/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt +++ b/app/src/main/java/com/myongsik/myongsikandroid/data/repository/food/FoodRepositoryImpl.kt @@ -7,10 +7,10 @@ import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.emptyPreferences import androidx.datastore.preferences.core.stringPreferencesKey import com.myongsik.myongsikandroid.data.api.HomeFoodApi -import com.myongsik.myongsikandroid.data.db.RestaurantDatabase -import com.myongsik.myongsikandroid.data.model.food.* -import com.myongsik.myongsikandroid.data.model.restaurant.RequestScrap -import com.myongsik.myongsikandroid.data.model.restaurant.ResponseScrap +import com.myongsik.myongsikandroid.data.model.food.DayFoodResponse +import com.myongsik.myongsikandroid.data.model.food.RankRestaurantResponse +import com.myongsik.myongsikandroid.data.model.food.ResponseOneRestaurant +import com.myongsik.myongsikandroid.data.model.food.WeekFoodResponse import com.myongsik.myongsikandroid.data.model.review.RequestReviewData import com.myongsik.myongsikandroid.data.model.review.ResponseReviewData import com.myongsik.myongsikandroid.data.repository.food.FoodRepositoryImpl.PreferencesKeys.DINNER_EVALUATION