Going somewhere.
This commit is contained in:
1 parent
20cc644bfb
commit
7a212d6d28
5 files changed
+213
-91
No files matched your search
+17
-21
@@ -27,7 +27,7 @@ impl<T> Output<T> {
|
||||
}
|
||||
|
||||
trait CommandLineUserLogic {
|
||||
fn create_user(&mut self, conn: &Connection, name: &String, public_key: &String);
|
||||
fn create_user(&mut self, conn: &mut Connection, name: &String, public_key: &String);
|
||||
|
||||
fn list_user(&mut self, conn: &Connection);
|
||||
|
||||
@@ -103,7 +103,7 @@ fn command_line_parser() -> Command {
|
||||
.subcommand(securities_command_line_parser());
|
||||
}
|
||||
|
||||
fn process_new_user_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_new_user_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
debug!("Processing new user command line {:?}.", m);
|
||||
let name = m.get_one::<String>("name").unwrap();
|
||||
let pk = m.get_one::<String>("public_key").unwrap();
|
||||
@@ -115,7 +115,7 @@ fn process_list_user_command_line(conn: &Connection, m: &ArgMatches, logic: &mut
|
||||
logic.list_user(conn);
|
||||
}
|
||||
|
||||
fn process_user_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_user_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
debug!("Processing user command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("new", new_user_match)) => {
|
||||
@@ -143,7 +143,7 @@ fn process_securities_command_line(conn: &Connection, m: &ArgMatches, logic: &mu
|
||||
}
|
||||
}
|
||||
|
||||
fn process_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
debug!("Processing command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("users", user_match)) => {
|
||||
@@ -181,7 +181,7 @@ mod test {
|
||||
}
|
||||
|
||||
impl CommandLineUserLogic for TestCommandLineLogic {
|
||||
fn create_user(&mut self, _conn: &Connection, _name: &String, _public_key: &String) {
|
||||
fn create_user(&mut self, _conn: &mut Connection, _name: &String, _public_key: &String) {
|
||||
self.create_user_count += 1;
|
||||
}
|
||||
|
||||
@@ -232,8 +232,8 @@ mod test {
|
||||
let cmd = command_line_parser();
|
||||
let m = cmd.get_matches_from(vec!["test", "users", "new", "--name", "paul", "--public-key", "123abc"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&conn, &m, &mut logic);
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&mut conn, &m, &mut logic);
|
||||
assert_eq!(logic.create_user_count, 1);
|
||||
}
|
||||
|
||||
@@ -242,8 +242,8 @@ mod test {
|
||||
let cmd = command_line_parser();
|
||||
let m = cmd.get_matches_from(vec!["test", "users", "ls"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&conn, &m, &mut logic);
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&mut conn, &m, &mut logic);
|
||||
assert_eq!(logic.list_user_count, 1);
|
||||
}
|
||||
|
||||
@@ -252,8 +252,8 @@ mod test {
|
||||
let cmd = command_line_parser();
|
||||
let m = cmd.get_matches_from(vec!["test", "securities", "ls"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&conn, &m, &mut logic);
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&mut conn, &m, &mut logic);
|
||||
assert_eq!(logic.list_securities_count, 1);
|
||||
}
|
||||
}
|
||||
@@ -267,21 +267,17 @@ impl ProCommandLineLogic {
|
||||
}
|
||||
|
||||
impl CommandLineUserLogic for ProCommandLineLogic {
|
||||
fn create_user(&mut self, conn: &Connection, name: &String, public_key: &String) {
|
||||
users::create_user(conn, name, public_key);
|
||||
fn create_user(&mut self, conn: &mut Connection, name: &String, public_key: &String) {
|
||||
let tx = conn.transaction().unwrap();
|
||||
users::create_user(& tx, name, public_key);
|
||||
tx.commit().unwrap();
|
||||
}
|
||||
|
||||
fn list_user(&mut self, conn: &Connection) {
|
||||
let users = users::list_users(conn);
|
||||
match users {
|
||||
Ok(u) => {
|
||||
let r: Vec<& users::User> = u.iter()
|
||||
.filter(|& x| x.is_ok())
|
||||
.map(| x| x.as_ref().unwrap())
|
||||
.collect();
|
||||
|
||||
let out = Output::success(r);
|
||||
|
||||
let out = Output::success(u);
|
||||
println!("{}", serde_json::to_string(&out).unwrap());
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -325,5 +321,5 @@ fn main() {
|
||||
|
||||
apply_migrations(&mut conn).unwrap();
|
||||
let mut logic = ProCommandLineLogic::new();
|
||||
process_command_line(&conn, &m, &mut logic);
|
||||
process_command_line(&mut conn, &m, &mut logic);
|
||||
}
|
||||
Reference in new issue
Block a user