Introduce MaybeError type
This commit is contained in:
1 parent
d836b57d2a
commit
a60ed37cd4
16 files changed
+127
-93
No files matched your search
@@ -2,7 +2,7 @@ use crate::core::srs::OrderMode;
|
||||
|
||||
use crate::data::entities::DeckSettings;
|
||||
use rusqlite::Connection;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
|
||||
pub fn load_sets(connection: &Connection) -> Result<Vec<DeckSettings>, NotificationData> {
|
||||
@@ -28,7 +28,7 @@ pub fn load_sets(connection: &Connection) -> Result<Vec<DeckSettings>, Notificat
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub fn add_set(set: &mut DeckSettings, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn add_set(set: &mut DeckSettings, connection: &Connection) -> MaybeError {
|
||||
let index : u32 = connection
|
||||
.query_row(
|
||||
"INSERT INTO card_set (name, forward, backward, filter) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
||||
@@ -46,7 +46,7 @@ pub fn add_set(set: &mut DeckSettings, connection: &Connection) -> Result<(), No
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) -> MaybeError {
|
||||
if !set.id.is_valid() {
|
||||
add_set(set, connection)?;
|
||||
} else {
|
||||
@@ -66,7 +66,7 @@ pub fn update_deck(set: &mut DeckSettings, connection: &Connection) -> Result<()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_set(set: &DeckSettings, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn delete_set(set: &DeckSettings, connection: &Connection) -> MaybeError {
|
||||
if !set.id.is_valid() {
|
||||
return Err(DbSaveError);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::data::entities::{CardStatistics, DeckSettings};
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
use log::info;
|
||||
use rusqlite::{Connection, params};
|
||||
@@ -30,7 +30,7 @@ pub fn load_stats_of_deck(
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection) -> Result<(), NotificationData> {
|
||||
pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection) -> MaybeError {
|
||||
let time = Instant::now();
|
||||
let tx = connection.transaction().expect("Failed to create transaction");
|
||||
let count = stats.len();
|
||||
@@ -66,7 +66,7 @@ pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) -> MaybeError {
|
||||
let time = Instant::now();
|
||||
|
||||
connection
|
||||
@@ -79,7 +79,7 @@ pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) -> Resu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_stats(stat: &[CardStatistics], connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn delete_stats(stat: &[CardStatistics], connection: &Connection) -> MaybeError {
|
||||
if stat.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::core::srs::WordOpenMode;
|
||||
use crate::data::Id;
|
||||
use crate::data::entities::HistoryItem;
|
||||
use crate::fs::*;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
use chrono::DateTime;
|
||||
use std::fs::{File, OpenOptions};
|
||||
@@ -20,7 +20,7 @@ pub fn get_history_of_set(id: Id) -> Result<Vec<HistoryItem>, NotificationData>
|
||||
Ok(parse_history_items(lines))
|
||||
}
|
||||
|
||||
fn append_lines_if_exists(path: PathBuf, lines: &mut Vec<String>) -> Result<(), NotificationData> {
|
||||
fn append_lines_if_exists(path: PathBuf, lines: &mut Vec<String>) -> MaybeError {
|
||||
if path.exists() {
|
||||
let reader = BufReader::new(File::open(path).map_err(|_| PermissionDenied)?);
|
||||
reader
|
||||
@@ -63,7 +63,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
||||
items
|
||||
}
|
||||
|
||||
pub fn push_note(set_id: Id, item: HistoryItem) -> Result<(), NotificationData> {
|
||||
pub fn push_note(set_id: Id, item: HistoryItem) -> MaybeError {
|
||||
let app_dir = history_dir()?;
|
||||
let path = app_dir.clone().join(format!("set_{}_history.csv", set_id));
|
||||
|
||||
|
||||
+13
-12
@@ -3,6 +3,8 @@ use hashbrown::HashMap;
|
||||
use log::info;
|
||||
use rusqlite::Connection;
|
||||
use serde_json::Value;
|
||||
use crate::helpers::into_result;
|
||||
use crate::notification::NotificationData::IncorrectAnkiFile;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||
@@ -26,41 +28,40 @@ pub struct ImportNote {
|
||||
pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationData> {
|
||||
let json_models: String = connection
|
||||
.query_one("select models from col", (), |row| row.get(0))
|
||||
.map_err(|_| NotificationData::IncorrectAnkiFile)?;
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
let raw: Value = serde_json::from_str(json_models.as_str())
|
||||
.map_err(|_| NotificationData::IncorrectAnkiFile)?;
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
let sets = raw.as_object();
|
||||
if let Some(sets) = sets {
|
||||
let mut total_data = ImportData(vec![]);
|
||||
|
||||
let mut count_stmt = connection
|
||||
.prepare("select mid, count(id) from notes group by mid")
|
||||
.map_err(|_| NotificationData::IncorrectAnkiFile)?;
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
|
||||
let counts = count_stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.map_err(|_| NotificationData::IncorrectAnkiFile)?
|
||||
.map_err(|_| IncorrectAnkiFile)?
|
||||
.filter_map(|x| x.ok())
|
||||
.collect::<Vec<(i64, i64)>>();
|
||||
|
||||
for (_, collection) in sets {
|
||||
let fields_property = collection.get("fields");
|
||||
if let Some(fields_property) = fields_property {
|
||||
let fields = fields_property
|
||||
.as_array()
|
||||
.unwrap()
|
||||
let fields = into_result(fields_property
|
||||
.as_array(), IncorrectAnkiFile)?
|
||||
.iter()
|
||||
.filter_map(|x| x.get("name"))
|
||||
.map(|x| x.as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let id = collection.get("id");
|
||||
if id.is_none() || id.unwrap().as_u64().is_none(){
|
||||
return Err(NotificationData::IncorrectAnkiFile);
|
||||
return Err(IncorrectAnkiFile);
|
||||
}
|
||||
let id = id.unwrap().as_u64().unwrap();
|
||||
let name = collection.get("name");
|
||||
if name.is_none() || name.unwrap().as_str().is_none() {
|
||||
return Err(NotificationData::IncorrectAnkiFile);
|
||||
return Err(IncorrectAnkiFile);
|
||||
}
|
||||
let name = name.unwrap().as_str().unwrap().to_string();
|
||||
|
||||
@@ -81,13 +82,13 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
|
||||
}
|
||||
return Ok(total_data)
|
||||
}
|
||||
Err(NotificationData::IncorrectAnkiFile)
|
||||
Err(IncorrectAnkiFile)
|
||||
}
|
||||
|
||||
pub fn get_words_of_group(connection: &Connection, group_id: u64) -> Result<Vec<ImportNote>, NotificationData> {
|
||||
let mut count_stmt = connection
|
||||
.prepare("select tags, flds from notes where mid == ?1;")
|
||||
.map_err(|_| NotificationData::IncorrectAnkiFile)?;
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
|
||||
Ok(count_stmt
|
||||
.query_map((group_id as i64,), |row| {
|
||||
@@ -100,7 +101,7 @@ pub fn get_words_of_group(connection: &Connection, group_id: u64) -> Result<Vec<
|
||||
.collect(),
|
||||
})
|
||||
})
|
||||
.map_err(|_| NotificationData::IncorrectAnkiFile)?
|
||||
.map_err(|_| IncorrectAnkiFile)?
|
||||
.filter_map(|x| x.ok())
|
||||
.collect::<Vec<ImportNote>>())
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
use iced::futures::StreamExt;
|
||||
use rusqlite::Connection;
|
||||
@@ -22,7 +22,7 @@ pub fn set_setting(
|
||||
key: String,
|
||||
value: String,
|
||||
connection: &Connection,
|
||||
) -> Result<(), NotificationData> {
|
||||
) -> MaybeError {
|
||||
let current = get_settings_list(connection)?;
|
||||
if current.contains(&key) {
|
||||
update_settings(key, value, connection)?;
|
||||
@@ -33,7 +33,7 @@ pub fn set_setting(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_settings(key: String, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn delete_settings(key: String, connection: &Connection) -> MaybeError {
|
||||
connection
|
||||
.execute("DELETE FROM settings WHERE id = ?1", (&key,))
|
||||
.map_err(|_| DbSaveError)?;
|
||||
@@ -44,7 +44,7 @@ fn create_settings(
|
||||
key: String,
|
||||
value: String,
|
||||
connection: &Connection,
|
||||
) -> Result<(), NotificationData> {
|
||||
) -> MaybeError {
|
||||
connection
|
||||
.execute(
|
||||
"INSERT into settings (id, value) VALUES (?1, ?2)",
|
||||
@@ -58,7 +58,7 @@ fn update_settings(
|
||||
key: String,
|
||||
value: String,
|
||||
connection: &Connection,
|
||||
) -> Result<(), NotificationData> {
|
||||
) -> MaybeError {
|
||||
connection
|
||||
.execute(
|
||||
"update settings
|
||||
|
||||
@@ -5,19 +5,19 @@ pub fn create_db() {
|
||||
let db_file = db_path();
|
||||
if !db_file.exists() {
|
||||
std::fs::File::create(&db_file).expect("Database file creation failed");
|
||||
let connection = Connection::open(&db_file).unwrap();
|
||||
connection.execute("PRAGMA foreign_keys = ON;", []).unwrap();
|
||||
let connection = Connection::open(&db_file).expect("Connection open failed");
|
||||
connection.execute("PRAGMA foreign_keys = ON;", []).expect("Failed to set PRAGMA");
|
||||
|
||||
create_tables(&connection);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_tables(conn: &Connection) {
|
||||
make_card_set(conn).unwrap();
|
||||
make_settings(conn).unwrap();
|
||||
make_word_group(conn).unwrap();
|
||||
make_words(conn).unwrap();
|
||||
make_card_stats(conn).unwrap();
|
||||
make_card_set(conn).expect("Failed to init table");
|
||||
make_settings(conn).expect("Failed to init table");
|
||||
make_word_group(conn).expect("Failed to init table");
|
||||
make_words(conn).expect("Failed to init table");
|
||||
make_card_stats(conn).expect("Failed to init table");
|
||||
}
|
||||
|
||||
fn make_settings(conn: &Connection) -> Result<(), rusqlite::Error> {
|
||||
@@ -51,7 +51,7 @@ fn make_card_stats(conn: &Connection) -> Result<(), rusqlite::Error> {
|
||||
|
||||
pub fn default_connection() -> Connection {
|
||||
let db_file = db_path();
|
||||
let connection = Connection::open(db_file).unwrap();
|
||||
connection.execute("PRAGMA foreign_keys = ON;", []).unwrap();
|
||||
let connection = Connection::open(db_file).expect("Failed to open database");
|
||||
connection.execute("PRAGMA foreign_keys = ON;", []).expect("Failed to set PRAGMA");
|
||||
connection
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
use std::io;
|
||||
use crate::fs::*;
|
||||
use crate::notification::NotificationData::{CompressError, PermissionDenied, WebApiUnavailable};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use log::info;
|
||||
use std::io;
|
||||
use tokio::fs::{File, OpenOptions};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
|
||||
use crate::fs::*;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::{CompressError, PermissionDenied, WebApiUnavailable};
|
||||
use zstd::{Decoder, Encoder, DEFAULT_COMPRESSION_LEVEL};
|
||||
|
||||
// const API_URL: &str = "http://127.0.0.1:8089/";
|
||||
const API_URL: &str = "https://learning.micialware.ru/";
|
||||
|
||||
pub async fn send_data(id: String) -> Result<(), NotificationData> {
|
||||
pub async fn send_data(id: String) -> MaybeError {
|
||||
let db_file = db_path();
|
||||
let data = tokio::fs::read(db_file).await.map_err(|_| WebApiUnavailable)?;
|
||||
let data = tokio::fs::read(db_file)
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?;
|
||||
let data = compress(data)?;
|
||||
|
||||
let api_url = API_URL.to_string();
|
||||
@@ -23,30 +25,35 @@ pub async fn send_data(id: String) -> Result<(), NotificationData> {
|
||||
.post(&id_url)
|
||||
.body(data)
|
||||
.send()
|
||||
.await.map_err(|_| WebApiUnavailable)?
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?
|
||||
.text()
|
||||
.await.map_err(|_| WebApiUnavailable)?;
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?;
|
||||
set_local_version(new_version.parse::<u32>().unwrap_or_default()).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compress(data: Vec<u8>) -> Result<Vec<u8>, NotificationData> {
|
||||
let mut encoder = Encoder::new(Vec::new(), DEFAULT_COMPRESSION_LEVEL).map_err(|_| CompressError)?;
|
||||
let mut encoder =
|
||||
Encoder::new(Vec::new(), DEFAULT_COMPRESSION_LEVEL).map_err(|_| CompressError)?;
|
||||
io::copy(&mut &data[..], &mut encoder).map_err(|_| PermissionDenied)?;
|
||||
encoder.finish().map_err(|_| CompressError)?;
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
pub async fn load_data(id: String, temp: bool) -> Result<(), NotificationData> {
|
||||
pub async fn load_data(id: String, temp: bool) -> MaybeError {
|
||||
let api_url = API_URL.to_string();
|
||||
let id_url = format!("{api_url}download/{id}");
|
||||
let client = reqwest::Client::new();
|
||||
let data = client
|
||||
.get(&id_url)
|
||||
.send()
|
||||
.await.map_err(|_| WebApiUnavailable)?
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?
|
||||
.bytes()
|
||||
.await.map_err(|_| WebApiUnavailable)?
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?
|
||||
.to_vec();
|
||||
let data = decompress(data)?;
|
||||
|
||||
@@ -54,15 +61,19 @@ pub async fn load_data(id: String, temp: bool) -> Result<(), NotificationData> {
|
||||
let file_name = if temp { "data.db.tmp" } else { "data.db" };
|
||||
let db_file = path.join(file_name);
|
||||
|
||||
tokio::fs::write(db_file, data).await.map_err(|_| PermissionDenied)?;
|
||||
tokio::fs::write(db_file, data)
|
||||
.await
|
||||
.map_err(|_| PermissionDenied)?;
|
||||
|
||||
let version_url = format!("{API_URL}{id}/version");
|
||||
let version = client
|
||||
.get(&version_url)
|
||||
.send()
|
||||
.await.map_err(|_| WebApiUnavailable)?
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?
|
||||
.text()
|
||||
.await.map_err(|_| WebApiUnavailable)?;
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?;
|
||||
set_local_version(version.parse::<u32>().unwrap_or_default()).await;
|
||||
Ok(())
|
||||
}
|
||||
@@ -93,22 +104,29 @@ pub async fn first_sync() -> Result<String, NotificationData> {
|
||||
pub async fn get_web_version(key: &str) -> Result<u32, NotificationData> {
|
||||
let id_url = format!("{API_URL}{key}/version");
|
||||
let client = reqwest::Client::new();
|
||||
let version = client.get(&id_url).send().await.map_err(|_| WebApiUnavailable)?.text().await.map_err(|_| WebApiUnavailable)?;
|
||||
let version = client
|
||||
.get(&id_url)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?
|
||||
.text()
|
||||
.await
|
||||
.map_err(|_| WebApiUnavailable)?;
|
||||
info!("version: {}", version);
|
||||
Ok(version.parse::<u32>().unwrap_or_default())
|
||||
}
|
||||
|
||||
pub async fn get_local_version() -> u32 {
|
||||
pub async fn get_local_version() -> Result<u32, NotificationData> {
|
||||
let file = db_meta_path();
|
||||
if file.exists() {
|
||||
let mut data = String::new();
|
||||
File::open(file.clone())
|
||||
.await
|
||||
.unwrap()
|
||||
.map_err(|_| PermissionDenied)?
|
||||
.read_to_string(&mut data)
|
||||
.await
|
||||
.unwrap();
|
||||
return data.parse::<u32>().unwrap_or_default();
|
||||
.map_err(|_| PermissionDenied)?;
|
||||
return Ok(data.parse::<u32>().unwrap_or_default());
|
||||
}
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
@@ -117,12 +135,14 @@ pub async fn get_local_version() -> u32 {
|
||||
.truncate(true)
|
||||
.open(file)
|
||||
.await
|
||||
.unwrap();
|
||||
file.write_all("0".as_bytes()).await.unwrap();
|
||||
0
|
||||
.map_err(|_| PermissionDenied)?;
|
||||
file.write_all("0".as_bytes())
|
||||
.await
|
||||
.map_err(|_| PermissionDenied)?;
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
pub async fn set_local_version(version: u32) {
|
||||
pub async fn set_local_version(version: u32) -> Result<(), NotificationData> {
|
||||
let file_path = db_meta_path();
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
@@ -130,8 +150,9 @@ pub async fn set_local_version(version: u32) {
|
||||
.truncate(true)
|
||||
.open(file_path)
|
||||
.await
|
||||
.unwrap();
|
||||
.map_err(|_| PermissionDenied)?;
|
||||
file.write_all(version.to_string().as_bytes())
|
||||
.await
|
||||
.unwrap();
|
||||
.map_err(|_| PermissionDenied)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
use rusqlite::{Connection, params};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn add_word(word: &mut WordData, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn add_word(word: &mut WordData, connection: &Connection) -> MaybeError {
|
||||
let index : u32 = connection
|
||||
.query_row(
|
||||
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5) RETURNING id",
|
||||
@@ -25,7 +25,7 @@ pub fn add_word(word: &mut WordData, connection: &Connection) -> Result<(), Noti
|
||||
pub fn add_words(
|
||||
words: &mut [WordData],
|
||||
connection: &mut Connection,
|
||||
) -> Result<(), NotificationData> {
|
||||
) -> MaybeError {
|
||||
let tx = connection.transaction().map_err(|_| DbLoadError)?;
|
||||
let count = words.len();
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn add_words(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_word(word: &mut WordData, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn update_word(word: &mut WordData, connection: &Connection) -> MaybeError {
|
||||
if !word.id.is_valid() {
|
||||
Ok(add_word(word, connection)?)
|
||||
} else {
|
||||
@@ -71,7 +71,7 @@ pub fn update_word(word: &mut WordData, connection: &Connection) -> Result<(), N
|
||||
&word.key,
|
||||
&word.value,
|
||||
&word.tags,
|
||||
serde_json::to_string(&word.additional).unwrap(),
|
||||
serde_json::to_string(&word.additional).map_err(|_| DbSaveError)?,
|
||||
&word.id,
|
||||
),
|
||||
)
|
||||
@@ -80,7 +80,7 @@ pub fn update_word(word: &mut WordData, connection: &Connection) -> Result<(), N
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete_word(word: &WordData, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn delete_word(word: &WordData, connection: &Connection) -> MaybeError {
|
||||
if !word.id.is_valid() {
|
||||
return Err(DbSaveError);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ pub fn load_word_groups(connection: &Connection) -> Result<Vec<WordGroup>, Notif
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub fn add_group(group: &mut WordGroup, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn add_group(group: &mut WordGroup, connection: &Connection) -> MaybeError {
|
||||
let index: u32 = connection
|
||||
.query_row(
|
||||
"INSERT INTO word_group (name) VALUES (?1) RETURNING id",
|
||||
@@ -149,7 +149,7 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) -> Result<(), N
|
||||
pub fn update_group(
|
||||
group: &mut WordGroup,
|
||||
connection: &Connection,
|
||||
) -> Result<(), NotificationData> {
|
||||
) -> MaybeError {
|
||||
if !group.id.is_valid() {
|
||||
Ok(add_group(group, connection)?)
|
||||
} else {
|
||||
@@ -163,7 +163,7 @@ pub fn update_group(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete_group(group: &WordGroup, connection: &Connection) -> Result<(), NotificationData> {
|
||||
pub fn delete_group(group: &WordGroup, connection: &Connection) -> MaybeError {
|
||||
if !group.id.is_valid() {
|
||||
return Err(DbSaveError);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user