summaryrefslogtreecommitdiff
path: root/src/channel/repo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel/repo.rs')
-rw-r--r--src/channel/repo.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/channel/repo.rs b/src/channel/repo.rs
index e6a5e5c..bb39d6e 100644
--- a/src/channel/repo.rs
+++ b/src/channel/repo.rs
@@ -82,11 +82,31 @@ impl<'c> Channels<'c> {
Ok(channels)
}
+
+ /// Unenrol a login from a channel.
+ pub async fn leave(&mut self, channel: &Id, login: &LoginId) -> Result<(), BoxedError> {
+ sqlx::query_scalar!(
+ r#"
+ delete
+ from channel_member
+ where channel = $1
+ and login = $2
+ returning 1 as "deleted: bool"
+ "#,
+ channel,
+ login,
+ )
+ .fetch_one(&mut *self.0)
+ .await?;
+
+ Ok(())
+ }
}
/// Stable identifier for a [Channel]. Prefixed with `C`.
-#[derive(Debug, sqlx::Type)]
+#[derive(Debug, sqlx::Type, serde::Deserialize)]
#[sqlx(transparent)]
+#[serde(transparent)]
pub struct Id(BaseId);
impl From<BaseId> for Id {