feat: a bunch of things
This commit is contained in:
parent
2cd0311a20
commit
2e2b01990e
20 changed files with 16216 additions and 137 deletions
58
src/nnid/person_exists.rs
Normal file
58
src/nnid/person_exists.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use rocket::{get, State};
|
||||
use sqlx::Row;
|
||||
use crate::error::{Error, Errors};
|
||||
use crate::Pool;
|
||||
use crate::xml::Xml;
|
||||
|
||||
#[get("/v1/api/people/<username>")]
|
||||
pub async fn person_exists(database: &State<Pool>, 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(),
|
||||
"<?xml version=\"1.0\"?><errors><error><code>0100</code><message>Account ID already exists</message></error></errors>"
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue