(
id: i32,
session: Session,
store: Store,
question: Question,
)
| 32 | } |
| 33 | |
| 34 | pub async fn update_question( |
| 35 | id: i32, |
| 36 | session: Session, |
| 37 | store: Store, |
| 38 | question: Question, |
| 39 | ) -> Result<impl warp::Reply, warp::Rejection> { |
| 40 | let account_id = session.account_id; |
| 41 | if store.is_question_owner(id, &account_id).await? { |
| 42 | let title = check_profanity(question.title); |
| 43 | let content = check_profanity(question.content); |
| 44 | |
| 45 | let (title, content) = tokio::join!(title, content); |
| 46 | |
| 47 | if title.is_ok() && content.is_ok() { |
| 48 | let question = Question { |
| 49 | id: question.id, |
| 50 | title: title.unwrap(), |
| 51 | content: content.unwrap(), |
| 52 | tags: question.tags, |
| 53 | }; |
| 54 | match store.update_question(question, id, account_id).await { |
| 55 | Ok(res) => Ok(warp::reply::json(&res)), |
| 56 | Err(e) => Err(warp::reject::custom(e)), |
| 57 | } |
| 58 | } else { |
| 59 | Err(warp::reject::custom( |
| 60 | title.expect_err("Expected API call to have failed here"), |
| 61 | )) |
| 62 | } |
| 63 | } else { |
| 64 | Err(warp::reject::custom(handle_errors::Error::Unauthorized)) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | pub async fn delete_question( |
| 69 | id: i32, |
nothing calls this directly
no test coverage detected