(conn: Connection<Db>, post_data: DataResult<'_, post::Model>)
| 30 | #[openapi(tag = "POST")] |
| 31 | #[post("/", data = "<post_data>")] |
| 32 | async fn create(conn: Connection<Db>, post_data: DataResult<'_, post::Model>) -> R<Option<String>> { |
| 33 | let db = conn.into_inner(); |
| 34 | let form = post_data?.into_inner(); |
| 35 | let cmd = Mutation::create_post(&db, form); |
| 36 | match cmd.await { |
| 37 | Ok(_) => Ok(Json(Some("Post successfully added.".to_string()))), |
| 38 | Err(e) => { |
| 39 | let m = error::Error { |
| 40 | err: "Could not insert post".to_string(), |
| 41 | msg: Some(e.to_string()), |
| 42 | http_status_code: 400, |
| 43 | }; |
| 44 | Err(m) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /// # Update a post |
| 50 | #[openapi(tag = "POST")] |
no test coverage detected