Update favorite status on icon click
This commit is contained in:
@@ -42,4 +42,8 @@ interface MealieDataSourceV0 {
|
||||
): String
|
||||
|
||||
suspend fun requestUserInfo(): GetUserInfoResponseV0
|
||||
|
||||
suspend fun removeFavoriteRecipe(userId: Int, recipeSlug: String)
|
||||
|
||||
suspend fun addFavoriteRecipe(userId: Int, recipeSlug: String)
|
||||
}
|
||||
@@ -97,4 +97,22 @@ class MealieDataSourceV0Impl @Inject constructor(
|
||||
logMethod = { "requestUserInfo" },
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun removeFavoriteRecipe(
|
||||
userId: Int,
|
||||
recipeSlug: String
|
||||
): Unit = networkRequestWrapper.makeCallAndHandleUnauthorized(
|
||||
block = { service.removeFavoriteRecipe(userId, recipeSlug) },
|
||||
logMethod = { "removeFavoriteRecipe" },
|
||||
logParameters = { "userId = $userId, recipeSlug = $recipeSlug" }
|
||||
)
|
||||
|
||||
override suspend fun addFavoriteRecipe(
|
||||
userId: Int,
|
||||
recipeSlug: String
|
||||
): Unit = networkRequestWrapper.makeCallAndHandleUnauthorized(
|
||||
block = { service.addFavoriteRecipe(userId, recipeSlug) },
|
||||
logMethod = { "addFavoriteRecipe" },
|
||||
logParameters = { "userId = $userId, recipeSlug = $recipeSlug" }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -43,4 +43,16 @@ interface MealieServiceV0 {
|
||||
|
||||
@GET("/api/users/self")
|
||||
suspend fun getUserSelfInfo(): GetUserInfoResponseV0
|
||||
|
||||
@DELETE("/api/users/{userId}/favorites/{recipeSlug}")
|
||||
suspend fun removeFavoriteRecipe(
|
||||
@Path("userId") userId: Int,
|
||||
@Path("recipeSlug") recipeSlug: String
|
||||
)
|
||||
|
||||
@POST("/api/users/{userId}/favorites/{recipeSlug}")
|
||||
suspend fun addFavoriteRecipe(
|
||||
@Path("userId") userId: Int,
|
||||
@Path("recipeSlug") recipeSlug: String
|
||||
)
|
||||
}
|
||||
@@ -5,5 +5,6 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GetUserInfoResponseV0(
|
||||
@SerialName("id") val id: Int,
|
||||
@SerialName("favoriteRecipes") val favoriteRecipes: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
@@ -50,4 +50,8 @@ interface MealieDataSourceV1 {
|
||||
): CreateApiTokenResponseV1
|
||||
|
||||
suspend fun requestUserInfo(): GetUserInfoResponseV1
|
||||
|
||||
suspend fun removeFavoriteRecipe(userId: String, recipeSlug: String)
|
||||
|
||||
suspend fun addFavoriteRecipe(userId: String, recipeSlug: String)
|
||||
}
|
||||
@@ -108,5 +108,23 @@ class MealieDataSourceV1Impl @Inject constructor(
|
||||
logMethod = { "requestUserInfo" },
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun removeFavoriteRecipe(
|
||||
userId: String,
|
||||
recipeSlug: String
|
||||
): Unit = networkRequestWrapper.makeCallAndHandleUnauthorized(
|
||||
block = { service.removeFavoriteRecipe(userId, recipeSlug) },
|
||||
logMethod = { "removeFavoriteRecipe" },
|
||||
logParameters = { "userId = $userId, recipeSlug = $recipeSlug" }
|
||||
)
|
||||
|
||||
override suspend fun addFavoriteRecipe(
|
||||
userId: String,
|
||||
recipeSlug: String
|
||||
): Unit = networkRequestWrapper.makeCallAndHandleUnauthorized(
|
||||
block = { service.addFavoriteRecipe(userId, recipeSlug) },
|
||||
logMethod = { "addFavoriteRecipe" },
|
||||
logParameters = { "userId = $userId, recipeSlug = $recipeSlug" }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -49,4 +49,16 @@ interface MealieServiceV1 {
|
||||
|
||||
@GET("/api/users/self")
|
||||
suspend fun getUserSelfInfo(): GetUserInfoResponseV1
|
||||
|
||||
@DELETE("/api/users/{userId}/favorites/{recipeSlug}")
|
||||
suspend fun removeFavoriteRecipe(
|
||||
@Path("userId") userId: String,
|
||||
@Path("recipeSlug") recipeSlug: String
|
||||
)
|
||||
|
||||
@POST("/api/users/{userId}/favorites/{recipeSlug}")
|
||||
suspend fun addFavoriteRecipe(
|
||||
@Path("userId") userId: String,
|
||||
@Path("recipeSlug") recipeSlug: String
|
||||
)
|
||||
}
|
||||
@@ -5,5 +5,6 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GetUserInfoResponseV1(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("favoriteRecipes") val favoriteRecipes: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user