Skip to content

Commit

Permalink
feat(recipeDetail): 레시피 상세 조회 api 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Jun 13, 2024
1 parent 989a87d commit d3a02cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import com.sundaegukbap.banchango.Recipe

interface RecipeRepository {
suspend fun getRecipeRecommendation(): Result<List<Recipe>>
suspend fun getRecipeDetail(id: Int): Result<Recipe>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ internal interface RecipeApi {
suspend fun getRecipeRecommendation(
@Path("userId") userId: Long
): Response<List<RecipeRecommendResponse>>

@GET("api/recipe/{userId}/{recipeId}")
suspend fun getRecipeDetail(
@Path("userId") userId: Long,
@Path("recipeId") recipeId: Long
): Response<RecipeRecommendResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.sundaegukbap.banchango.core.data.repository

import com.sundaegukbap.banchango.Recipe
import com.sundaegukbap.banchango.core.data.api.RecipeApi
import com.sundaegukbap.banchango.core.data.api.model.RecipeRecommendResponse
import com.sundaegukbap.banchango.core.data.mapper.toData
import com.sundaegukbap.banchango.core.data.repository.api.RecipeRepository
import javax.inject.Inject
Expand All @@ -23,4 +22,18 @@ internal class DefaultRecipeRepository @Inject constructor(
}
}
}

override suspend fun getRecipeDetail(id: Int): Result<Recipe> {
return runCatching {
val response = recipeApi.getRecipeDetail(1, id.toLong())
if (response.isSuccessful) {
if (response.body() == null) {
throw IllegalStateException("Response body is null")
}
response.body()!!.toData()
} else {
throw IllegalStateException("Response is not successful")
}
}
}
}

0 comments on commit d3a02cc

Please sign in to comment.