teo_runtime/handler/default/
delete.rs

1use key_path::path;
2use crate::value::Value;
3use crate::request::Request;
4use crate::response::Response;
5use crate::action::action::*;
6use crate::connection::transaction;
7use crate::model::object::object::ErrorIfNotFound;
8
9pub async fn delete(request: Request) -> teo_result::Result<Response> {
10    let action = DELETE | ENTRY | SINGLE;
11    let value: Value = request.transaction_ctx().run_transaction(move |ctx: transaction::Ctx| {
12        let request = request.clone();
13        let model = request.transaction_ctx().namespace().model_at_path(&request.handler_match().unwrap().path()).unwrap().clone();
14        async move {
15            let object = ctx.find_unique_internal(&model, request.body_value()?, true, action, Some(request.clone()), path![]).await.into_not_found_error(path![])?;
16            object.delete_internal(path!["delete"]).await?;
17            Ok(object.to_teon_internal(&path!["data"]).await?)
18        }
19    }).await?;
20    Ok(Response::data(value))
21}