-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from MYONGSIK/refactor/clean
[refact/clean] : #83 LoveViewModel 클린아키텍처 마이그레이션
- Loading branch information
Showing
42 changed files
with
594 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/myongsik/myongsikandroid/data/api/RestaurantApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ResponseScrap> | ||
} |
22 changes: 22 additions & 0 deletions
22
...main/java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 | ||
|
||
interface RestaurantDataSource { | ||
|
||
suspend fun insertRestaurant(restaurantEntity: RestaurantEntity) | ||
|
||
suspend fun deleteRestaurant(restaurantEntity: RestaurantEntity) | ||
|
||
suspend fun loveIs(id: String): RestaurantEntity | ||
|
||
suspend fun getLoveRestaurant(): Flow<PagingData<RestaurantEntity>> | ||
|
||
suspend fun getLoveListRestaurant() : Flow<List<RestaurantEntity>> | ||
|
||
suspend fun postScrapRestaurant(requestScrapEntity: RequestScrapEntity): ResponseScrapEntity? | ||
} |
67 changes: 67 additions & 0 deletions
67
.../java/com/myongsik/myongsikandroid/data/datasource/restaurant/RestaurantDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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.api.RestaurantApi | ||
import com.myongsik.myongsikandroid.data.db.RestaurantDatabase | ||
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 | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class RestaurantDataSourceImpl @Inject constructor( | ||
private val loveDb: RestaurantDatabase, | ||
private val restaurantApi: RestaurantApi | ||
) : RestaurantDataSource { | ||
|
||
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() | ||
|
||
override suspend fun getLoveRestaurant(): Flow<PagingData<RestaurantEntity>> { | ||
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<List<RestaurantEntity>> { | ||
return loveDb.restaurantDao().getIsLoveFood() | ||
.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 | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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? | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/myongsik/myongsikandroid/data/datasource/user/UserDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.myongsik.myongsikandroid.data.datasource.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.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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/myongsik/myongsikandroid/data/model/food/ResponseScrap.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/RequestScrap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/myongsik/myongsikandroid/data/model/restaurant/ResponseScrap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
) |
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/myongsik/myongsikandroid/data/model/user/RequestUserData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/myongsik/myongsikandroid/data/model/user/ResponseUserData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.