diff --git a/docs-site/content/docs/getting-started/guide.md b/docs-site/content/docs/getting-started/guide.md index 4f2f11465..da7dc4443 100644 --- a/docs-site/content/docs/getting-started/guide.md +++ b/docs-site/content/docs/getting-started/guide.md @@ -550,9 +550,7 @@ pub async fn list(State(ctx): State) -> Result { } pub async fn add(State(ctx): State, Json(params): Json) -> Result { - let mut item = ActiveModel { - ..Default::default() - }; + let mut item: ActiveModel = Default::default(); params.update(&mut item); let item = item.insert(&ctx.db).await?; format::json(item) @@ -586,7 +584,7 @@ pub fn routes() -> Routes { .add("/", post(add)) .add("/:id", get(get_one)) .add("/:id", delete(remove)) - .add("/:id", post(update)) + .add("/:id", patch(update)) } ``` @@ -678,7 +676,7 @@ pub fn routes() -> Routes { // .add("/", get(list)) // .add("/:id", get(get_one)) // .add("/:id", delete(remove)) - // .add("/:id", post(update)) + // .add("/:id", patch(update)) } ``` @@ -855,9 +853,7 @@ Go back to `src/controllers/comments.rs` and take a look at the `add` function: ```rust pub async fn add(State(ctx): State, Json(params): Json) -> Result { - let mut item = ActiveModel { - ..Default::default() - }; + let mut item: ActiveModel = Default::default(); params.update(&mut item); let item = item.insert(&ctx.db).await?; format::json(item) @@ -872,16 +868,14 @@ async fn add( State(ctx): State, Json(params): Json, ) -> Result { - // we only want to make sure it exists - let _current_user = crate::models::users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?; - - // next, update - // homework/bonus: make a comment _actually_ belong to user (user_id) - let mut item = ActiveModel { - ..Default::default() - }; - params.update(&mut item); - let item = item.insert(&ctx.db).await?; - format::json(item) + // we only want to make sure it exists + let _current_user = crate::models::users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?; + + // next, update + // homework/bonus: make a comment _actually_ belong to user (user_id) + let mut item: ActiveModel = Default::default(); + params.update(&mut item); + let item = item.insert(&ctx.db).await?; + format::json(item) } ```