MCPcopy Create free account
hub / github.com/Rust-Web-Development/code / add_answer

Function add_answer

ch_09/src/routes/answer.rs:8–30  ·  view source on GitHub ↗
(
    session: Session,
    store: Store,
    new_answer: NewAnswer,
)

Source from the content-addressed store, hash-verified

6use crate::types::answer::NewAnswer;
7
8pub async fn add_answer(
9 session: Session,
10 store: Store,
11 new_answer: NewAnswer,
12) -> Result<impl warp::Reply, warp::Rejection> {
13 let account_id = session.account_id;
14 let content = match check_profanity(new_answer.content).await {
15 Ok(res) => res,
16 Err(e) => return Err(warp::reject::custom(e)),
17 };
18
19 let answer = NewAnswer {
20 content,
21 question_id: new_answer.question_id,
22 };
23
24 match store.add_answer(answer, account_id).await {
25 Ok(_) => {
26 Ok(warp::reply::with_status("Answer added", StatusCode::OK))
27 }
28 Err(e) => Err(warp::reject::custom(e)),
29 }
30}

Callers

nothing calls this directly

Calls 2

check_profanityFunction · 0.50
add_answerMethod · 0.45

Tested by

no test coverage detected