apps: sql + get valid one, get by id, insert, generate app id, generate secret
This commit is contained in:
parent
b5c2be6c9f
commit
71b083895d
19 changed files with 490 additions and 0 deletions
61
crates/apps/src/database.rs
Normal file
61
crates/apps/src/database.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use crate::error::Error;
|
||||
use crate::App;
|
||||
use database::sqlx::SqliteExecutor;
|
||||
use database::Apps as DatabaseApps;
|
||||
use hash::Secret;
|
||||
use id::AppID;
|
||||
use url::Url;
|
||||
|
||||
impl From<DatabaseApps> for App {
|
||||
fn from(db: DatabaseApps) -> Self {
|
||||
Self {
|
||||
id: AppID(db.id),
|
||||
created_at: db.created_at,
|
||||
updated_at: db.updated_at,
|
||||
is_archived: db.is_archived,
|
||||
label: db.label,
|
||||
redirect_uri: db.redirect_uri,
|
||||
secret: db.secret,
|
||||
is_confidential: db.is_confidential,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub async fn insert(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &AppID,
|
||||
label: &str,
|
||||
redirect_uri: &Url,
|
||||
secret: &Secret,
|
||||
is_confidential: bool,
|
||||
) -> Result<Option<()>, Error> {
|
||||
Ok(DatabaseApps::insert(
|
||||
conn,
|
||||
id.as_ref(),
|
||||
label,
|
||||
redirect_uri.as_str(),
|
||||
secret.hash(),
|
||||
is_confidential,
|
||||
)
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// App needs to be not archived
|
||||
pub async fn get_one(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
redirect: &str,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
Ok(DatabaseApps::get_one(conn, id, redirect)
|
||||
.await?
|
||||
.map(Self::from))
|
||||
}
|
||||
|
||||
pub async fn get_one_by_id(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
Ok(DatabaseApps::get_one_by_id(conn, id).await?.map(Self::from))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue