Rename 'published' to 'public' (for recipe)

This commit is contained in:
Greg Burri 2025-04-02 01:53:02 +02:00
parent eaef6dc77e
commit 4f739593b8
20 changed files with 92 additions and 91 deletions

28
Cargo.lock generated
View file

@ -123,9 +123,9 @@ dependencies = [
[[package]] [[package]]
name = "askama" name = "askama"
version = "0.13.0-pre.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e2034a9f5ce003854892404493ee3c6c7126b606fdc3b7f095b3de96bb91692" checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543"
dependencies = [ dependencies = [
"askama_derive", "askama_derive",
"itoa", "itoa",
@ -136,9 +136,9 @@ dependencies = [
[[package]] [[package]]
name = "askama_derive" name = "askama_derive"
version = "0.13.0-pre.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4093a6764e6fcf280e6fadbcde60614fa0b49cdbf60d823696a68b05f8356a80" checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6"
dependencies = [ dependencies = [
"askama_parser", "askama_parser",
"basic-toml", "basic-toml",
@ -153,9 +153,9 @@ dependencies = [
[[package]] [[package]]
name = "askama_parser" name = "askama_parser"
version = "0.13.0-pre.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "035b5b741f7d44d37a6fef913426b15f3ad5a4afe63b35ce9fce44e6ce55d0d3" checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f"
dependencies = [ dependencies = [
"memchr", "memchr",
"serde", "serde",
@ -414,9 +414,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.34" version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e958897981290da2a852763fe9cdb89cd36977a5d729023127095fa94d95e2ff" checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@ -424,9 +424,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.34" version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83b0f35019843db2160b5bb19ae09b4e6411ac33fc6a712003c33e03090e2489" checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -2081,9 +2081,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "1.0.3" version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e56a18552996ac8d29ecc3b190b4fdbb2d91ca4ec396de7bbffaf43f3d637e96" checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"errno", "errno",
@ -2138,9 +2138,9 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]] [[package]]
name = "scanf" name = "scanf"
version = "1.3.0" version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c9dc7fe5fe9f920a393e3c6f39e5c1830f078f33b03e110ac6b561c7dd04f8" checksum = "db2388de1e65f8545db637b467e3a8ed3c85357ff098c16aa4e9493561e49d03"
dependencies = [ dependencies = [
"nom", "nom",
] ]

View file

@ -27,7 +27,7 @@ clap = { version = "4", features = ["derive"] }
sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "chrono"] } sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "chrono"] }
askama = "=0.13.0-pre.0" askama = "0.13"
argon2 = { version = "0.5", features = ["default", "std"] } argon2 = { version = "0.5", features = ["default", "std"] }
rand_core = { version = "0.9", features = ["std"] } rand_core = { version = "0.9", features = ["std"] }

View file

@ -21,16 +21,16 @@ VALUES (
NULL NULL
); );
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime]) INSERT INTO [Recipe] ([id], [user_id], [title], [is_public], [creation_datetime])
VALUES (1, 1, 'Croissant au jambon', true, '2025-01-07T10:41:05.697884837+00:00'); VALUES (1, 1, 'Croissant au jambon', true, '2025-01-07T10:41:05.697884837+00:00');
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime], [servings], [estimated_time], [difficulty]) INSERT INTO [Recipe] ([id], [user_id], [title], [is_public], [creation_datetime], [servings], [estimated_time], [difficulty])
VALUES (2, 1, 'Gratin de thon aux olives', true, '2025-01-07T10:41:05.697884837+00:00', 4, 40, 1); VALUES (2, 1, 'Gratin de thon aux olives', true, '2025-01-07T10:41:05.697884837+00:00', 4, 40, 1);
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime]) INSERT INTO [Recipe] ([id], [user_id], [title], [is_public], [creation_datetime])
VALUES (3, 1, 'Saumon en croute', true, '2025-01-07T10:41:05.697884837+00:00'); VALUES (3, 1, 'Saumon en croute', true, '2025-01-07T10:41:05.697884837+00:00');
INSERT INTO [Recipe] ([id], [user_id], [title], [is_published], [creation_datetime]) INSERT INTO [Recipe] ([id], [user_id], [title], [is_public], [creation_datetime])
VALUES (4, 2, 'Ouiche lorraine', true, '2025-01-07T10:41:05.697884837+00:00'); VALUES (4, 2, 'Ouiche lorraine', true, '2025-01-07T10:41:05.697884837+00:00');

View file

@ -62,7 +62,7 @@ CREATE TABLE [Recipe] (
-- 0: Unknown, 1: Easy, 2: Medium, 4: Hard. -- 0: Unknown, 1: Easy, 2: Medium, 4: Hard.
[difficulty] INTEGER NOT NULL DEFAULT 0, [difficulty] INTEGER NOT NULL DEFAULT 0,
[servings] INTEGER DEFAULT 4, [servings] INTEGER DEFAULT 4,
[is_published] INTEGER NOT NULL DEFAULT FALSE, [is_public] INTEGER NOT NULL DEFAULT FALSE,
[creation_datetime] TEXT NOT NULL, [creation_datetime] TEXT NOT NULL,
FOREIGN KEY([user_id]) REFERENCES [User]([id]) ON DELETE SET NULL FOREIGN KEY([user_id]) REFERENCES [User]([id]) ON DELETE SET NULL

View file

@ -14,7 +14,7 @@ pub enum AddScheduledRecipeResult {
impl Connection { impl Connection {
/// Returns all the recipe titles where recipe is written in the given language. /// 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. /// 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, &self,
lang: &str, lang: &str,
user_id: Option<i64>, user_id: Option<i64>,
@ -24,7 +24,7 @@ impl Connection {
r#" r#"
SELECT [id], [title] SELECT [id], [title]
FROM [Recipe] 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 ORDER BY [title] COLLATE NOCASE
"#, "#,
) )
@ -35,7 +35,7 @@ ORDER BY [title] COLLATE NOCASE
r#" r#"
SELECT [id], [title] SELECT [id], [title]
FROM [Recipe] FROM [Recipe]
WHERE [is_published] = true AND [lang] = $1 WHERE [is_public] = true AND [lang] = $1
ORDER BY [title] COLLATE NOCASE ORDER BY [title] COLLATE NOCASE
"#, "#,
) )
@ -46,15 +46,12 @@ ORDER BY [title] COLLATE NOCASE
.map_err(DBError::from) .map_err(DBError::from)
} }
pub async fn get_all_unpublished_recipe_titles( pub async fn get_all_private_recipe_titles(&self, owned_by: i64) -> Result<Vec<(i64, String)>> {
&self,
owned_by: i64,
) -> Result<Vec<(i64, String)>> {
sqlx::query_as( sqlx::query_as(
r#" r#"
SELECT [id], [title] SELECT [id], [title]
FROM [Recipe] FROM [Recipe]
WHERE [is_published] = false AND [user_id] = $1 WHERE [is_public] = false AND [user_id] = $1
ORDER BY [title] ORDER BY [title]
"#, "#,
) )
@ -264,8 +261,7 @@ WHERE [id] = $1 AND ([user_id] = $2 OR (SELECT [is_admin] FROM [User] WHERE [id]
r#" r#"
SELECT SELECT
[id], [user_id], [title], [lang], [id], [user_id], [title], [lang],
[estimated_time], [description], [difficulty], [servings], [estimated_time], [description], [difficulty], [servings], [is_public]
[is_published]
FROM [Recipe] WHERE [id] = $1 FROM [Recipe] WHERE [id] = $1
"#, "#,
) )
@ -520,10 +516,10 @@ WHERE [id] = $1 AND [id] NOT IN (
.map_err(DBError::from) .map_err(DBError::from)
} }
pub async fn set_recipe_is_published(&self, recipe_id: i64, is_published: bool) -> Result<()> { pub async fn set_recipe_is_public(&self, recipe_id: i64, is_public: bool) -> Result<()> {
sqlx::query("UPDATE [Recipe] SET [is_published] = $2 WHERE [id] = $1") sqlx::query("UPDATE [Recipe] SET [is_public] = $2 WHERE [id] = $1")
.bind(recipe_id) .bind(recipe_id)
.bind(is_published) .bind(is_public)
.execute(&self.pool) .execute(&self.pool)
.await .await
.map(|_| ()) .map(|_| ())
@ -966,7 +962,7 @@ mod tests {
.set_recipe_difficulty(recipe_id, Difficulty::Medium) .set_recipe_difficulty(recipe_id, Difficulty::Medium)
.await?; .await?;
connection.set_recipe_language(recipe_id, "fr").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(); 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.estimated_time, Some(420));
assert_eq!(recipe.difficulty, Difficulty::Medium); assert_eq!(recipe.difficulty, Difficulty::Medium);
assert_eq!(recipe.lang, "fr"); assert_eq!(recipe.lang, "fr");
assert!(recipe.is_published); assert!(recipe.is_public);
Ok(()) Ok(())
} }

View file

@ -32,7 +32,7 @@ pub struct Recipe {
pub difficulty: Difficulty, pub difficulty: Difficulty,
pub servings: Option<u32>, pub servings: Option<u32>,
pub is_published: bool, pub is_public: bool,
#[sqlx(skip)] #[sqlx(skip)]
pub tags: Vec<String>, pub tags: Vec<String>,

View file

@ -7,8 +7,8 @@ use crate::{
}; };
pub struct Recipes { pub struct Recipes {
pub published: Vec<(i64, String)>, pub public: Vec<(i64, String)>,
pub unpublished: Vec<(i64, String)>, pub private: Vec<(i64, String)>,
pub current_id: Option<i64>, pub current_id: Option<i64>,
} }

View file

@ -162,8 +162,8 @@ async fn main() {
patch(services::ron::recipe::set_language), patch(services::ron::recipe::set_language),
) )
.route( .route(
"/recipe/is_published", "/recipe/is_public",
patch(services::ron::recipe::set_is_published), patch(services::ron::recipe::set_is_public),
) )
.route("/recipe", delete(services::ron::recipe::rm)) .route("/recipe", delete(services::ron::recipe::rm))
.route("/recipe/groups", get(services::ron::recipe::get_groups)) .route("/recipe/groups", get(services::ron::recipe::get_groups))

View file

@ -21,16 +21,14 @@ pub async fn recipes_list_fragments(
Extension(context): Extension<Context>, Extension(context): Extension<Context>,
) -> Result<impl IntoResponse> { ) -> Result<impl IntoResponse> {
let recipes = Recipes { let recipes = Recipes {
published: connection public: connection
.get_all_published_recipe_titles( .get_all_public_recipe_titles(
context.tr.current_lang_code(), context.tr.current_lang_code(),
context.user.as_ref().map(|u| u.id), context.user.as_ref().map(|u| u.id),
) )
.await?, .await?,
unpublished: if let Some(user) = context.user.as_ref() { private: if let Some(user) = context.user.as_ref() {
connection connection.get_all_private_recipe_titles(user.id).await?
.get_all_unpublished_recipe_titles(user.id)
.await?
} else { } else {
vec![] vec![]
}, },

View file

@ -51,16 +51,14 @@ pub async fn home_page(
Extension(context): Extension<Context>, Extension(context): Extension<Context>,
) -> Result<impl IntoResponse> { ) -> Result<impl IntoResponse> {
let recipes = Recipes { let recipes = Recipes {
published: connection public: connection
.get_all_published_recipe_titles( .get_all_public_recipe_titles(
context.tr.current_lang_code(), context.tr.current_lang_code(),
context.user.as_ref().map(|u| u.id), context.user.as_ref().map(|u| u.id),
) )
.await?, .await?,
unpublished: if let Some(user) = context.user.as_ref() { private: if let Some(user) = context.user.as_ref() {
connection connection.get_all_private_recipe_titles(user.id).await?
.get_all_unpublished_recipe_titles(user.id)
.await?
} else { } else {
vec![] vec![]
}, },

View file

@ -44,14 +44,11 @@ pub async fn edit(
if let Some(recipe) = connection.get_recipe(recipe_id, false).await? { if let Some(recipe) = connection.get_recipe(recipe_id, false).await? {
if model::can_user_edit_recipe(user, &recipe) { if model::can_user_edit_recipe(user, &recipe) {
let recipes = Recipes { let recipes = Recipes {
published: connection public: connection
.get_all_published_recipe_titles( .get_all_public_recipe_titles(context.tr.current_lang_code(), Some(user.id))
context.tr.current_lang_code(),
Some(user.id),
)
.await?, .await?,
unpublished: connection private: connection
.get_all_unpublished_recipe_titles(user.id) .get_all_private_recipe_titles(user.id)
.await?, .await?,
current_id: Some(recipe_id), current_id: Some(recipe_id),
}; };
@ -98,7 +95,7 @@ pub async fn view(
) -> Result<Response> { ) -> Result<Response> {
match connection.get_recipe(recipe_id, true).await? { match connection.get_recipe(recipe_id, true).await? {
Some(recipe) => { Some(recipe) => {
if !recipe.is_published if !recipe.is_public
&& (context.user.is_none() || recipe.user_id != context.user.as_ref().unwrap().id) && (context.user.is_none() || recipe.user_id != context.user.as_ref().unwrap().id)
{ {
return Ok(Html( return Ok(Html(
@ -115,15 +112,15 @@ pub async fn view(
} }
let recipes = Recipes { let recipes = Recipes {
published: connection public: connection
.get_all_published_recipe_titles( .get_all_public_recipe_titles(
context.tr.current_lang_code(), context.tr.current_lang_code(),
context.user.as_ref().map(|u| u.id), context.user.as_ref().map(|u| u.id),
) )
.await?, .await?,
unpublished: if let Some(user) = context.user.as_ref() { private: if let Some(user) = context.user.as_ref() {
connection connection
.get_all_unpublished_recipe_titles(user.id) .get_all_private_recipe_titles(user.id)
.await? .await?
} else { } else {
vec![] vec![]

View file

@ -152,14 +152,14 @@ pub async fn set_language(
} }
#[debug_handler] #[debug_handler]
pub async fn set_is_published( pub async fn set_is_public(
State(connection): State<db::Connection>, State(connection): State<db::Connection>,
Extension(context): Extension<Context>, Extension(context): Extension<Context>,
ExtractRon(ron): ExtractRon<ron_api::SetIsPublished>, ExtractRon(ron): ExtractRon<ron_api::SetIsPublic>,
) -> Result<StatusCode> { ) -> Result<StatusCode> {
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?; check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
connection connection
.set_recipe_is_published(ron.recipe_id, ron.is_published) .set_recipe_is_public(ron.recipe_id, ron.is_public)
.await?; .await?;
Ok(StatusCode::OK) Ok(StatusCode::OK)
} }

View file

@ -13,7 +13,7 @@ use crate::consts;
pub enum Sentence { pub enum Sentence {
MainTitle = 0, MainTitle = 0,
CreateNewRecipe, CreateNewRecipe,
UnpublishedRecipes, PrivateRecipes,
UntitledRecipe, UntitledRecipe,
Name, Name,
@ -100,7 +100,7 @@ pub enum Sentence {
RecipeDifficultyHard, RecipeDifficultyHard,
RecipeTags, RecipeTags,
RecipeLanguage, RecipeLanguage,
RecipeIsPublished, RecipeIsPublic,
RecipeDelete, RecipeDelete,
RecipeAddAGroup, RecipeAddAGroup,
RecipeRemoveGroup, RecipeRemoveGroup,

View file

@ -69,13 +69,13 @@
</select> </select>
<input <input
id="input-is-published" id="input-is-public"
type="checkbox" type="checkbox"
{%~ if recipe.is_published %} {%~ if recipe.is_public %}
checked checked
{% endif %} {% endif %}
> >
<label for="input-is-published">{{ context.tr.t(Sentence::RecipeIsPublished) }}</label> <label for="input-is-public">{{ context.tr.t(Sentence::RecipeIsPublic) }}</label>
<input id="input-delete" type="button" value="{{ context.tr.t(Sentence::RecipeDelete) }}"> <input id="input-delete" type="button" value="{{ context.tr.t(Sentence::RecipeDelete) }}">

View file

@ -15,25 +15,25 @@
{% endmacro %} {% endmacro %}
<div id="recipes-list"> <div id="recipes-list">
{% if !recipes.unpublished.is_empty() %} {% if !recipes.private.is_empty() %}
{{ context.tr.t(Sentence::UnpublishedRecipes) }} {{ context.tr.t(Sentence::PrivateRecipes) }}
{% endif %} {% endif %}
<nav class="recipes-list-unpublished"> <nav class="recipes-list-private">
<ul> <ul>
{% for (id, title) in recipes.unpublished %} {% for (id, title) in recipes.private %}
{% call recipe_item(id, title, recipes.is_current(id)) %} {% call recipe_item(id, title, recipes.is_current(id)) %}
{% endfor %} {% endfor %}
</ul> </ul>
</nav> </nav>
{% if !recipes.unpublished.is_empty() %} {% if !recipes.private.is_empty() %}
<hr> <hr>
{% endif %} {% endif %}
<nav class="recipes-list-published"> <nav class="recipes-list-public">
<ul> <ul>
{% for (id, title) in recipes.published %} {% for (id, title) in recipes.public %}
{% call recipe_item(id, title, recipes.is_current(id)) %} {% call recipe_item(id, title, recipes.is_current(id)) %}
{% endfor %} {% endfor %}
</ul> </ul>

View file

@ -6,7 +6,7 @@
translation: [ translation: [
(MainTitle, "Cooking Recipes"), (MainTitle, "Cooking Recipes"),
(CreateNewRecipe, "Create a new recipe"), (CreateNewRecipe, "Create a new recipe"),
(UnpublishedRecipes, "Unpublished recipes"), (PrivateRecipes, "Private recipes"),
(UntitledRecipe, "Untitled recipe"), (UntitledRecipe, "Untitled recipe"),
(Name, "Name"), (Name, "Name"),
@ -86,7 +86,7 @@
(RecipeDifficultyHard, "Hard"), (RecipeDifficultyHard, "Hard"),
(RecipeTags, "Tags"), (RecipeTags, "Tags"),
(RecipeLanguage, "Language"), (RecipeLanguage, "Language"),
(RecipeIsPublished, "Is published"), (RecipeIsPublic, "Is public"),
(RecipeDelete, "Delete recipe"), (RecipeDelete, "Delete recipe"),
(RecipeAddAGroup, "Add a group"), (RecipeAddAGroup, "Add a group"),
(RecipeRemoveGroup, "Remove group"), (RecipeRemoveGroup, "Remove group"),
@ -145,7 +145,7 @@
translation: [ translation: [
(MainTitle, "Recettes de Cuisine"), (MainTitle, "Recettes de Cuisine"),
(CreateNewRecipe, "Créer une nouvelle recette"), (CreateNewRecipe, "Créer une nouvelle recette"),
(UnpublishedRecipes, "Recettes non-publiés"), (PrivateRecipes, "Recettes privées"),
(UntitledRecipe, "Recette sans nom"), (UntitledRecipe, "Recette sans nom"),
(Name, "Nom"), (Name, "Nom"),
@ -225,7 +225,7 @@
(RecipeDifficultyHard, "Difficile"), (RecipeDifficultyHard, "Difficile"),
(RecipeTags, "Tags"), (RecipeTags, "Tags"),
(RecipeLanguage, "Langue"), (RecipeLanguage, "Langue"),
(RecipeIsPublished, "Est publiée"), (RecipeIsPublic, "Est public"),
(RecipeDelete, "Supprimer la recette"), (RecipeDelete, "Supprimer la recette"),
(RecipeAddAGroup, "Ajouter un groupe"), (RecipeAddAGroup, "Ajouter un groupe"),
(RecipeRemoveGroup, "Supprimer le groupe"), (RecipeRemoveGroup, "Supprimer le groupe"),

View file

@ -102,9 +102,9 @@ pub struct SetRecipeLanguage {
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]
pub struct SetIsPublished { pub struct SetIsPublic {
pub recipe_id: i64, pub recipe_id: i64,
pub is_published: bool, pub is_public: bool,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]

View file

@ -226,16 +226,16 @@ pub fn setup_page(recipe_id: i64) {
.forget(); .forget();
} }
// Is published. // Is public.
{ {
let is_published: HtmlInputElement = by_id("input-is-published"); let is_public: HtmlInputElement = by_id("input-is-public");
EventListener::new(&is_published.clone(), "input", move |_event| { EventListener::new(&is_public.clone(), "input", move |_event| {
let body = ron_api::SetIsPublished { let body = ron_api::SetIsPublic {
recipe_id, recipe_id,
is_published: is_published.checked(), is_public: is_public.checked(),
}; };
spawn_local(async move { spawn_local(async move {
let _ = request::patch::<(), _>("recipe/is_published", body).await; let _ = request::patch::<(), _>("recipe/is_public", body).await;
reload_recipes_list(recipe_id).await; reload_recipes_list(recipe_id).await;
}); });
}) })

View file

@ -1,3 +1,7 @@
/// This module provides a simple API for making HTTP requests to the server.
/// For requests with a body (POST, PUT, PATCH, etc.), it uses the RON format.
/// The RON data structures should come from the `ron_api` module.
/// For requests with parameters (GET), it uses the HTML form format.
use common::ron_api; use common::ron_api;
use gloo::net::http::{Request, RequestBuilder}; use gloo::net::http::{Request, RequestBuilder};
use serde::{Serialize, de::DeserializeOwned}; use serde::{Serialize, de::DeserializeOwned};
@ -82,6 +86,13 @@ where
} }
} }
/// Sends a request to the server with the given API name and body.
/// # Example
/// ```rust
/// use common::ron_api;
/// let body = ron_api::SetLang { lang : "en".to_string() };
/// request::put::<(), _>("lang", body).await;
/// ```
pub async fn put<T, U>(api_name: &str, body: U) -> Result<T> pub async fn put<T, U>(api_name: &str, body: U) -> Result<T>
where where
T: DeserializeOwned, T: DeserializeOwned,

1
generate_doc.nu Normal file
View file

@ -0,0 +1 @@
cargo doc --document-private-items --no-deps