Move Sheet and Composer to separate code file

This commit is contained in:
Julian Mutter 2024-02-02 16:36:29 +01:00
parent 3f7b45efda
commit 0addc7c4b9
3 changed files with 44 additions and 44 deletions

View File

@ -1,46 +1,7 @@
use log::debug;
use sqlx::{migrate::MigrateDatabase, Connection, Sqlite, SqliteConnection, SqlitePool};
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
#[derive(sqlx::FromRow, Debug)]
pub struct Sheet {
name: String,
// #[sqlx(from = "String")]
path: String,
// #[sqlx(from = "i64")]
file_size: i32,
file_hash: String,
}
#[derive(sqlx::FromRow)]
pub struct Composer {
name: String,
id: u32,
}
impl Sheet {
pub fn new_debug() -> Self {
Sheet {
name: "Hello world".to_string(),
path: "This/is/my/path".into(),
file_size: 42,
file_hash: "h4sh".to_string(),
}
}
pub fn verify_path(&self) -> std::io::Result<bool> {
// First compare file size since it is faster than hashing
// let file_size = fs::metadata(&self.path)?.len();
// if file_size == self.file_size {
// let file_content = fs::read(&self.path)?;
// let file_hash = blake3::hash(&file_content);
// if file_hash.to_string() == self.file_hash {
// return Ok(true);
// }
// }
Ok(false)
}
}
use crate::sheet::Sheet;
pub struct Database {
connection: SqlitePool,

View File

@ -1,8 +1,9 @@
mod database;
mod mcdu;
mod sheet;
mod sheet_listing;
use std::{env, path::PathBuf, process};
use std::{path::PathBuf, process};
use clap::Parser;
use database::Database;
@ -13,8 +14,6 @@ use mcdu::McduModel;
use relm4::prelude::*;
use sheet_listing::{SheetListingInput, SheetListingModel};
use crate::database::Sheet;
struct AppModel {
mcdu: Controller<McduModel>,
sheet_listing: Controller<SheetListingModel>,

40
src/sheet.rs Normal file
View File

@ -0,0 +1,40 @@
#[derive(sqlx::FromRow, Debug)]
pub struct Sheet {
pub name: String,
// #[sqlx(from = "String")]
pub path: String,
// #[sqlx(from = "i64")]
pub file_size: i32,
pub file_hash: String,
}
#[derive(sqlx::FromRow)]
pub struct Composer {
pub name: String,
pub id: u32,
}
impl Sheet {
pub fn new_debug() -> Self {
Sheet {
name: "Hello world".to_string(),
path: "This/is/my/path".into(),
file_size: 42,
file_hash: "h4sh".to_string(),
}
}
pub fn verify_path(&self) -> std::io::Result<bool> {
// First compare file size since it is faster than hashing
// let file_size = fs::metadata(&self.path)?.len();
// if file_size == self.file_size {
// let file_content = fs::read(&self.path)?;
// let file_hash = blake3::hash(&file_content);
// if file_hash.to_string() == self.file_hash {
// return Ok(true);
// }
// }
Ok(false)
}
}