Add some fields to recipe view

This commit is contained in:
Greg Burri 2025-01-15 20:30:19 +01:00
parent 54989f3212
commit afd42ba1d0
6 changed files with 44 additions and 2 deletions

View file

@ -172,7 +172,7 @@ WHERE [Ingredient].[id] = $1 AND [user_id] = $2
.map_err(DBError::from) .map_err(DBError::from)
} }
pub async fn get_recipe(&self, id: i64, with_groups: bool) -> Result<Option<model::Recipe>> { pub async fn get_recipe(&self, id: i64, complete: bool) -> Result<Option<model::Recipe>> {
match sqlx::query_as::<_, model::Recipe>( match sqlx::query_as::<_, model::Recipe>(
r#" r#"
SELECT SELECT
@ -186,7 +186,8 @@ FROM [Recipe] WHERE [id] = $1
.fetch_optional(&self.pool) .fetch_optional(&self.pool)
.await? .await?
{ {
Some(mut recipe) if with_groups => { Some(mut recipe) if complete => {
recipe.tags = self.get_recipes_tags(id).await?;
recipe.groups = self.get_groups(id).await?; recipe.groups = self.get_groups(id).await?;
Ok(Some(recipe)) Ok(Some(recipe))
} }

View file

@ -32,6 +32,9 @@ pub struct Recipe {
pub servings: Option<u32>, pub servings: Option<u32>,
pub is_published: bool, pub is_published: bool,
#[sqlx(skip)]
pub tags: Vec<String>,
#[sqlx(skip)] #[sqlx(skip)]
pub groups: Vec<Group>, pub groups: Vec<Group>,
} }

View file

@ -107,6 +107,11 @@ pub enum Sentence {
RecipeIngredientQuantity, RecipeIngredientQuantity,
RecipeIngredientUnit, RecipeIngredientUnit,
RecipeIngredientComment, RecipeIngredientComment,
// View Recipe.
RecipeOneServing,
RecipeSomeServings,
RecipeEstimatedTimeMinAbbreviation,
} }
pub const DEFAULT_LANGUAGE_CODE: &str = "en"; pub const DEFAULT_LANGUAGE_CODE: &str = "en";

View file

@ -9,6 +9,31 @@
<a class="edit-recipe" href="/recipe/edit/{{ recipe.id }}" >Edit</a> <a class="edit-recipe" href="/recipe/edit/{{ recipe.id }}" >Edit</a>
{% endif %} {% endif %}
<div class="tags">
{% for tag in recipe.tags %}
<span class="tag">{{ tag }}</span>
{% endfor %}
</div>
{% match recipe.servings %}
{% when Some(servings) %}
<span class="servings">
{% if *servings == 1 %}
{{ tr.t(Sentence::RecipeOneServing) }}
{% else %}
{{ tr.tp(Sentence::RecipeSomeServings, [Box::new(**servings)]) }}
{% endif %}
</span>
{% else %}
{% endmatch %}
{% match recipe.estimated_time %}
{% when Some(time) %}
{{ time +}} {{+ tr.t(Sentence::RecipeEstimatedTimeMinAbbreviation) }}
{% else %}
{% endmatch %}
{% if !recipe.description.is_empty() %} {% if !recipe.description.is_empty() %}
<div class="recipe-description" > <div class="recipe-description" >
{{ recipe.description.clone() }} {{ recipe.description.clone() }}

View file

@ -94,6 +94,10 @@
(RecipeIngredientQuantity, "Quantity"), (RecipeIngredientQuantity, "Quantity"),
(RecipeIngredientUnit, "Unit"), (RecipeIngredientUnit, "Unit"),
(RecipeIngredientComment, "Comment"), (RecipeIngredientComment, "Comment"),
(RecipeOneServing, "1 serving"),
(RecipeSomeServings, "{} servings"),
(RecipeEstimatedTimeMinAbbreviation, "min"),
] ]
), ),
( (
@ -191,6 +195,10 @@
(RecipeIngredientQuantity, "Quantité"), (RecipeIngredientQuantity, "Quantité"),
(RecipeIngredientUnit, "Unité"), (RecipeIngredientUnit, "Unité"),
(RecipeIngredientComment, "Commentaire"), (RecipeIngredientComment, "Commentaire"),
(RecipeOneServing, "pour 1 personne"),
(RecipeSomeServings, "pour {} personnes"),
(RecipeEstimatedTimeMinAbbreviation, "min"),
] ]
) )
] ]