1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use key_path::path;
use teo_teon::Value;
use crate::request;
use crate::response::Response;
use crate::action::action::*;

pub async fn find_first(ctx: &request::Ctx) -> crate::path::Result<Response> {
    let model = ctx.namespace().model_at_path(&ctx.handler_match().path()).unwrap();
    let action = FIND | SINGLE | ENTRY;
    let result = ctx.transaction_ctx().find_first_internal(
        model,
        ctx.body(),
        false,
        action,
        Some(ctx.clone()),
        path![],
    ).await?;
    match result {
        None => Ok(Response::data(Value::Null)?),
        Some(obj) => {
            let obj_data = obj.to_teon_internal(&path!["data"]).await?;
            Ok(Response::data(obj_data)?)
        }
    }
}