-
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.
Browse files
Browse the repository at this point in the history
* feat: Data Response model 정의 * feat: 재료 Domain Model 정의 * feat: 재료 요청 Retrofit API 정의 * feat: 재료 DTO 맵퍼 정의 * feat: 재료 저장소 및 냉장고 식자재 가져오기 정의 * feat: Default 재료 저장소 의존성 주입 * feat: 냉장고 재료 화면 보기 개발 * feat: 냉장고 재료 상자 이름 색깔 추가
- Loading branch information
1 parent
2367dcb
commit f2de6ba
Showing
26 changed files
with
646 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
7 changes: 7 additions & 0 deletions
7
...src/main/java/com/sundaegukbap/banchango/core/data/repository/api/IngredientRepository.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,7 @@ | ||
package com.sundaegukbap.banchango.core.data.repository.api | ||
|
||
import com.sundaegukbap.banchango.ContainerIngredient | ||
|
||
interface IngredientRepository { | ||
suspend fun getIngredientContainers(): Result<List<ContainerIngredient>> | ||
} |
13 changes: 13 additions & 0 deletions
13
Android/core/data/src/main/java/com/sundaegukbap/banchango/core/data/api/IngredientApi.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,13 @@ | ||
package com.sundaegukbap.banchango.core.data.api | ||
|
||
import com.sundaegukbap.banchango.core.data.api.model.ContainerIngredientDtos | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
internal interface IngredientApi { | ||
@GET("api/ingredients/main/list/{userid}") | ||
suspend fun getIngredients( | ||
@Path("userid") userId: Long, | ||
): Response<ContainerIngredientDtos> | ||
} |
9 changes: 9 additions & 0 deletions
9
...id/core/data/src/main/java/com/sundaegukbap/banchango/core/data/api/model/ContainerDto.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.sundaegukbap.banchango.core.data.api.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ContainerDto( | ||
val containerId: Long, | ||
val containerName: String | ||
) |
12 changes: 12 additions & 0 deletions
12
...ta/src/main/java/com/sundaegukbap/banchango/core/data/api/model/ContainerIngredientDto.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,12 @@ | ||
package com.sundaegukbap.banchango.core.data.api.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ContainerIngredientDto( | ||
val containerIngredientId: Long, | ||
val containerDto: ContainerDto, | ||
val ingredientDto: IngredientDto, | ||
val createdAt: String, | ||
val expirationDate: String | ||
) |
8 changes: 8 additions & 0 deletions
8
...a/src/main/java/com/sundaegukbap/banchango/core/data/api/model/ContainerIngredientDtos.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,8 @@ | ||
package com.sundaegukbap.banchango.core.data.api.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ContainerIngredientDtos( | ||
val containerIngredientDtos: List<ContainerIngredientDto> | ||
) |
11 changes: 11 additions & 0 deletions
11
...d/core/data/src/main/java/com/sundaegukbap/banchango/core/data/api/model/IngredientDto.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,11 @@ | ||
package com.sundaegukbap.banchango.core.data.api.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class IngredientDto( | ||
val id: Long, | ||
val name: String, | ||
val kind: String, | ||
val image: String?, | ||
) |
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
14 changes: 12 additions & 2 deletions
14
Android/core/data/src/main/java/com/sundaegukbap/banchango/core/data/di/RepositoryModule.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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
package com.sundaegukbap.banchango.core.data.di | ||
|
||
import com.sundaegukbap.banchango.core.data.repository.DefaultIngredientRepository | ||
import com.sundaegukbap.banchango.core.data.repository.DefaultRecipeRepository | ||
import com.sundaegukbap.banchango.core.data.repository.FakeIngredientRepository | ||
import com.sundaegukbap.banchango.core.data.repository.FakeRecipeRepository | ||
import com.sundaegukbap.banchango.core.data.repository.api.IngredientRepository | ||
import com.sundaegukbap.banchango.core.data.repository.api.RecipeRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
internal abstract class RepositoryModule { | ||
internal interface RepositoryModule { | ||
@Singleton | ||
@Binds | ||
abstract fun bindsRecipeRepository(recipeRepository: DefaultRecipeRepository): RecipeRepository | ||
fun bindsRecipeRepository(recipeRepository: FakeRecipeRepository): RecipeRepository | ||
|
||
@Singleton | ||
@Binds | ||
fun bindsIngredientRepository(ingredientRepository: FakeIngredientRepository): IngredientRepository | ||
} |
37 changes: 37 additions & 0 deletions
37
...d/core/data/src/main/java/com/sundaegukbap/banchango/core/data/mapper/IngredientMapper.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,37 @@ | ||
package com.sundaegukbap.banchango.core.data.mapper | ||
|
||
import com.sundaegukbap.banchango.Container | ||
import com.sundaegukbap.banchango.Ingredient | ||
import com.sundaegukbap.banchango.ContainerIngredient | ||
import com.sundaegukbap.banchango.IngredientKind | ||
import com.sundaegukbap.banchango.core.data.api.model.ContainerDto | ||
import com.sundaegukbap.banchango.core.data.api.model.ContainerIngredientDto | ||
import com.sundaegukbap.banchango.core.data.api.model.IngredientDto | ||
import java.time.LocalDateTime | ||
|
||
internal fun ContainerIngredientDto.toData() = ContainerIngredient( | ||
id = containerIngredientId, | ||
container = containerDto.toData(), | ||
ingredient = ingredientDto.toData(), | ||
createdAt = LocalDateTime.parse(createdAt), | ||
expirationDate = LocalDateTime.parse(expirationDate) | ||
) | ||
|
||
internal fun ContainerDto.toData() = Container( | ||
id = containerId, | ||
name = containerName | ||
) | ||
|
||
internal fun IngredientDto.toData() = Ingredient( | ||
id = id, | ||
name = name, | ||
kind = when (kind) { | ||
"육류" -> IngredientKind.MEAT | ||
"해산물" -> IngredientKind.SEAFOOD | ||
"채소" -> IngredientKind.VEGETABLE | ||
"과일" -> IngredientKind.FRUIT | ||
"기타" -> IngredientKind.ETC | ||
else -> IngredientKind.ETC | ||
}, | ||
image = image ?: "" | ||
) |
31 changes: 31 additions & 0 deletions
31
.../main/java/com/sundaegukbap/banchango/core/data/repository/DefaultIngredientRepository.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,31 @@ | ||
package com.sundaegukbap.banchango.core.data.repository | ||
|
||
import android.util.Log | ||
import com.sundaegukbap.banchango.Container | ||
import com.sundaegukbap.banchango.ContainerIngredient | ||
import com.sundaegukbap.banchango.Ingredient | ||
import com.sundaegukbap.banchango.IngredientKind | ||
import com.sundaegukbap.banchango.core.data.api.IngredientApi | ||
import com.sundaegukbap.banchango.core.data.mapper.toData | ||
import com.sundaegukbap.banchango.core.data.repository.api.IngredientRepository | ||
import java.time.LocalDateTime | ||
import javax.inject.Inject | ||
|
||
internal class DefaultIngredientRepository @Inject constructor( | ||
private val ingredientApi: IngredientApi, | ||
) : IngredientRepository { | ||
override suspend fun getIngredientContainers(): Result<List<ContainerIngredient>> { | ||
return runCatching { | ||
val response = ingredientApi.getIngredients(1) | ||
Log.d("asdf", "response: $response") | ||
if (response.isSuccessful) { | ||
if (response.body() == null) { | ||
throw IllegalStateException("Response body is null") | ||
} | ||
response.body()!!.containerIngredientDtos.map { it.toData() } | ||
} else { | ||
throw IllegalStateException("Response is not successful") | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...src/main/java/com/sundaegukbap/banchango/core/data/repository/FakeIngredientRepository.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,54 @@ | ||
package com.sundaegukbap.banchango.core.data.repository | ||
|
||
import com.sundaegukbap.banchango.Container | ||
import com.sundaegukbap.banchango.ContainerIngredient | ||
import com.sundaegukbap.banchango.Ingredient | ||
import com.sundaegukbap.banchango.IngredientKind | ||
import com.sundaegukbap.banchango.core.data.repository.api.IngredientRepository | ||
import java.time.LocalDateTime | ||
import javax.inject.Inject | ||
|
||
internal class FakeIngredientRepository @Inject constructor() : IngredientRepository { | ||
override suspend fun getIngredientContainers(): Result<List<ContainerIngredient>> { | ||
return Result.success( | ||
listOf( | ||
ContainerIngredient( | ||
1, | ||
Container(1, "Container 1"), | ||
Ingredient(1, "Ingredient 1", IngredientKind.SAUCE, "Ingredient 1 Image"), | ||
LocalDateTime.now(), | ||
LocalDateTime.now().plusDays(1) | ||
), | ||
ContainerIngredient( | ||
2, | ||
Container(2, "Container 2"), | ||
Ingredient(2, "Ingredient 2", IngredientKind.VEGETABLE, "Ingredient 2 Image"), | ||
LocalDateTime.now(), | ||
LocalDateTime.now().plusDays(2) | ||
), | ||
ContainerIngredient( | ||
3, | ||
Container(2, "Container 2"), | ||
Ingredient(3, "Ingredient 3", IngredientKind.MEAT, "Ingredient 3 Image"), | ||
LocalDateTime.now(), | ||
LocalDateTime.now().plusDays(3) | ||
), | ||
ContainerIngredient( | ||
4, | ||
Container(2, "Container 2"), | ||
Ingredient(4, "Ingredient 4", IngredientKind.VEGETABLE, "Ingredient 4 Image"), | ||
LocalDateTime.now(), | ||
LocalDateTime.now().plusDays(4) | ||
), | ||
ContainerIngredient( | ||
5, | ||
Container(1, "Container 1"), | ||
Ingredient(5, "Ingredient 5", IngredientKind.SAUCE, "Ingredient 5 Image"), | ||
LocalDateTime.now(), | ||
LocalDateTime.now().plusDays(5) | ||
), | ||
) | ||
) | ||
} | ||
|
||
} |
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
6 changes: 6 additions & 0 deletions
6
Android/core/model/src/main/java/com/sundaegukbap/banchango/Container.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,6 @@ | ||
package com.sundaegukbap.banchango | ||
|
||
data class Container( | ||
val id: Long, | ||
val name: String | ||
) |
12 changes: 12 additions & 0 deletions
12
Android/core/model/src/main/java/com/sundaegukbap/banchango/ContainerIngredient.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,12 @@ | ||
package com.sundaegukbap.banchango | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class ContainerIngredient( | ||
val id: Long, | ||
val container: Container, | ||
val ingredient: Ingredient, | ||
val createdAt: LocalDateTime, | ||
val expirationDate: LocalDateTime | ||
) | ||
|
7 changes: 7 additions & 0 deletions
7
Android/core/model/src/main/java/com/sundaegukbap/banchango/IngredientContainer.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,7 @@ | ||
package com.sundaegukbap.banchango | ||
|
||
data class IngredientContainer( | ||
val container: Container, | ||
val kindIngredientContainers: List<KindIngredientContainer> | ||
) | ||
|
28 changes: 28 additions & 0 deletions
28
Android/core/model/src/main/java/com/sundaegukbap/banchango/IngredientContainers.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,28 @@ | ||
package com.sundaegukbap.banchango | ||
|
||
class ContainerIngredients( | ||
containerIngredients: List<ContainerIngredient> | ||
) { | ||
private val _value: MutableList<ContainerIngredient> = containerIngredients.toMutableList() | ||
val value: List<ContainerIngredient> get() = _value.toList() | ||
|
||
fun getIngredientContainers(): List<IngredientContainer> { | ||
return _value.groupBy { it.container } | ||
.map { (container, containerIngredients) -> | ||
IngredientContainer( | ||
container = container, | ||
kindIngredientContainers = containerIngredients.toKindIngredientContainers() | ||
) | ||
} | ||
} | ||
|
||
private fun List<ContainerIngredient>.toKindIngredientContainers(): List<KindIngredientContainer> { | ||
return groupBy { it.ingredient.kind } | ||
.map { (kind, ingredients) -> | ||
KindIngredientContainer( | ||
kind = kind, | ||
ingredients = ingredients | ||
) | ||
} | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
Android/core/model/src/main/java/com/sundaegukbap/banchango/IngredientKind.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.sundaegukbap.banchango | ||
|
||
enum class IngredientKind { | ||
MEAT, | ||
VEGETABLE, | ||
FRUIT, | ||
SEAFOOD, | ||
SAUCE, | ||
ETC, | ||
enum class IngredientKind(val label: String) { | ||
MEAT("육류"), | ||
VEGETABLE("채소"), | ||
FRUIT("과일"), | ||
SEAFOOD("해산물"), | ||
SAUCE("소스"), | ||
ETC("기타"), | ||
} |
6 changes: 6 additions & 0 deletions
6
Android/core/model/src/main/java/com/sundaegukbap/banchango/KindIngredientContainer.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,6 @@ | ||
package com.sundaegukbap.banchango | ||
|
||
data class KindIngredientContainer( | ||
val kind: IngredientKind, | ||
val ingredients: List<ContainerIngredient> | ||
) |
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.