df-plugin 0.3.18

This is an Plugin
Documentation
use df_fields::Field;
use json::{JsonValue, object};
use crate::plugin::{{plugin}}::{{model_a}}::{{model}};
use df_plugin::{Action, Response};

pub struct {{action}} {
    pub model: {{model}},
}

impl Action for {{action}} {
    fn title(&mut self) -> &'static str { "{{title}}" }
    fn name(&mut self) -> &'static str { "{{api}}" }
    fn token(&mut self) -> bool { true }
    fn params(&mut self) -> JsonValue {
        let mut params = object! {};
        params[self.model.primary_key()] = df_fields::str::Key::new(true, self.model.primary_key(), "ID", 20).field();
        return params;
    }
    fn index(&mut self, _header: JsonValue, request: JsonValue) -> Response {
        let id = request["id"].clone();
        let data = self.tools().db.table(self.model.table())
            .where_and("id", "=", id.clone())
            .find();
        if data.is_empty() {
            return self.fail("获取失败");
        }
        return self.success(object! {}, "获取成功");
    }
}