add: user associations
This commit is contained in:
parent
50319f9124
commit
675b3e4ee6
11 changed files with 131 additions and 9 deletions
|
@ -11,7 +11,6 @@ use crate::model::{
|
|||
};
|
||||
use crate::{auto_method, execute, get, query_row, params};
|
||||
use pathbufd::PathBufD;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::{exists, remove_file};
|
||||
use tetratto_shared::hash::{hash_salted, salt};
|
||||
use tetratto_shared::unix_epoch_timestamp;
|
||||
|
@ -49,6 +48,7 @@ impl DataManager {
|
|||
connections: serde_json::from_str(&get!(x->17(String)).to_string()).unwrap(),
|
||||
stripe_id: get!(x->18(String)),
|
||||
grants: serde_json::from_str(&get!(x->19(String)).to_string()).unwrap(),
|
||||
associated: serde_json::from_str(&get!(x->20(String)).to_string()).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)",
|
||||
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)",
|
||||
params![
|
||||
&(data.id as i64),
|
||||
&(data.created as i64),
|
||||
|
@ -209,7 +209,9 @@ impl DataManager {
|
|||
&0_i32,
|
||||
&0_i32,
|
||||
&serde_json::to_string(&data.connections).unwrap(),
|
||||
&""
|
||||
&"",
|
||||
&serde_json::to_string(&data.grants).unwrap(),
|
||||
&serde_json::to_string(&data.associated).unwrap(),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -753,7 +755,7 @@ impl DataManager {
|
|||
auto_method!(update_user_grants(Vec<AuthGrant>)@get_user_by_id -> "UPDATE users SET grants = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
|
||||
auto_method!(update_user_settings(UserSettings)@get_user_by_id -> "UPDATE users SET settings = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
|
||||
auto_method!(update_user_connections(UserConnections)@get_user_by_id -> "UPDATE users SET connections = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
|
||||
auto_method!(update_user_subscriptions(HashMap<usize, usize>)@get_user_by_id -> "UPDATE users SET subscriptions = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
|
||||
auto_method!(update_user_associated(Vec<usize>)@get_user_by_id -> "UPDATE users SET associated = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
|
||||
|
||||
auto_method!(get_user_by_stripe_id(&str)@get_user_from_row -> "SELECT * FROM users WHERE stripe_id = $1" --name="user" --returns=User);
|
||||
auto_method!(update_user_stripe_id(&str)@get_user_by_id -> "UPDATE users SET stripe_id = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);
|
||||
|
|
|
@ -17,5 +17,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
post_count INT NOT NULL,
|
||||
request_count INT NOT NULL,
|
||||
connections TEXT NOT NULL,
|
||||
subscriptions TEXT NOT NULL
|
||||
stripe_id TEXT NOT NULL,
|
||||
grants TEXT NOT NULL,
|
||||
associated TEXT NOT NULL
|
||||
)
|
||||
|
|
|
@ -46,6 +46,9 @@ pub struct User {
|
|||
/// The grants associated with the user's account.
|
||||
#[serde(default)]
|
||||
pub grants: Vec<AuthGrant>,
|
||||
/// A list of the IDs of all accounts the user has signed into through the UI.
|
||||
#[serde(default)]
|
||||
pub associated: Vec<usize>,
|
||||
}
|
||||
|
||||
pub type UserConnections =
|
||||
|
@ -261,6 +264,7 @@ impl User {
|
|||
connections: HashMap::new(),
|
||||
stripe_id: String::new(),
|
||||
grants: Vec::new(),
|
||||
associated: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue