use rocket::{get, State}; use sqlx::Row; use crate::error::{Error, Errors}; use crate::Pool; use crate::xml::Xml; #[get("/v1/api/people/")] pub async fn person_exists(database: &State, username: &str) -> Result<(), Errors<'static>>{ let database = database.inner(); let exists: bool = sqlx::query_as!( bool, "SELECT EXISTS(SELECT 1 FROM users.users WHERE username = ? )", username ).fetch_one(database) .await .unwrap_or(true); if exists { Err( Errors{ error: &[ Error{ code: "0100", message: "Account ID already exists" } ], } ) } else { Ok(()) } } #[cfg(test)] mod test{ use crate::error::{Error, Errors}; use crate::xml::serialize_with_version; #[test] fn test(){ let val = Errors{ error: &[ Error{ code: "0100", message: "Account ID already exists" } ], }; let enc = serialize_with_version(&val).unwrap(); assert_eq!( enc.as_ref(), "0100Account ID already exists" ) } }