add: apps api
This commit is contained in:
parent
2a99d49c8a
commit
ebded00fd3
33 changed files with 698 additions and 31 deletions
|
@ -34,6 +34,7 @@ impl DataManager {
|
|||
execute!(&conn, common::CREATE_TABLE_DRAFTS).unwrap();
|
||||
execute!(&conn, common::CREATE_TABLE_POLLS).unwrap();
|
||||
execute!(&conn, common::CREATE_TABLE_POLLVOTES).unwrap();
|
||||
execute!(&conn, common::CREATE_TABLE_APPS).unwrap();
|
||||
|
||||
self.0
|
||||
.1
|
||||
|
@ -456,7 +457,7 @@ macro_rules! auto_method {
|
|||
let res = execute!(
|
||||
&conn,
|
||||
$query,
|
||||
&[&serde_json::to_string(&x).unwrap(), &(id as i64)]
|
||||
params![&serde_json::to_string(&x).unwrap(), &(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
|
@ -507,6 +508,31 @@ macro_rules! auto_method {
|
|||
}
|
||||
};
|
||||
|
||||
($name:ident()@$select_fn:ident -> $query:literal --cache-key-tmpl=$cache_key_tmpl:literal --decr=$field:ident) => {
|
||||
pub async fn $name(&self, id: usize) -> Result<()> {
|
||||
let y = self.$select_fn(id).await?;
|
||||
|
||||
if (y.$field as isize) - 1 < 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = execute!(&conn, $query, &[&(id as i64)]);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.0.1.remove(format!($cache_key_tmpl, id)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
|
||||
($name:ident()@$select_fn:ident:$permission:ident -> $query:literal --cache-key-tmpl=$cache_key_tmpl:ident) => {
|
||||
pub async fn $name(&self, id: usize, user: &User) -> Result<()> {
|
||||
let y = self.$select_fn(id).await?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue