summary refs log tree commit diff stats
path: root/src/main.rs
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-08-30 19:17:16 -0400
committerBen Morrison <ben@gbmor.dev>2019-08-30 19:18:26 -0400
commitd098a93d910f4bb23e4f0f81a69db83693dd2b78 (patch)
treea044a8a54dceccc0984c251a681e6d92ceb57b30 /src/main.rs
parentcf2b9750ca87ed4fadee63606d8de6f109e84cb8 (diff)
downloadclinte-d098a93d910f4bb23e4f0f81a69db83693dd2b78.tar.gz
moved some functionality to module, added tests
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs
index b837d47..2c9122f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,6 +6,7 @@ use users;
 
 mod db;
 mod logging;
+mod posts;
 
 fn main() {
     let arg_matches = clap::App::new("clinte")
@@ -124,13 +125,7 @@ fn post(db: &db::Conn) {
         &body
     };
 
-    let user = users::get_current_username()
-        .unwrap()
-        .into_string()
-        .unwrap();
-
-    stmt.execute_named(&[(":title", &title), (":author", &user), (":body", &body)])
-        .unwrap();
+    posts::new(&mut stmt, title, body).unwrap();
 
     println!();
 }
@@ -181,15 +176,7 @@ fn update(db: &db::Conn) {
     io::stdin().read_line(&mut new_body).unwrap();
     println!();
 
-    let new_title = new_title.trim();
-    let new_body = new_body.trim();
-
-    let title_stmt = format!("UPDATE posts SET title = :title WHERE id = {}", id_num_in);
-    let mut stmt = db.conn.prepare(&title_stmt).unwrap();
-    stmt.execute_named(&[(":title", &new_title)]).unwrap();
-    let body_stmt = format!("UPDATE posts SET body = :body WHERE id = {}", id_num_in);
-    let mut stmt = db.conn.prepare(&body_stmt).unwrap();
-    stmt.execute_named(&[(":body", &new_body)]).unwrap();
+    posts::update(&new_title, &new_body, id_num_in, &db).unwrap();
 }
 
 fn delete(db: &db::Conn) {
@@ -221,5 +208,17 @@ fn delete(db: &db::Conn) {
         return;
     }
 
-    del_stmt.execute(rusqlite::NO_PARAMS).unwrap();
+    posts::exec_stmt_no_params(&mut del_stmt).unwrap();
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    // Just a "Don't Panic" test
+    #[test]
+    fn display() {
+        let db = db::Conn::new();
+        list_matches(&db);
+    }
 }