deck list code

This commit is contained in:
micialware committed 2026-10-04 16:47:16 +03:00
1 parent 936efd0e99
commit f4903725aa
2 files changed
+38 -4

No files matched your search

+21 -3
View File
@@ -93,9 +93,7 @@ fn load_old_schema(connection: &Connection) -> Result<ImportData, NotificationDa
} }
Err(IncorrectAnkiFile) Err(IncorrectAnkiFile)
} }
fn load_new_schema(connection: &Connection) -> Result<ImportData, NotificationData> {
return Err(IncorrectAnkiFile);
}
pub fn get_words_of_group( pub fn get_words_of_group(
connection: &Connection, connection: &Connection,
group_id: u64, group_id: u64,
@@ -119,3 +117,23 @@ pub fn get_words_of_group(
.filter_map(|x| x.ok()) .filter_map(|x| x.ok())
.collect::<Vec<ImportNote>>()) .collect::<Vec<ImportNote>>())
} }
fn load_new_schema(connection: &Connection) -> Result<ImportData, NotificationData> {
return Err(IncorrectAnkiFile);
}
pub struct DeckHeader {
pub id: u64,
pub name: String,
pub count: u64,
}
pub fn load_decks(connection: &Connection) -> Result<Vec<DeckHeader>, NotificationData> {
let mut stmt = connection
.prepare("select id, name from decks")
.unwrap();
Ok(stmt.query_map([], |row| Ok(DeckHeader{
id: row.get::<usize, i64>(0)? as u64,
name: row.get(1)?
})).unwrap().filter_map(|x| x.ok()).collect::<Vec<DeckHeader>>())
}
+17 -1
View File
@@ -1,5 +1,5 @@
#[cfg(test)] #[cfg(test)]
mod mod_tests { mod data_access {
use crate::data::Id; use crate::data::Id;
use crate::data::entities::{EntityData, EntityHandle}; use crate::data::entities::{EntityData, EntityHandle};
use crate::data::repositories::fast_position_of; use crate::data::repositories::fast_position_of;
@@ -121,3 +121,19 @@ mod mod_tests {
assert_eq!(entity.index(), 0) assert_eq!(entity.index(), 0)
} }
} }
#[cfg(test)]
mod anki_import{
use std::path::{Path, PathBuf};
use rusqlite::Connection;
use crate::data_provider::import::load_decks;
use crate::notification::NotificationData::IncorrectAnkiFile;
#[test]
pub fn decks(){
let file_name = Path::new("import");
let connection = Connection::open(file_name).unwrap();
let decks = load_decks(&connection).unwrap();
assert_eq!(decks.len(), 2);
}
}