Refactor recipe fetching logic to use a new constructor for Recipes, improving code clarity and reducing duplication.
This commit is contained in:
parent
aebca7a7e2
commit
9daa852add
5 changed files with 61 additions and 63 deletions
|
|
@ -50,22 +50,31 @@ pub async fn home_page(
|
|||
State(connection): State<db::Connection>,
|
||||
Extension(context): Extension<Context>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
let recipes = Recipes {
|
||||
public: connection
|
||||
.get_all_public_recipe_titles(
|
||||
context.tr.current_lang_code(),
|
||||
context.user.as_ref().map(|u| u.id),
|
||||
)
|
||||
.await?,
|
||||
private: if let Some(user) = context.user.as_ref() {
|
||||
connection.get_all_private_recipe_titles(user.id).await?
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
current_id: None,
|
||||
};
|
||||
Ok(Html(
|
||||
HomeTemplate {
|
||||
recipes: Recipes::new(connection, &context.user, context.tr.current_lang_code())
|
||||
.await?,
|
||||
context,
|
||||
}
|
||||
.render()?,
|
||||
))
|
||||
}
|
||||
|
||||
Ok(Html(HomeTemplate { context, recipes }.render()?))
|
||||
///// DEV_PANEL /////
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn dev_panel(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(context): Extension<Context>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
Ok(Html(
|
||||
HomeTemplate {
|
||||
recipes: Recipes::new(connection, &context.user, context.tr.current_lang_code())
|
||||
.await?,
|
||||
context,
|
||||
}
|
||||
.render()?,
|
||||
))
|
||||
}
|
||||
|
||||
///// 404 /////
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue