refactor and implement user

This commit is contained in:
2023-08-29 21:34:00 +02:00
parent 57f97b0b7d
commit efcac1edc0
9 changed files with 1509 additions and 1344 deletions

View File

@@ -8,6 +8,11 @@ pub struct User {
pub fullname: String,
}
pub struct NewUser<'a> {
pub username: &'a str,
pub fullname: &'a str,
}
#[derive(Debug)]
pub struct DbUserRow {
id: String,
@@ -43,3 +48,22 @@ impl User {
.transpose()
}
}
pub async fn create(pool: &sqlx::Pool<sqlx::Sqlite>, user: NewUser<'_>) -> Result<Uuid, Error> {
let id = Uuid::new_v4();
let id_param = id.to_string();
sqlx::query!(
"INSERT INTO users
(id, username, fullname)
VALUES
(?, ?, ?)",
id_param,
user.username,
user.fullname
)
.execute(pool)
.await?;
Ok(id)
}