summaryrefslogtreecommitdiff
path: root/src/login/repo/logins.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/login/repo/logins.rs')
-rw-r--r--src/login/repo/logins.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/login/repo/logins.rs b/src/login/repo/logins.rs
index 142d8fb..e1c5057 100644
--- a/src/login/repo/logins.rs
+++ b/src/login/repo/logins.rs
@@ -18,7 +18,7 @@ pub struct Logins<'t>(&'t mut SqliteConnection);
// This also implements FromRequestParts (see `src/login/extract/login.rs`). As
// a result, it can be used as an extractor.
-#[derive(Debug)]
+#[derive(Clone, Debug, serde::Serialize)]
pub struct Login {
pub id: Id,
pub name: String,
@@ -55,6 +55,24 @@ impl<'c> Logins<'c> {
Ok(login)
}
+ pub async fn by_id(&mut self, id: &Id) -> Result<Login, BoxedError> {
+ let login = sqlx::query_as!(
+ Login,
+ r#"
+ select
+ id as "id: Id",
+ name
+ from login
+ where id = $1
+ "#,
+ id,
+ )
+ .fetch_one(&mut *self.0)
+ .await?;
+
+ Ok(login)
+ }
+
/// Retrieves a login by name, plus its stored password hash for
/// verification. If there's no login with the requested name, this will
/// return [None].
@@ -90,7 +108,7 @@ impl<'c> Logins<'c> {
}
/// Stable identifier for a [Login]. Prefixed with `L`.
-#[derive(Clone, Debug, sqlx::Type, serde::Serialize)]
+#[derive(Clone, Debug, Eq, PartialEq, sqlx::Type, serde::Serialize)]
#[sqlx(transparent)]
pub struct Id(BaseId);
@@ -105,3 +123,9 @@ impl Id {
BaseId::generate("L")
}
}
+
+impl std::fmt::Display for Id {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.0.fmt(f)
+ }
+}