Rename 'published' to 'public' (for recipe)
This commit is contained in:
parent
eaef6dc77e
commit
4f739593b8
20 changed files with 92 additions and 91 deletions
|
|
@ -14,7 +14,7 @@ pub enum AddScheduledRecipeResult {
|
|||
impl Connection {
|
||||
/// Returns all the recipe titles where recipe is written in the given language.
|
||||
/// If a user_id is given, the language constraint is ignored for recipes owned by user_id.
|
||||
pub async fn get_all_published_recipe_titles(
|
||||
pub async fn get_all_public_recipe_titles(
|
||||
&self,
|
||||
lang: &str,
|
||||
user_id: Option<i64>,
|
||||
|
|
@ -24,7 +24,7 @@ impl Connection {
|
|||
r#"
|
||||
SELECT [id], [title]
|
||||
FROM [Recipe]
|
||||
WHERE [is_published] = true AND ([lang] = $1 OR [user_id] = $2)
|
||||
WHERE [is_public] = true AND ([lang] = $1 OR [user_id] = $2)
|
||||
ORDER BY [title] COLLATE NOCASE
|
||||
"#,
|
||||
)
|
||||
|
|
@ -35,7 +35,7 @@ ORDER BY [title] COLLATE NOCASE
|
|||
r#"
|
||||
SELECT [id], [title]
|
||||
FROM [Recipe]
|
||||
WHERE [is_published] = true AND [lang] = $1
|
||||
WHERE [is_public] = true AND [lang] = $1
|
||||
ORDER BY [title] COLLATE NOCASE
|
||||
"#,
|
||||
)
|
||||
|
|
@ -46,15 +46,12 @@ ORDER BY [title] COLLATE NOCASE
|
|||
.map_err(DBError::from)
|
||||
}
|
||||
|
||||
pub async fn get_all_unpublished_recipe_titles(
|
||||
&self,
|
||||
owned_by: i64,
|
||||
) -> Result<Vec<(i64, String)>> {
|
||||
pub async fn get_all_private_recipe_titles(&self, owned_by: i64) -> Result<Vec<(i64, String)>> {
|
||||
sqlx::query_as(
|
||||
r#"
|
||||
SELECT [id], [title]
|
||||
FROM [Recipe]
|
||||
WHERE [is_published] = false AND [user_id] = $1
|
||||
WHERE [is_public] = false AND [user_id] = $1
|
||||
ORDER BY [title]
|
||||
"#,
|
||||
)
|
||||
|
|
@ -264,8 +261,7 @@ WHERE [id] = $1 AND ([user_id] = $2 OR (SELECT [is_admin] FROM [User] WHERE [id]
|
|||
r#"
|
||||
SELECT
|
||||
[id], [user_id], [title], [lang],
|
||||
[estimated_time], [description], [difficulty], [servings],
|
||||
[is_published]
|
||||
[estimated_time], [description], [difficulty], [servings], [is_public]
|
||||
FROM [Recipe] WHERE [id] = $1
|
||||
"#,
|
||||
)
|
||||
|
|
@ -520,10 +516,10 @@ WHERE [id] = $1 AND [id] NOT IN (
|
|||
.map_err(DBError::from)
|
||||
}
|
||||
|
||||
pub async fn set_recipe_is_published(&self, recipe_id: i64, is_published: bool) -> Result<()> {
|
||||
sqlx::query("UPDATE [Recipe] SET [is_published] = $2 WHERE [id] = $1")
|
||||
pub async fn set_recipe_is_public(&self, recipe_id: i64, is_public: bool) -> Result<()> {
|
||||
sqlx::query("UPDATE [Recipe] SET [is_public] = $2 WHERE [id] = $1")
|
||||
.bind(recipe_id)
|
||||
.bind(is_published)
|
||||
.bind(is_public)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map(|_| ())
|
||||
|
|
@ -966,7 +962,7 @@ mod tests {
|
|||
.set_recipe_difficulty(recipe_id, Difficulty::Medium)
|
||||
.await?;
|
||||
connection.set_recipe_language(recipe_id, "fr").await?;
|
||||
connection.set_recipe_is_published(recipe_id, true).await?;
|
||||
connection.set_recipe_is_public(recipe_id, true).await?;
|
||||
|
||||
let recipe = connection.get_recipe(recipe_id, false).await?.unwrap();
|
||||
|
||||
|
|
@ -976,7 +972,7 @@ mod tests {
|
|||
assert_eq!(recipe.estimated_time, Some(420));
|
||||
assert_eq!(recipe.difficulty, Difficulty::Medium);
|
||||
assert_eq!(recipe.lang, "fr");
|
||||
assert!(recipe.is_published);
|
||||
assert!(recipe.is_public);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub struct Recipe {
|
|||
pub difficulty: Difficulty,
|
||||
|
||||
pub servings: Option<u32>,
|
||||
pub is_published: bool,
|
||||
pub is_public: bool,
|
||||
|
||||
#[sqlx(skip)]
|
||||
pub tags: Vec<String>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue