Allow to see recipe list
This commit is contained in:
parent
e459df69bf
commit
55dd953f43
3 changed files with 69 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ use axum::{
|
||||||
handler::HandlerWithoutStateExt,
|
handler::HandlerWithoutStateExt,
|
||||||
http::{request::Parts, StatusCode},
|
http::{request::Parts, StatusCode},
|
||||||
response::{IntoResponse, Redirect},
|
response::{IntoResponse, Redirect},
|
||||||
routing::{get, post},
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use maud::{html, Markup};
|
use maud::{html, Markup};
|
||||||
|
|
@ -21,6 +21,7 @@ use crate::entity::{prelude::*, user};
|
||||||
use self::{household::CurrentHousehold, sidebar::SidebarLocation};
|
use self::{household::CurrentHousehold, sidebar::SidebarLocation};
|
||||||
|
|
||||||
mod household;
|
mod household;
|
||||||
|
mod recipe;
|
||||||
mod sidebar;
|
mod sidebar;
|
||||||
|
|
||||||
type AppState = Arc<crate::AppState>;
|
type AppState = Arc<crate::AppState>;
|
||||||
|
|
@ -368,5 +369,6 @@ pub(crate) fn router() -> Router<AppState> {
|
||||||
.route("/logout", get(logout))
|
.route("/logout", get(logout))
|
||||||
.route("/login/redirect/:id", get(oidc_login_finish))
|
.route("/login/redirect/:id", get(oidc_login_finish))
|
||||||
.nest("/household", household::routes())
|
.nest("/household", household::routes())
|
||||||
|
.nest("/recipe", recipe::routes())
|
||||||
.fallback_service(ServeDir::new(public).fallback((|| async { not_found() }).into_service()))
|
.fallback_service(ServeDir::new(public).fallback((|| async { not_found() }).into_service()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
src/app/recipe.rs
Normal file
64
src/app/recipe.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
use axum::{extract::State, routing::get, Router};
|
||||||
|
use maud::{html, Markup};
|
||||||
|
use sea_orm::prelude::*;
|
||||||
|
|
||||||
|
use crate::entity::prelude::*;
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
household::CurrentHousehold,
|
||||||
|
sidebar::{sidebar, SidebarLocation},
|
||||||
|
AppState, AuthenticatedUser, RouteError,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub(super) fn routes() -> Router<AppState> {
|
||||||
|
Router::new().route("/", get(list_recipes))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn recipe_rating(rating: i32) -> Markup {
|
||||||
|
html! {
|
||||||
|
span aria-label={"Rating: " (rating)} ."ms-1" {
|
||||||
|
@for _ in 0..rating {
|
||||||
|
i aria-hidden="true" .bi-star-fill."ms-1" {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_recipes(
|
||||||
|
state: State<AppState>,
|
||||||
|
user: AuthenticatedUser,
|
||||||
|
household: CurrentHousehold,
|
||||||
|
) -> Result<Markup, RouteError> {
|
||||||
|
let mut recipes = household.0.find_related(Recipe).all(&state.db).await?;
|
||||||
|
recipes.sort_unstable_by(|m1, m2| m1.name.cmp(&m2.name));
|
||||||
|
|
||||||
|
let content = html! {
|
||||||
|
.d-flex.align-items-center.justify-content-center."w-100" {
|
||||||
|
.container.text-center.rounded.border."pt-2"."m-2" {
|
||||||
|
h2 { "Recipes" }
|
||||||
|
.container.text-center {
|
||||||
|
.row."row-cols-2"."row-cols-sm-2"."row-cols-md-4"."g-2"."mb-2" {
|
||||||
|
@for r in recipes {
|
||||||
|
.col {
|
||||||
|
."p-3".border.rounded.border-light-subtle."h-100" {
|
||||||
|
a .link-light."link-offset-2"."link-underline-opacity-25"."link-underline-opacity-100-hover"
|
||||||
|
href={"/recipe/" (r.id)}
|
||||||
|
{
|
||||||
|
(r.name) (recipe_rating(r.ranking))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(sidebar(
|
||||||
|
SidebarLocation::RecipeList,
|
||||||
|
&household,
|
||||||
|
&user,
|
||||||
|
content,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
@ -14,9 +14,9 @@ impl SidebarLocation {
|
||||||
fn to(&self) -> &'static str {
|
fn to(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
SidebarLocation::Home => "/",
|
SidebarLocation::Home => "/",
|
||||||
SidebarLocation::RecipeList => "/recipes",
|
SidebarLocation::RecipeList => "/recipe",
|
||||||
SidebarLocation::Ingredients => "/ingredients",
|
SidebarLocation::Ingredients => "/ingredients",
|
||||||
SidebarLocation::RecipeCreator => "/recipes/create",
|
SidebarLocation::RecipeCreator => "/recipe/create",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue