Skip to content

Commit

Permalink
Merge branch 'master' into prep-for-custom-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot authored Dec 6, 2024
2 parents 40fca68 + 41270e9 commit 1617e70
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,7 @@ pub async fn list(State(ctx): State<AppContext>) -> Result<Response> {
}

pub async fn add(State(ctx): State<AppContext>, Json(params): Json<Params>) -> Result<Response> {
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)
Expand Down Expand Up @@ -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))
}
```
Expand Down Expand Up @@ -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))
}
```
Expand Down Expand Up @@ -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<AppContext>, Json(params): Json<Params>) -> Result<Response> {
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)
Expand All @@ -872,16 +868,14 @@ async fn add(
State(ctx): State<AppContext>,
Json(params): Json<Params>,
) -> Result<Response> {
// 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)
}
```

0 comments on commit 1617e70

Please sign in to comment.