Pedantic clippy pass
This commit is contained in:
parent
7fe20e6ae8
commit
c3255c97f5
13
src/app.rs
13
src/app.rs
@ -2,7 +2,7 @@
|
||||
// use int_enum::IntEnum;
|
||||
use rusqlite::Connection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::min;
|
||||
use std::{cmp::min, error::Error};
|
||||
use tui_textarea::TextArea;
|
||||
|
||||
use crate::db;
|
||||
@ -29,7 +29,6 @@ pub struct Task {
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct Project {
|
||||
pub name: String,
|
||||
pub filepath: String,
|
||||
pub selected_column_idx: usize,
|
||||
pub columns: Vec<Column>,
|
||||
}
|
||||
@ -182,12 +181,16 @@ impl<'a> Column {
|
||||
}
|
||||
|
||||
impl Project {
|
||||
pub async fn load(pool: &Connection) -> Result<Self, KanbanError> {
|
||||
let columns = db::get_all_columns(&pool).unwrap();
|
||||
/// .
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if it has issues reading from the database
|
||||
pub fn load(conn: &Connection) -> Result<Self, Box<dyn Error>> {
|
||||
let columns = db::get_all_columns(conn)?;
|
||||
|
||||
Ok(Project {
|
||||
name: String::from("Kanban Board"),
|
||||
filepath: String::from("path"),
|
||||
columns,
|
||||
selected_column_idx: 0,
|
||||
})
|
||||
|
45
src/db.rs
45
src/db.rs
@ -1,6 +1,11 @@
|
||||
use crate::{Column, Task};
|
||||
use rusqlite::{params, Connection, Result};
|
||||
|
||||
/// .
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if something is wrong with the SQL
|
||||
pub fn get_tasks_by_column(conn: &Connection, column_name: &String) -> Result<Vec<Task>> {
|
||||
let mut stmt = conn.prepare(
|
||||
r#"
|
||||
@ -11,7 +16,7 @@ pub fn get_tasks_by_column(conn: &Connection, column_name: &String) -> Result<Ve
|
||||
"#,
|
||||
)?;
|
||||
let mut tasks = Vec::new();
|
||||
let rows = stmt.query_map(&[column_name], |row| {
|
||||
let rows = stmt.query_map([column_name], |row| {
|
||||
Ok(Task {
|
||||
id: row.get(0)?,
|
||||
title: row.get(1)?,
|
||||
@ -24,6 +29,11 @@ pub fn get_tasks_by_column(conn: &Connection, column_name: &String) -> Result<Ve
|
||||
Ok(tasks)
|
||||
}
|
||||
|
||||
/// .
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if there are issues with the SQL
|
||||
pub fn get_all_columns(conn: &Connection) -> Result<Vec<Column>> {
|
||||
let mut stmt = conn.prepare("select id, name from kb_column")?;
|
||||
let query_rows = stmt.query_map((), |row| {
|
||||
@ -33,11 +43,11 @@ pub fn get_all_columns(conn: &Connection) -> Result<Vec<Column>> {
|
||||
for row in query_rows {
|
||||
let r = &row?;
|
||||
let name = &r.1;
|
||||
let tasks = get_tasks_by_column(conn, &name).unwrap();
|
||||
let tasks = get_tasks_by_column(conn, name)?;
|
||||
let col = Column {
|
||||
id: r.0,
|
||||
name: name.clone(),
|
||||
tasks: tasks,
|
||||
tasks,
|
||||
selected_task_idx: 0,
|
||||
};
|
||||
columns.push(col);
|
||||
@ -45,6 +55,11 @@ pub fn get_all_columns(conn: &Connection) -> Result<Vec<Column>> {
|
||||
Ok(columns)
|
||||
}
|
||||
|
||||
/// .
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if something goes wrong with the SQL
|
||||
pub fn insert_new_task(
|
||||
conn: &Connection,
|
||||
title: String,
|
||||
@ -64,11 +79,21 @@ pub fn insert_new_task(
|
||||
}
|
||||
}
|
||||
|
||||
/// .
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if something goes wrong with the SQL
|
||||
pub fn delete_task(conn: &Connection, task: &Task) {
|
||||
let mut stmt = conn.prepare("delete from task where id = ?1").unwrap();
|
||||
stmt.execute([task.id]).unwrap();
|
||||
}
|
||||
|
||||
/// .
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if something goes wrong with the SQL
|
||||
pub fn update_task_text(conn: &Connection, task: &Task) {
|
||||
let mut stmt = conn
|
||||
.prepare("update task set title = ?2, description = ?3 where id = ?1")
|
||||
@ -77,6 +102,11 @@ pub fn update_task_text(conn: &Connection, task: &Task) {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// .
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if something goes wrong with the SQL
|
||||
pub fn move_task_to_column(conn: &Connection, task: &Task, target_column: &Column) {
|
||||
let mut stmt = conn
|
||||
.prepare(
|
||||
@ -93,12 +123,17 @@ pub fn move_task_to_column(conn: &Connection, task: &Task, target_column: &Colum
|
||||
stmt.execute((&task.id, &target_column.id)).unwrap();
|
||||
}
|
||||
|
||||
/// .
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if something goes wrong with the SQL
|
||||
pub fn swap_task_order(conn: &mut Connection, task1: &Task, task2: &Task) {
|
||||
let tx = conn.transaction().unwrap();
|
||||
|
||||
tx.execute(
|
||||
"create temp table temp_order as select sort_order from task where id = ?1",
|
||||
&[&task1.id],
|
||||
[&task1.id],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@ -111,7 +146,7 @@ pub fn swap_task_order(conn: &mut Connection, task1: &Task, task2: &Task) {
|
||||
|
||||
tx.execute(
|
||||
"update task set sort_order = (select sort_order from temp_order) where id = ?1",
|
||||
&[&task2.id],
|
||||
[&task2.id],
|
||||
)
|
||||
.unwrap();
|
||||
tx.execute("drop table temp_order", ()).unwrap();
|
||||
|
18
src/input.rs
18
src/input.rs
@ -6,6 +6,10 @@ use crossterm::event::{Event, KeyCode};
|
||||
/// # Errors
|
||||
///
|
||||
/// Crossterm `event::read()` might return an error
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Shouldn't really panic because there are checks to ensure we can unwrap safely
|
||||
pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
||||
let project = &mut state.project;
|
||||
let column = project.get_selected_column_mut();
|
||||
@ -40,14 +44,14 @@ pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
||||
if let Some(selected_task) = column.get_selected_task_mut() {
|
||||
selected_task.title = title;
|
||||
selected_task.description = description;
|
||||
db::update_task_text(&state.db_conn, &selected_task);
|
||||
db::update_task_text(&state.db_conn, selected_task);
|
||||
}
|
||||
} else {
|
||||
let task = db::insert_new_task(
|
||||
&state.db_conn,
|
||||
title,
|
||||
description,
|
||||
&column,
|
||||
column,
|
||||
);
|
||||
column.add_task(task);
|
||||
}
|
||||
@ -82,7 +86,7 @@ pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
||||
project.move_task_previous_column();
|
||||
let col = project.get_selected_column();
|
||||
let t = col.get_selected_task().unwrap();
|
||||
db::move_task_to_column(&state.db_conn, &t, &col);
|
||||
db::move_task_to_column(&state.db_conn, t, col);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('L') => {
|
||||
@ -90,26 +94,26 @@ pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
||||
project.move_task_next_column();
|
||||
let col = project.get_selected_column();
|
||||
let t = col.get_selected_task().unwrap();
|
||||
db::move_task_to_column(&state.db_conn, &t, &col);
|
||||
db::move_task_to_column(&state.db_conn, t, col);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('J') => {
|
||||
if column.move_task_down() {
|
||||
let task1 = column.get_selected_task().unwrap();
|
||||
let task2 = column.get_previous_task().unwrap();
|
||||
db::swap_task_order(&mut state.db_conn, &task1, &task2);
|
||||
db::swap_task_order(&mut state.db_conn, task1, task2);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('K') => {
|
||||
if column.move_task_up() {
|
||||
let task1 = column.get_selected_task().unwrap();
|
||||
let task2 = column.get_next_task().unwrap();
|
||||
db::swap_task_order(&mut state.db_conn, &task1, &task2);
|
||||
db::swap_task_order(&mut state.db_conn, task1, task2);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('n') => state.task_edit_state = Some(TaskState::default()),
|
||||
KeyCode::Char('e') => {
|
||||
state.task_edit_state = column.get_task_state_from_curr_selected_task()
|
||||
state.task_edit_state = column.get_task_state_from_curr_selected_task();
|
||||
}
|
||||
KeyCode::Char('D') => {
|
||||
if !column.tasks.is_empty() {
|
||||
|
@ -32,7 +32,7 @@ async fn main() -> anyhow::Result<(), Box<dyn Error>> {
|
||||
|
||||
if migrate {
|
||||
let migrations = include_str!("../sql/migrations.sql");
|
||||
let migrations: Vec<&str> = migrations.split(";").collect();
|
||||
let migrations: Vec<&str> = migrations.split(';').collect();
|
||||
let tx = conn.transaction()?;
|
||||
for m in migrations {
|
||||
if !m.trim().is_empty() {
|
||||
@ -42,7 +42,7 @@ async fn main() -> anyhow::Result<(), Box<dyn Error>> {
|
||||
tx.commit()?;
|
||||
}
|
||||
|
||||
let project = Project::load(&conn).await?;
|
||||
let project = Project::load(&conn)?;
|
||||
let mut state = State::new(conn, project);
|
||||
|
||||
enable_raw_mode()?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user