diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-04 23:19:51 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-04 23:19:51 -0400 |
| commit | beeb40acdc07d5652bf2128ecb8f71a1116993ae (patch) | |
| tree | 14b48e7bf9555cb9079a7d918050ff9dd70c271f /src/channel/repo.rs | |
| parent | cae21da31ff795cc21ec19288fcdc5fdb8a713c7 (diff) | |
Support leaving a channel
Diffstat (limited to 'src/channel/repo.rs')
| -rw-r--r-- | src/channel/repo.rs | 22 |
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 { |
