From 6d62c4a3d147ab030aa9bbbe569cc9ad4e63aa32 Mon Sep 17 00:00:00 2001 From: SsongSik Date: Sun, 7 May 2023 01:18:59 +0900 Subject: [PATCH] =?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