added microchip-based search
This commit is contained in:
parent
c9806e4458
commit
2e0ae0de57
3 changed files with 30 additions and 12 deletions
|
@ -3,7 +3,11 @@ use sqlx::types::chrono;
|
|||
|
||||
use super::schema::{CreateDollProfile, DollTagsDb};
|
||||
|
||||
pub async fn get(mut db: DollTagsDb, ident: i64) -> sqlx::Result<Option<DollProfile>> {
|
||||
pub async fn get(
|
||||
mut db: DollTagsDb,
|
||||
ident: i64,
|
||||
microchip_id: &str,
|
||||
) -> sqlx::Result<Option<DollProfile>> {
|
||||
sqlx::query_as!(
|
||||
DollProfile,
|
||||
r#"
|
||||
|
@ -11,9 +15,10 @@ pub async fn get(mut db: DollTagsDb, ident: i64) -> sqlx::Result<Option<DollProf
|
|||
id, microchip_id,
|
||||
name, pronouns, handler_name, handler_url, kind, breed, behaviour, description, chassis_type, chassis_id, chassis_color,
|
||||
created_at as "created_at!: chrono::NaiveDateTime", updated_at as "updated_at!: Option<chrono::NaiveDateTime>"
|
||||
from doll_profiles where id = ?
|
||||
from doll_profiles where id = ? or microchip_id = ?
|
||||
"#,
|
||||
ident
|
||||
ident,
|
||||
microchip_id
|
||||
)
|
||||
.fetch_optional(&mut **db).await
|
||||
}
|
||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -84,13 +84,14 @@ async fn handle_register(db: DollTagsDb, tag: Form<TagForm<'_>>) -> Template {
|
|||
"{}/{}/{}",
|
||||
tag.pronoun_subject, tag.pronoun_object, tag.pronoun_possessive
|
||||
);
|
||||
let microchip_id = tag.microchip_id.to_lowercase();
|
||||
|
||||
doll::create(
|
||||
db,
|
||||
CreateDollProfile {
|
||||
id,
|
||||
microchip_id: if tag.microchip_id.len() != 0 {
|
||||
Some(tag.microchip_id)
|
||||
microchip_id: if microchip_id.len() != 0 {
|
||||
Some(µchip_id)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
|
@ -145,10 +146,18 @@ async fn handle_register(db: DollTagsDb, tag: Form<TagForm<'_>>) -> Template {
|
|||
Template::render("register", context! {})
|
||||
}
|
||||
|
||||
#[get("/profile?<ident>")]
|
||||
async fn show_profile(db: DollTagsDb, ident: &str) -> Result<Template, Redirect> {
|
||||
let internal_id = id_public_to_db(ident).ok_or_else(|| Redirect::to(uri!("/")))?;
|
||||
let profile = doll::get(db, internal_id)
|
||||
#[get("/profile?<ident>&<microchip_id>")]
|
||||
async fn show_profile(
|
||||
db: DollTagsDb,
|
||||
ident: Option<&str>,
|
||||
microchip_id: Option<&str>,
|
||||
) -> Result<Template, Redirect> {
|
||||
let internal_id = ident
|
||||
.and_then(|v| id_public_to_db(v))
|
||||
.ok_or_else(|| Redirect::to(uri!("/")))?;
|
||||
let microchip_id = microchip_id.unwrap_or("");
|
||||
|
||||
let profile = doll::get(db, internal_id, microchip_id)
|
||||
.await
|
||||
.expect("fuck")
|
||||
.ok_or(Redirect::to(uri!("/")))?;
|
||||
|
|
|
@ -3,9 +3,13 @@
|
|||
{% block main %}
|
||||
<form action="/profile" id="stray-form">
|
||||
<h2>Found a stray?</h2>
|
||||
<label for="ident">Enter the 6-digit ID you found:</label>
|
||||
<input type="text" inputmode="numeric" pattern="\d{6}" id="ident" name="ident" required size="6"
|
||||
placeholder="000000" autofocus />
|
||||
<label for="ident">Enter the 6-digit ID you found</label>
|
||||
<input type="text" inputmode="numeric" pattern="\d{6}" id="ident" name="ident" size="6" placeholder="000000"
|
||||
autofocus />
|
||||
|
||||
<label for="ident">Alternatively, enter the microchip ID (hexadecimal form), if available</label>
|
||||
<input type="text" pattern="(0x)?[a-fA-F0-9]+" id="microchip_id" name="microchip_id"
|
||||
placeholder="A hexadecimal ID" />
|
||||
|
||||
<button type="submit">Search the database</button>
|
||||
</form>
|
||||
|
|
Loading…
Add table
Reference in a new issue