Lint the shit out of the project.
This commit is contained in:
1 parent
920ab5d188
commit
af11915a52
9 files changed
+81
-50
No files matched your search
@@ -4,7 +4,6 @@ use serde::Serialize;
|
|||||||
use crate::db::_external_id::{Id, SecurityId};
|
use crate::db::_external_id::{Id, SecurityId};
|
||||||
use crate::util::{CustomResult, Error};
|
use crate::util::{CustomResult, Error};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, PartialEq)]
|
#[derive(Debug, Serialize, PartialEq)]
|
||||||
pub enum SecurityType {
|
pub enum SecurityType {
|
||||||
Currency,
|
Currency,
|
||||||
@@ -77,7 +76,8 @@ pub fn get_security_by_id(tx: &Transaction, id: i32) -> CustomResult<Security> {
|
|||||||
let q = "SELECT id AS sec_id, security_type AS sec_security_type, symbol AS sec_symbol
|
let q = "SELECT id AS sec_id, security_type AS sec_security_type, symbol AS sec_symbol
|
||||||
FROM securities
|
FROM securities
|
||||||
WHERE id = ?1";
|
WHERE id = ?1";
|
||||||
tx.query_row(q, params![id], Security::from_row).map_err(Error::SqlError)
|
tx.query_row(q, params![id], Security::from_row)
|
||||||
|
.map_err(Error::SqlError)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_securities(conn: &Connection) -> CustomResult<Vec<Security>> {
|
pub fn list_securities(conn: &Connection) -> CustomResult<Vec<Security>> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use rusqlite::{Result, Transaction};
|
use rusqlite::{Transaction};
|
||||||
|
|
||||||
use crate::db::_accounts::create_checking_account;
|
use crate::db::_accounts::create_checking_account;
|
||||||
use crate::db::_external_id::UserId;
|
use crate::db::_external_id::UserId;
|
||||||
|
|||||||
+8
-4
@@ -1,7 +1,7 @@
|
|||||||
use crate::db::_external_id::{Id, UserId};
|
use crate::db::_external_id::{Id, UserId};
|
||||||
|
use crate::util::{CustomResult, Error};
|
||||||
use rusqlite::{params, Connection, Result, Row, Transaction};
|
use rusqlite::{params, Connection, Result, Row, Transaction};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use crate::util::{CustomResult, Error};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
@@ -20,7 +20,8 @@ pub fn create_user(tx: &Transaction, name: &String, public_key: &String) -> Cust
|
|||||||
tx.execute(
|
tx.execute(
|
||||||
"INSERT INTO users (name, public_key) VALUES (?1, ?2)",
|
"INSERT INTO users (name, public_key) VALUES (?1, ?2)",
|
||||||
(name, public_key),
|
(name, public_key),
|
||||||
).map_err(Error::SqlError)?;
|
)
|
||||||
|
.map_err(Error::SqlError)?;
|
||||||
return get_user_by_id(tx, tx.last_insert_rowid() as i32);
|
return get_user_by_id(tx, tx.last_insert_rowid() as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,11 +37,14 @@ fn get_user_by_id(tx: &Transaction, id: i32) -> CustomResult<User> {
|
|||||||
let q = "SELECT id, name, public_key
|
let q = "SELECT id, name, public_key
|
||||||
FROM users
|
FROM users
|
||||||
WHERE id = ?1";
|
WHERE id = ?1";
|
||||||
tx.query_row(q, params![id], _user_from_row).map_err(Error::SqlError)
|
tx.query_row(q, params![id], _user_from_row)
|
||||||
|
.map_err(Error::SqlError)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_users(conn: &Connection) -> CustomResult<Vec<User>> {
|
pub fn list_users(conn: &Connection) -> CustomResult<Vec<User>> {
|
||||||
let mut stmt = conn.prepare("SELECT id, name, public_key FROM users").map_err(Error::SqlError)?;
|
let mut stmt = conn
|
||||||
|
.prepare("SELECT id, name, public_key FROM users")
|
||||||
|
.map_err(Error::SqlError)?;
|
||||||
let ret: Vec<User> = stmt
|
let ret: Vec<User> = stmt
|
||||||
.query_map([], _user_from_row)
|
.query_map([], _user_from_row)
|
||||||
.map_err(Error::SqlError)?
|
.map_err(Error::SqlError)?
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::util::{CustomResult, Error};
|
use crate::util::{CustomResult, Error};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -40,10 +36,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
use rusqlite::Connection;
|
|
||||||
use tempfile::tempfile;
|
use tempfile::tempfile;
|
||||||
use crate::event_processor::process_event_file;
|
use super::*;
|
||||||
use crate::util::CustomResult;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic() -> CustomResult<()> {
|
fn test_basic() -> CustomResult<()> {
|
||||||
|
|||||||
+54
-25
@@ -1,7 +1,7 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
|
|
||||||
use clap::parser::ValuesRef;
|
use clap::parser::ValuesRef;
|
||||||
|
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -38,15 +38,29 @@ impl<T> Output<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait CommandLineUserLogic {
|
trait CommandLineUserLogic {
|
||||||
fn create_user(&mut self, conn: &mut Connection, name: &String, public_key: &String) -> CustomResult<()>;
|
fn create_user(
|
||||||
|
&mut self,
|
||||||
|
conn: &mut Connection,
|
||||||
|
name: &String,
|
||||||
|
public_key: &String,
|
||||||
|
) -> CustomResult<()>;
|
||||||
|
|
||||||
fn list_user(&mut self, conn: &Connection) -> CustomResult<()>;
|
fn list_user(&mut self, conn: &Connection) -> CustomResult<()>;
|
||||||
|
|
||||||
fn list_securities(&mut self, conn: &Connection) -> CustomResult<()>;
|
fn list_securities(&mut self, conn: &Connection) -> CustomResult<()>;
|
||||||
|
|
||||||
fn process_events(&mut self, conn: &mut Connection, files: ValuesRef<PathBuf>) -> CustomResult<()>;
|
fn process_events(
|
||||||
|
&mut self,
|
||||||
|
conn: &mut Connection,
|
||||||
|
files: ValuesRef<PathBuf>,
|
||||||
|
) -> CustomResult<()>;
|
||||||
|
|
||||||
fn run_webui(&mut self, conn: &mut Connection, port: u16, enable_template_autoreload: bool) -> CustomResult<()>;
|
fn run_webui(
|
||||||
|
&mut self,
|
||||||
|
conn: &mut Connection,
|
||||||
|
port: u16,
|
||||||
|
enable_template_autoreload: bool,
|
||||||
|
) -> CustomResult<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verbosity_arg() -> Arg {
|
fn verbosity_arg() -> Arg {
|
||||||
@@ -202,9 +216,7 @@ fn process_user_command_line(
|
|||||||
) -> CustomResult<()> {
|
) -> CustomResult<()> {
|
||||||
debug!("Processing user command line {:?}.", m);
|
debug!("Processing user command line {:?}.", m);
|
||||||
match m.subcommand() {
|
match m.subcommand() {
|
||||||
Some(("new", new_user_match)) => {
|
Some(("new", new_user_match)) => process_new_user_command_line(conn, new_user_match, logic),
|
||||||
process_new_user_command_line(conn, new_user_match, logic)
|
|
||||||
}
|
|
||||||
Some(("ls", list_user_match)) => {
|
Some(("ls", list_user_match)) => {
|
||||||
process_list_user_command_line(conn, list_user_match, logic)
|
process_list_user_command_line(conn, list_user_match, logic)
|
||||||
}
|
}
|
||||||
@@ -230,7 +242,9 @@ fn process_process_events_command_line(
|
|||||||
let mut files = m.get_many::<PathBuf>("PATH").unwrap();
|
let mut files = m.get_many::<PathBuf>("PATH").unwrap();
|
||||||
if files.any(|x| !x.exists()) {
|
if files.any(|x| !x.exists()) {
|
||||||
error!("Some passed files do not exists. Existing right now.");
|
error!("Some passed files do not exists. Existing right now.");
|
||||||
return Err(Error::UserInputError("Some passed files do not exists. Existing right now.".to_string()));
|
return Err(Error::UserInputError(
|
||||||
|
"Some passed files do not exists. Existing right now.".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
logic.process_events(conn, files)
|
logic.process_events(conn, files)
|
||||||
@@ -282,9 +296,7 @@ fn process_wui_command_line(
|
|||||||
) -> CustomResult<()> {
|
) -> CustomResult<()> {
|
||||||
debug!("Processing wui command line {:?}.", m);
|
debug!("Processing wui command line {:?}.", m);
|
||||||
match m.subcommand() {
|
match m.subcommand() {
|
||||||
Some(("run", run_wui_match)) => {
|
Some(("run", run_wui_match)) => process_run_wui_command_line(conn, run_wui_match, logic),
|
||||||
process_run_wui_command_line(conn, run_wui_match, logic)
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,18 +308,12 @@ fn process_command_line(
|
|||||||
) -> CustomResult<()> {
|
) -> CustomResult<()> {
|
||||||
debug!("Processing command line {:?}.", m);
|
debug!("Processing command line {:?}.", m);
|
||||||
match m.subcommand() {
|
match m.subcommand() {
|
||||||
Some(("users", user_match)) => {
|
Some(("users", user_match)) => process_user_command_line(conn, user_match, logic),
|
||||||
process_user_command_line(conn, user_match, logic)
|
|
||||||
}
|
|
||||||
Some(("securities", securities_match)) => {
|
Some(("securities", securities_match)) => {
|
||||||
process_securities_command_line(conn, securities_match, logic)
|
process_securities_command_line(conn, securities_match, logic)
|
||||||
}
|
}
|
||||||
Some(("events", events_match)) => {
|
Some(("events", events_match)) => process_events_command_line(conn, events_match, logic),
|
||||||
process_events_command_line(conn, events_match, logic)
|
Some(("wui", wui_match)) => process_wui_command_line(conn, wui_match, logic),
|
||||||
}
|
|
||||||
Some(("wui", wui_match)) => {
|
|
||||||
process_wui_command_line(conn, wui_match, logic)
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
println!("Received un parsable command. {:?}", m.subcommand());
|
println!("Received un parsable command. {:?}", m.subcommand());
|
||||||
unreachable!();
|
unreachable!();
|
||||||
@@ -340,7 +346,12 @@ mod cli_test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CommandLineUserLogic for TestCommandLineLogic {
|
impl CommandLineUserLogic for TestCommandLineLogic {
|
||||||
fn create_user(&mut self, _conn: &mut Connection, _name: &String, _public_key: &String) -> CustomResult<()> {
|
fn create_user(
|
||||||
|
&mut self,
|
||||||
|
_conn: &mut Connection,
|
||||||
|
_name: &String,
|
||||||
|
_public_key: &String,
|
||||||
|
) -> CustomResult<()> {
|
||||||
self.create_user_count += 1;
|
self.create_user_count += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -355,7 +366,11 @@ mod cli_test {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_events(&mut self, _conn: &mut Connection, _files: ValuesRef<PathBuf>) -> CustomResult<()> {
|
fn process_events(
|
||||||
|
&mut self,
|
||||||
|
_conn: &mut Connection,
|
||||||
|
_files: ValuesRef<PathBuf>,
|
||||||
|
) -> CustomResult<()> {
|
||||||
self.process_events_count += 1;
|
self.process_events_count += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -471,7 +486,12 @@ impl ProCommandLineLogic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CommandLineUserLogic for ProCommandLineLogic {
|
impl CommandLineUserLogic for ProCommandLineLogic {
|
||||||
fn create_user(&mut self, conn: &mut Connection, name: &String, public_key: &String) -> CustomResult<()> {
|
fn create_user(
|
||||||
|
&mut self,
|
||||||
|
conn: &mut Connection,
|
||||||
|
name: &String,
|
||||||
|
public_key: &String,
|
||||||
|
) -> CustomResult<()> {
|
||||||
let tx = conn.transaction().map_err(Error::SqlError)?;
|
let tx = conn.transaction().map_err(Error::SqlError)?;
|
||||||
create_user(&tx, name, public_key)?;
|
create_user(&tx, name, public_key)?;
|
||||||
tx.commit().map_err(Error::SqlError)
|
tx.commit().map_err(Error::SqlError)
|
||||||
@@ -491,11 +511,20 @@ impl CommandLineUserLogic for ProCommandLineLogic {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_events(&mut self, conn: &mut Connection, files: ValuesRef<PathBuf>) -> CustomResult<()> {
|
fn process_events(
|
||||||
|
&mut self,
|
||||||
|
conn: &mut Connection,
|
||||||
|
files: ValuesRef<PathBuf>,
|
||||||
|
) -> CustomResult<()> {
|
||||||
process_event_files(conn, files)
|
process_event_files(conn, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_webui(&mut self, _conn: &mut Connection, port: u16, enable_template_autoreload: bool) -> CustomResult<()> {
|
fn run_webui(
|
||||||
|
&mut self,
|
||||||
|
_conn: &mut Connection,
|
||||||
|
port: u16,
|
||||||
|
enable_template_autoreload: bool,
|
||||||
|
) -> CustomResult<()> {
|
||||||
info!("Serving web-ui on port {:?}", port);
|
info!("Serving web-ui on port {:?}", port);
|
||||||
web_ui_main(port, enable_template_autoreload)
|
web_ui_main(port, enable_template_autoreload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,9 @@ fn cash_cheque(tx: &mut Transaction, cheque: &Cheque, account_id: &AccountId) ->
|
|||||||
mod test_caching_cheques {
|
mod test_caching_cheques {
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
use crate::db::accounts::{create_checking_account, create_security_emitter_account, get_account_by_id};
|
use crate::db::accounts::{
|
||||||
|
create_checking_account, create_security_emitter_account, get_account_by_id,
|
||||||
|
};
|
||||||
use crate::db::cheques::{Drawer, Payee};
|
use crate::db::cheques::{Drawer, Payee};
|
||||||
use crate::db::external_id::{Id, UserId};
|
use crate::db::external_id::{Id, UserId};
|
||||||
use crate::db::test_utils;
|
use crate::db::test_utils;
|
||||||
|
|||||||
+4
-5
@@ -1,19 +1,18 @@
|
|||||||
#![feature(future_join)]
|
#![feature(future_join)]
|
||||||
|
|
||||||
|
|
||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use actix_files;
|
use actix_files;
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
App,
|
|
||||||
dev::ServiceResponse,
|
dev::ServiceResponse,
|
||||||
error,
|
error,
|
||||||
FromRequest,
|
http::{header::ContentType, StatusCode},
|
||||||
http::{header::ContentType, StatusCode}, HttpRequest, HttpResponse, HttpServer, middleware::{ErrorHandlerResponse, ErrorHandlers, Logger}, Responder, Result, web,
|
middleware::{ErrorHandlerResponse, ErrorHandlers, Logger},
|
||||||
|
web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder, Result,
|
||||||
};
|
};
|
||||||
use actix_web_lab::respond::Html;
|
use actix_web_lab::respond::Html;
|
||||||
use async_channel;
|
use async_channel;
|
||||||
use futures::{FutureExt, pin_mut, select};
|
use futures::{pin_mut, select, FutureExt};
|
||||||
use minijinja;
|
use minijinja;
|
||||||
use minijinja_autoreload::AutoReloader;
|
use minijinja_autoreload::AutoReloader;
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
use actix_web::http::header::q;
|
|
||||||
use actix_web::{web, HttpRequest, Responder};
|
use actix_web::{web, HttpRequest, Responder};
|
||||||
use clap::builder::TypedValueParser;
|
use clap::builder::TypedValueParser;
|
||||||
use log::info;
|
use log::info;
|
||||||
use minijinja::context;
|
use minijinja::context;
|
||||||
use resource::resource_str;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ pub async fn overview(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Res
|
|||||||
|
|
||||||
#[actix_web::get("/partials/overview/submit_button")]
|
#[actix_web::get("/partials/overview/submit_button")]
|
||||||
pub async fn overview_submit_button(
|
pub async fn overview_submit_button(
|
||||||
req: HttpRequest,
|
_req: HttpRequest,
|
||||||
tmpl_env: MiniJinjaRenderer,
|
tmpl_env: MiniJinjaRenderer,
|
||||||
query: web::Query<HashMap<String, String>>,
|
query: web::Query<HashMap<String, String>>,
|
||||||
) -> actix_web::Result<impl Responder> {
|
) -> actix_web::Result<impl Responder> {
|
||||||
@@ -38,7 +38,7 @@ pub async fn overview_submit_button(
|
|||||||
|
|
||||||
#[actix_web::get("/partials/actions/action-form")]
|
#[actix_web::get("/partials/actions/action-form")]
|
||||||
pub async fn actions_partials(
|
pub async fn actions_partials(
|
||||||
req: HttpRequest,
|
_req: HttpRequest,
|
||||||
tmpl_env: MiniJinjaRenderer,
|
tmpl_env: MiniJinjaRenderer,
|
||||||
query: web::Query<HashMap<String, String>>,
|
query: web::Query<HashMap<String, String>>,
|
||||||
) -> actix_web::Result<impl Responder> {
|
) -> actix_web::Result<impl Responder> {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
use std::{io};
|
use std::io;
|
||||||
|
|
||||||
pub async fn worker_loop(r: async_channel::Receiver<i32>) -> io::Result<()> {
|
pub async fn worker_loop(r: async_channel::Receiver<i32>) -> io::Result<()> {
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
Reference in new issue
Block a user