modified data type for new data schema

This commit is contained in:
2023-01-15 16:52:27 +09:00
parent 67dda85476
commit b274e16b13
2 changed files with 56 additions and 71 deletions

View File

@@ -8,9 +8,7 @@ use wana_kana::to_katakana::*;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
struct SearchResult { struct SearchResult {
id: i64, id: i64,
dex_index: String, name: String,
jap_name: String,
eng_name: String,
types: String, types: String,
hp: i64, hp: i64,
attack: i64, attack: i64,
@@ -18,8 +16,8 @@ struct SearchResult {
special_attack: i64, special_attack: i64,
special_defense: i64, special_defense: i64,
speed: i64, speed: i64,
thumb_small: String, abilities: String,
thumb_big: String, thumbnail: String,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
@@ -49,7 +47,7 @@ fn greet(name: &str) -> String {
fn autosearch(keyword: &str) -> serde_json::Value { fn autosearch(keyword: &str) -> serde_json::Value {
let connection = sqlite::open("./pokemon.db").unwrap(); let connection = sqlite::open("./pokemon.db").unwrap();
let query = "SELECT * FROM pokemon WHERE LOWER(eng_name) like ? or jap_name like ? or jap_name like ? or LOWER(dex_index) like ? LIMIT 5"; let query = "SELECT * FROM pokemon WHERE name like ? or name like ? LIMIT 5";
let mut result: Vec<Autosearch> = vec![]; let mut result: Vec<Autosearch> = vec![];
let aste_keyword = format!("%{}%", keyword.to_lowercase()); let aste_keyword = format!("%{}%", keyword.to_lowercase());
let katakana = format!("%{}%", to_katakana(keyword)); let katakana = format!("%{}%", to_katakana(keyword));
@@ -60,21 +58,15 @@ fn autosearch(keyword: &str) -> serde_json::Value {
.into_iter() .into_iter()
.bind((1, aste_keyword.as_str())) .bind((1, aste_keyword.as_str()))
.unwrap() .unwrap()
.bind((2, aste_keyword.as_str())) .bind((2, katakana.as_str()))
.unwrap()
.bind((3, katakana.as_str()))
.unwrap()
.bind((4, aste_keyword.as_str()))
.unwrap() .unwrap()
.map(|row| row.unwrap()) .map(|row| row.unwrap())
{ {
let row_result = Autosearch { let row_result = Autosearch {
id: row.read::<i64, _>("id"), id: row.read::<i64, _>("id"),
name: format!( name: format!(
"{} - {} ({})", "{}",
row.read::<&str, _>("dex_index").to_string(), row.read::<&str, _>("name").to_string()
row.read::<&str, _>("jap_name").to_string(),
row.read::<&str, _>("eng_name").to_string()
), ),
}; };
result.push(row_result); result.push(row_result);
@@ -96,12 +88,10 @@ fn search(index: i64) -> SearchResult {
{ {
let row_result = SearchResult { let row_result = SearchResult {
id: row.read::<i64, _>("id"), id: row.read::<i64, _>("id"),
dex_index: row.read::<&str, _>("dex_index").to_string(), name: row.read::<&str, _>("name").to_string(),
eng_name: row.read::<&str, _>("eng_name").to_string(),
jap_name: row.read::<&str, _>("jap_name").to_string(),
types: row.read::<&str, _>("types").to_string(), types: row.read::<&str, _>("types").to_string(),
thumb_big: row.read::<&str, _>("thumb_big").to_string(), thumbnail: row.read::<&str, _>("thumbnail").to_string(),
thumb_small: row.read::<&str, _>("thumb_small").to_string(), abilities: row.read::<&str, _>("abilities").to_string(),
hp: row.read::<i64, _>("hp"), hp: row.read::<i64, _>("hp"),
attack: row.read::<i64, _>("attack"), attack: row.read::<i64, _>("attack"),
defense: row.read::<i64, _>("defense"), defense: row.read::<i64, _>("defense"),
@@ -113,12 +103,10 @@ fn search(index: i64) -> SearchResult {
} }
return SearchResult { return SearchResult {
id: 0, id: 0,
dex_index: "#???".to_string(), name: "Missigno".to_string(),
eng_name: "Missigno".to_string(),
jap_name: "Missigno".to_string(),
types: "[]".to_string(), types: "[]".to_string(),
thumb_big: "".to_string(), thumbnail: "".to_string(),
thumb_small: "".to_string(), abilities: "{}".to_string(),
hp: 0, hp: 0,
attack: 0, attack: 0,
defense: 0, defense: 0,

View File

@@ -46,64 +46,60 @@
let result = [] let result = []
parsed_types.forEach(type => { parsed_types.forEach(type => {
switch (type) { switch (type) {
case 0: { case 1: {
result.push(`<div class="normal type">ノーマル</div>`) result.push(`<div class="normal type">ノーマル</div>`)
break; break;
} }
case 1: {
result.push(`<div class="fighting type">かくとう</div>`)
break;
}
case 2: { case 2: {
result.push(`<div class="flying type">ひこう</div>`)
break;
}
case 3: {
result.push(`<div class="poison type">どく</div>`)
break;
}
case 4: {
result.push(`<div class="ground type">じめん</div>`)
break;
}
case 5: {
result.push(`<div class="rock type">いわ</div>`)
break;
}
case 6: {
result.push(`<div class="bug type">むし</div>`)
break;
}
case 7: {
result.push(`<div class="ghost type">ゴースト</div>`)
break;
}
case 8: {
result.push(`<div class="steel type">はがね</div>`)
break;
}
case 9: {
result.push(`<div class="fire type">ほのお</div>`) result.push(`<div class="fire type">ほのお</div>`)
break; break;
} }
case 10: { case 3: {
result.push(`<div class="water type">みず</div>`) result.push(`<div class="water type">みず</div>`)
break; break;
} }
case 11: { case 4: {
result.push(`<div class="grass type">くさ</div>`)
break;
}
case 12: {
result.push(`<div class="electric type">でんき</div>`) result.push(`<div class="electric type">でんき</div>`)
break; break;
} }
case 13: { case 5: {
result.push(`<div class="grass type">くさ</div>`)
break;
}
case 6: {
result.push(`<div class="ice type">こおり</div>`)
break;
}
case 7: {
result.push(`<div class="fighting type">かくとう</div>`)
break;
}
case 8: {
result.push(`<div class="poison type">どく</div>`)
break;
}
case 9: {
result.push(`<div class="ground type">じめん</div>`)
break;
}
case 10: {
result.push(`<div class="flying type">ひこう</div>`)
break;
}
case 11: {
result.push(`<div class="psychic type">エスパー</div>`) result.push(`<div class="psychic type">エスパー</div>`)
break; break;
} }
case 12: {
result.push(`<div class="bug type">むし</div>`)
break;
}
case 13: {
result.push(`<div class="rock type">いわ</div>`)
break;
}
case 14: { case 14: {
result.push(`<div class="ice type">こおり</div>`) result.push(`<div class="ghost type">ゴースト</div>`)
break; break;
} }
case 15: { case 15: {
@@ -115,6 +111,10 @@
break; break;
} }
case 17: { case 17: {
result.push(`<div class="steel type">はがね</div>`)
break;
}
case 18: {
result.push(`<div class="fairy type">フェアリー</div>`) result.push(`<div class="fairy type">フェアリー</div>`)
break; break;
} }
@@ -166,15 +166,12 @@
<div class="data-container"> <div class="data-container">
{#if pokemonData && pokemonData.id && pokemonData.id > 0} {#if pokemonData && pokemonData.id && pokemonData.id > 0}
<div class="row"> <div class="row">
<img src={`data:image/png;base64,${pokemonData.thumb_big}`} alt={pokemonData.jap_name}/> <img src={`data:image/png;base64,${pokemonData.thumbnail}`} alt={pokemonData.jap_name} width="32%"/>
</div> </div>
<div class="row"> <div class="row">
<table> <table>
<tr> <tr>
<td><b>{pokemonData.jap_name}</b></td> <td><b>{pokemonData.name}</b></td>
</tr>
<tr>
<td><b>{pokemonData.eng_name}</b></td>
</tr> </tr>
<tr> <tr>
<td style="display: flex;">{@html generate_type(pokemonData.types)}</td> <td style="display: flex;">{@html generate_type(pokemonData.types)}</td>