Translation (WIP)

This commit is contained in:
Greg Burri 2025-01-05 22:38:46 +01:00
parent 9b0fcec5e2
commit e9873c1943
29 changed files with 586 additions and 285 deletions

View file

@ -102,8 +102,8 @@ WHERE [Ingredient].[id] = $1 AND [user_id] = $2
.map_err(DBError::from)
}
pub async fn get_recipe(&self, id: i64) -> Result<Option<model::Recipe>> {
sqlx::query_as(
pub async fn get_recipe(&self, id: i64, with_groups: bool) -> Result<Option<model::Recipe>> {
match sqlx::query_as::<_, model::Recipe>(
r#"
SELECT
[id], [user_id], [title], [lang],
@ -114,8 +114,14 @@ FROM [Recipe] WHERE [id] = $1
)
.bind(id)
.fetch_optional(&self.pool)
.await
.map_err(DBError::from)
.await?
{
Some(mut recipe) if with_groups => {
recipe.groups = self.get_groups(id).await?;
Ok(Some(recipe))
}
recipe => Ok(recipe),
}
}
pub async fn create_recipe(&self, user_id: i64) -> Result<i64> {
@ -543,8 +549,6 @@ ORDER BY [name]
#[cfg(test)]
mod tests {
use axum::routing::connect;
use super::*;
#[tokio::test]
@ -555,7 +559,7 @@ mod tests {
let recipe_id = connection.create_recipe(user_id).await?;
connection.set_recipe_title(recipe_id, "Crêpe").await?;
let recipe = connection.get_recipe(recipe_id).await?.unwrap();
let recipe = connection.get_recipe(recipe_id, false).await?.unwrap();
assert_eq!(recipe.title, "Crêpe".to_string());
Ok(())
@ -581,7 +585,7 @@ mod tests {
connection.set_recipe_language(recipe_id, "fr").await?;
connection.set_recipe_is_published(recipe_id, true).await?;
let recipe = connection.get_recipe(recipe_id).await?.unwrap();
let recipe = connection.get_recipe(recipe_id, false).await?.unwrap();
assert_eq!(recipe.id, recipe_id);
assert_eq!(recipe.title, "Ouiche");