some more fixes for data consistency
This commit is contained in:
@@ -87,7 +87,7 @@ fn search_move(index: i64) -> MoveSearchResult {
|
||||
let row_result = MoveSearchResult {
|
||||
id: row.read::<i64, _>("id"),
|
||||
name: row.read::<&str, _>("name").to_string(),
|
||||
types: row.read::<&str, _>("types").to_string(),
|
||||
types: serde_json::from_str(row.read::<&str, _>("types")).unwrap_or(vec![0]),
|
||||
power: row.read::<i64, _>("power"),
|
||||
category: row.read::<i64, _>("category"),
|
||||
priority: row.read::<i64, _>("priority"),
|
||||
@@ -101,7 +101,7 @@ fn search_move(index: i64) -> MoveSearchResult {
|
||||
return MoveSearchResult {
|
||||
id: 0,
|
||||
name: "Wrong".to_string(),
|
||||
types: "[0]".to_string(),
|
||||
types: vec![0],
|
||||
power: 0,
|
||||
category: 0,
|
||||
priority: 0,
|
||||
@@ -133,11 +133,44 @@ fn get_items() -> Vec<ItemSearchResult> {
|
||||
return items;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn increase_attack_usage(index: i64) {
|
||||
println!("update index: {index}");
|
||||
let connection = sqlite::open("./pokemon.db").unwrap();
|
||||
let query = format!("UPDATE pokemon__learnset SET usage = usage + 1 WHERE id = {index}");
|
||||
connection.execute(query).unwrap();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn search_learnset(index: i64) -> Vec<PokemonDataLearnset> {
|
||||
let connection = sqlite::open("./pokemon.db").unwrap();
|
||||
let mut learnset: Vec<PokemonDataLearnset> = vec![];
|
||||
let move_query = "SELECT pl.id, pl.learnset_id, l.name, l.types, l.power, l.category FROM pokemon__learnset pl JOIN learnset l on pl.learnset_id = l.id WHERE pl.pokemon_id = ? ORDER BY usage DESC";
|
||||
for row in connection
|
||||
.prepare(move_query)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.bind((1, index))
|
||||
.unwrap()
|
||||
.map(|row| row.unwrap())
|
||||
{
|
||||
let row_result = PokemonDataLearnset {
|
||||
id: row.read::<i64, _>("id"),
|
||||
learnset_id: row.read::<i64, _>("learnset_id"),
|
||||
name: row.read::<&str, _>("name").to_string(),
|
||||
types: serde_json::from_str(row.read::<&str, _>("types")).unwrap_or(vec![0]),
|
||||
power: row.read::<i64, _>("power"),
|
||||
category: row.read::<i64, _>("category"),
|
||||
};
|
||||
learnset.push(row_result)
|
||||
}
|
||||
return learnset;
|
||||
}
|
||||
#[tauri::command]
|
||||
fn search(index: i64) -> SearchResult {
|
||||
let connection = sqlite::open("./pokemon.db").unwrap();
|
||||
let mut learnset: Vec<PokemonDataLearnset> = vec![];
|
||||
let move_query = "SELECT pl.id, pl.learnset_id, l.name, l.types, l.power, l.category FROM pokemon__learnset pl JOIN learnset l on pl.learnset_id = l.id WHERE pl.pokemon_id = ? ORDER BY usage";
|
||||
let move_query = "SELECT pl.id, pl.learnset_id, l.name, l.types, l.power, l.category FROM pokemon__learnset pl JOIN learnset l on pl.learnset_id = l.id WHERE pl.pokemon_id = ? ORDER BY usage DESC";
|
||||
for row in connection
|
||||
.prepare(move_query)
|
||||
.unwrap()
|
||||
@@ -168,7 +201,7 @@ fn search(index: i64) -> SearchResult {
|
||||
let row_result = SearchResult {
|
||||
id: row.read::<i64, _>("id"),
|
||||
name: row.read::<&str, _>("name").to_string(),
|
||||
types: row.read::<&str, _>("types").to_string(),
|
||||
types: serde_json::from_str(row.read::<&str, _>("types")).unwrap_or(vec![0]),
|
||||
thumbnail: row.read::<&str, _>("thumbnail").to_string(),
|
||||
abilities: row.read::<&str, _>("abilities").to_string(),
|
||||
hp: row.read::<i64, _>("hp"),
|
||||
@@ -184,7 +217,7 @@ fn search(index: i64) -> SearchResult {
|
||||
return SearchResult {
|
||||
id: 0,
|
||||
name: "Missigno".to_string(),
|
||||
types: "[]".to_string(),
|
||||
types: vec![],
|
||||
thumbnail: "".to_string(),
|
||||
abilities: "{}".to_string(),
|
||||
hp: 0,
|
||||
@@ -198,7 +231,7 @@ fn search(index: i64) -> SearchResult {
|
||||
}
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![autosearch_move, search_move, autosearch, search, get_items])
|
||||
.invoke_handler(tauri::generate_handler![autosearch_move, search_move, autosearch, search, get_items, increase_attack_usage, search_learnset])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct SearchResult {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub types: String,
|
||||
pub types: Vec<i64>,
|
||||
pub hp: i64,
|
||||
pub attack: i64,
|
||||
pub defense: i64,
|
||||
@@ -29,7 +29,7 @@ pub struct PokemonDataLearnset {
|
||||
pub struct MoveSearchResult {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub types: String,
|
||||
pub types: Vec<i64>,
|
||||
pub power: i64,
|
||||
pub category: i64,
|
||||
pub priority: i64,
|
||||
|
||||
Reference in New Issue
Block a user