rename User::get to User::get_by_id and add User::get_by_token

This commit is contained in:
SadlyNotSappho 2024-01-30 09:15:29 -08:00
parent 147d7a251f
commit d01ee9ae73
1 changed files with 14 additions and 2 deletions

View File

@ -82,9 +82,21 @@ impl User {
}
}
}
pub async fn get(mut db: Connection<Db>, id: i32) -> User {
pub async fn get_by_id(mut db: Connection<Db>, id: i32) -> User {
let res = db
.fetch_one(sqlx::query("SELECT * FROM posts WHERE id = $1;").bind(id))
.fetch_one(sqlx::query("SELECT * FROM users WHERE id = $1;").bind(id))
.await
.unwrap();
User {
id: res.get::<i32, _>("id"),
username: res.get::<String, _>("username"),
password: res.get::<String, _>("password"),
token: res.get::<Option<String>, _>("token"),
}
}
pub async fn get_by_token(mut db: Connection<Db>, token: String) -> User {
let res = db
.fetch_one(sqlx::query("SELECT * FROM users WHERE token = $1;").bind(token))
.await
.unwrap();
User {