MCPcopy Index your code
hub / github.com/Rust-Web-Development/code / update_question

Function update_question

ch_11/src/routes/question.rs:34–66  ·  view source on GitHub ↗
(
    id: i32,
    session: Session,
    store: Store,
    question: Question,
)

Source from the content-addressed store, hash-verified

32}
33
34pub 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
68pub async fn delete_question(
69 id: i32,

Callers

nothing calls this directly

Calls 3

check_profanityFunction · 0.50
is_question_ownerMethod · 0.45
update_questionMethod · 0.45

Tested by

no test coverage detected