-
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.
* feat: orbit 4.4.0 의존성 추가 * feat: Retrofit 을 Result 응답 받을 수 있다 * feat: HomeScreen MVVM to MVI * feat: Add Ingredient Item Design
- Loading branch information
1 parent
7f1c39f
commit ee8853c
Showing
16 changed files
with
411 additions
and
88 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
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: 12 additions & 3 deletions
15
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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package com.sundaegukbap.banchango.core.data.api | ||
|
||
import com.sundaegukbap.banchango.core.data.api.model.AddIngredientContainerRequest | ||
import com.sundaegukbap.banchango.core.data.api.model.ContainerIngredientDtos | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
import retrofit2.http.Path | ||
|
||
internal interface IngredientApi { | ||
@GET("api/ingredients/main/list/{userid}") | ||
suspend fun getIngredients( | ||
@Path("userid") userId: Long, | ||
): Response<ContainerIngredientDtos> | ||
} | ||
): Result<ContainerIngredientDtos> | ||
|
||
@POST("/api/container/{userId}") | ||
suspend fun addIngredientContainer( | ||
@Path("userId") userId: Long, | ||
@Body addIngredientContainerRequest: AddIngredientContainerRequest, | ||
): Result<Unit> | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
...main/java/com/sundaegukbap/banchango/core/data/api/model/AddIngredientContainerRequest.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 AddIngredientContainerRequest( | ||
val containerName: 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
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
23 changes: 7 additions & 16 deletions
23
.../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 |
---|---|---|
@@ -1,31 +1,22 @@ | ||
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.api.model.AddIngredientContainerRequest | ||
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") | ||
} | ||
return ingredientApi.getIngredients(1).mapCatching { dto -> | ||
dto.containerIngredientDtos.map { it.toData() } | ||
} | ||
} | ||
|
||
override suspend fun addIngredientContainer(containerName: String): Result<Unit> { | ||
return ingredientApi.addIngredientContainer(1, AddIngredientContainerRequest(containerName)) | ||
} | ||
} |
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
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
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
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.