Lint the shit out of the project.
This commit is contained in:
1 parent
920ab5d188
commit
af11915a52
9 files changed
+87
-56
No files matched your search
@@ -4,7 +4,6 @@ use serde::Serialize;
|
||||
use crate::db::_external_id::{Id, SecurityId};
|
||||
use crate::util::{CustomResult, Error};
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq)]
|
||||
pub enum SecurityType {
|
||||
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
|
||||
FROM securities
|
||||
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>> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use rusqlite::{Result, Transaction};
|
||||
use rusqlite::{Transaction};
|
||||
|
||||
use crate::db::_accounts::create_checking_account;
|
||||
use crate::db::_external_id::UserId;
|
||||
|
||||
+8
-4
@@ -1,7 +1,7 @@
|
||||
use crate::db::_external_id::{Id, UserId};
|
||||
use crate::util::{CustomResult, Error};
|
||||
use rusqlite::{params, Connection, Result, Row, Transaction};
|
||||
use serde::Serialize;
|
||||
use crate::util::{CustomResult, Error};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct User {
|
||||
@@ -20,7 +20,8 @@ pub fn create_user(tx: &Transaction, name: &String, public_key: &String) -> Cust
|
||||
tx.execute(
|
||||
"INSERT INTO users (name, public_key) VALUES (?1, ?2)",
|
||||
(name, public_key),
|
||||
).map_err(Error::SqlError)?;
|
||||
)
|
||||
.map_err(Error::SqlError)?;
|
||||
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
|
||||
FROM users
|
||||
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>> {
|
||||
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
|
||||
.query_map([], _user_from_row)
|
||||
.map_err(Error::SqlError)?
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
use std::borrow::Borrow;
|
||||
|
||||
|
||||
use std::fs::File;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::util::{CustomResult, Error};
|
||||
|
||||
|
||||
|
||||
|
||||
use rusqlite::Connection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -40,10 +36,11 @@ where
|
||||
}
|
||||
|
||||
mod test {
|
||||
use rusqlite::Connection;
|
||||
use tempfile::tempfile;
|
||||
use crate::event_processor::process_event_file;
|
||||
use crate::util::CustomResult;
|
||||
use super::*;
|
||||
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_basic() -> CustomResult<()> {
|
||||
|
||||
+60
-31
@@ -1,7 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
|
||||
use clap::parser::ValuesRef;
|
||||
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
|
||||
use log::{debug, error, info};
|
||||
use rusqlite::Connection;
|
||||
use serde::Serialize;
|
||||
@@ -38,15 +38,29 @@ impl<T> Output<T> {
|
||||
}
|
||||
|
||||
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_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 {
|
||||
@@ -190,7 +204,7 @@ fn process_list_user_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing list users command line {:?}.", m);
|
||||
logic.list_user(conn)
|
||||
}
|
||||
@@ -202,9 +216,7 @@ fn process_user_command_line(
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing user command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("new", new_user_match)) => {
|
||||
process_new_user_command_line(conn, new_user_match, logic)
|
||||
}
|
||||
Some(("new", new_user_match)) => process_new_user_command_line(conn, new_user_match, logic),
|
||||
Some(("ls", list_user_match)) => {
|
||||
process_list_user_command_line(conn, list_user_match, logic)
|
||||
}
|
||||
@@ -216,7 +228,7 @@ fn process_list_securities_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing list securities command line {:?}.", m);
|
||||
logic.list_securities(conn)
|
||||
}
|
||||
@@ -230,7 +242,9 @@ fn process_process_events_command_line(
|
||||
let mut files = m.get_many::<PathBuf>("PATH").unwrap();
|
||||
if files.any(|x| !x.exists()) {
|
||||
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)
|
||||
@@ -251,7 +265,7 @@ fn process_securities_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing securities command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("ls", list_securities_match)) => {
|
||||
@@ -265,7 +279,7 @@ fn process_events_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing events command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("process", process_events_match)) => {
|
||||
@@ -282,9 +296,7 @@ fn process_wui_command_line(
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing wui command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("run", run_wui_match)) => {
|
||||
process_run_wui_command_line(conn, run_wui_match, logic)
|
||||
}
|
||||
Some(("run", run_wui_match)) => process_run_wui_command_line(conn, run_wui_match, logic),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -296,18 +308,12 @@ fn process_command_line(
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("users", user_match)) => {
|
||||
process_user_command_line(conn, user_match, logic)
|
||||
}
|
||||
Some(("users", user_match)) => process_user_command_line(conn, user_match, logic),
|
||||
Some(("securities", securities_match)) => {
|
||||
process_securities_command_line(conn, securities_match, logic)
|
||||
}
|
||||
Some(("events", events_match)) => {
|
||||
process_events_command_line(conn, events_match, logic)
|
||||
}
|
||||
Some(("wui", wui_match)) => {
|
||||
process_wui_command_line(conn, wui_match, logic)
|
||||
}
|
||||
Some(("events", events_match)) => process_events_command_line(conn, events_match, logic),
|
||||
Some(("wui", wui_match)) => process_wui_command_line(conn, wui_match, logic),
|
||||
_ => {
|
||||
println!("Received un parsable command. {:?}", m.subcommand());
|
||||
unreachable!();
|
||||
@@ -340,22 +346,31 @@ mod cli_test {
|
||||
}
|
||||
|
||||
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;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_user(&mut self, _conn: &Connection) -> CustomResult<()>{
|
||||
fn list_user(&mut self, _conn: &Connection) -> CustomResult<()> {
|
||||
self.list_user_count += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_securities(&mut self, _conn: &Connection) -> CustomResult<()>{
|
||||
fn list_securities(&mut self, _conn: &Connection) -> CustomResult<()> {
|
||||
self.list_securities_count += 1;
|
||||
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;
|
||||
Ok(())
|
||||
}
|
||||
@@ -471,7 +486,12 @@ impl 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)?;
|
||||
create_user(&tx, name, public_key)?;
|
||||
tx.commit().map_err(Error::SqlError)
|
||||
@@ -491,11 +511,20 @@ impl CommandLineUserLogic for ProCommandLineLogic {
|
||||
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)
|
||||
}
|
||||
|
||||
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);
|
||||
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 {
|
||||
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::external_id::{Id, UserId};
|
||||
use crate::db::test_utils;
|
||||
|
||||
+4
-5
@@ -1,19 +1,18 @@
|
||||
#![feature(future_join)]
|
||||
|
||||
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use actix_files;
|
||||
use actix_web::{
|
||||
App,
|
||||
dev::ServiceResponse,
|
||||
error,
|
||||
FromRequest,
|
||||
http::{header::ContentType, StatusCode}, HttpRequest, HttpResponse, HttpServer, middleware::{ErrorHandlerResponse, ErrorHandlers, Logger}, Responder, Result, web,
|
||||
http::{header::ContentType, StatusCode},
|
||||
middleware::{ErrorHandlerResponse, ErrorHandlers, Logger},
|
||||
web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder, Result,
|
||||
};
|
||||
use actix_web_lab::respond::Html;
|
||||
use async_channel;
|
||||
use futures::{FutureExt, pin_mut, select};
|
||||
use futures::{pin_mut, select, FutureExt};
|
||||
use minijinja;
|
||||
use minijinja_autoreload::AutoReloader;
|
||||
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
use actix_web::http::header::q;
|
||||
|
||||
use actix_web::{web, HttpRequest, Responder};
|
||||
use clap::builder::TypedValueParser;
|
||||
use log::info;
|
||||
use minijinja::context;
|
||||
use resource::resource_str;
|
||||
|
||||
use serde::Deserialize;
|
||||
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")]
|
||||
pub async fn overview_submit_button(
|
||||
req: HttpRequest,
|
||||
_req: HttpRequest,
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
query: web::Query<HashMap<String, String>>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
@@ -38,7 +38,7 @@ pub async fn overview_submit_button(
|
||||
|
||||
#[actix_web::get("/partials/actions/action-form")]
|
||||
pub async fn actions_partials(
|
||||
req: HttpRequest,
|
||||
_req: HttpRequest,
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
query: web::Query<HashMap<String, String>>,
|
||||
) -> 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<()> {
|
||||
loop {
|
||||
|
||||
Reference in new issue
Block a user