use json::{JsonValue, object};
use br_addon::action::{Action, InterfaceType};
use br_addon::module::Module;
use br_addon::request::Request;
use br_addon::ApiResponse;
use br_fields::Field;
use crate::addon::{{plugin}}::{{model_a}}::{{model}};
pub struct {{action}} {
pub module: {{model}},
}
impl Action for {{action}} {
fn tags(&self) -> &'static [&'static str] {
&[]
}
fn title(&self) -> &'static str { "{{title}}" }
fn auth(&self) -> bool {
false
}
fn public(&self) -> bool {
false
}
fn interface_type(&self) -> InterfaceType {
InterfaceType::API
}
fn params(&mut self) -> JsonValue {
let mut params = object! {};
params[self.module.table_key()] = br_fields::str::Key::new(true, self.module.table_key(), "ID", 20).field();
params
}
fn index(&mut self, request: Request) -> ApiResponse {
let id = request.body["id"].clone();
let data = self.tools().db.table(self.module._table_name())
.where_and("id", "=", id.clone())
.find();
if data.is_empty() {
return ApiResponse::fail(111111,"{{title}}失败");
}
ApiResponse::success(data, "{{title}}成功")
}
}