use br_db::Mode;
use json::{JsonValue, object};
use crate::{Action, Model, Response};
use crate::test::test::TestTest;

pub struct TestTestAdd {
    pub model: TestTest,
}

impl Action for TestTestAdd {
    fn title(&mut self) -> &'static str { "添加" }
    fn name(&mut self) -> &'static str { "test.test.add" }
    fn token(&mut self) -> bool { true }
    fn params(&mut self) -> JsonValue {
        let params = object! {};
        return params;
    }

    fn index(&mut self, _header: JsonValue, request: JsonValue) -> Response {
        let data = self.tools().db.table(self.model.table()).insert(request.clone());
        if data.is_empty() {
            return self.fail("添加失败");
        }
        return self.success(data, "添加成功");
    }
}