diff options
Diffstat (limited to 'src/push/repo.rs')
| -rw-r--r-- | src/push/repo.rs | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/push/repo.rs b/src/push/repo.rs index ddef706..56bbc3d 100644 --- a/src/push/repo.rs +++ b/src/push/repo.rs @@ -41,7 +41,30 @@ impl Subscriptions<'_> { Ok(id) } - pub async fn by_id(&mut self, id: &Id) -> Result<Subscription, sqlx::Error> { + pub async fn all(&mut self) -> Result<Vec<Subscription>, sqlx::Error> { + let subscriptions = sqlx::query!( + r#" + select + id as "id: Id", + user as "user: user::Id", + endpoint, + key_p256dh, + key_auth + from subscription + "# + ) + .map(|row| Subscription { + id: row.id, + user: row.user, + info: SubscriptionInfo::new(row.endpoint, row.key_p256dh, row.key_auth), + }) + .fetch_all(&mut *self.0) + .await?; + + Ok(subscriptions) + } + + pub async fn by_endpoint(&mut self, endpoint: &String) -> Result<Subscription, sqlx::Error> { let subscription = sqlx::query!( r#" select @@ -51,9 +74,9 @@ impl Subscriptions<'_> { key_p256dh, key_auth from subscription - where id = $1 + where endpoint = $1 "#, - id, + endpoint, ) .map(|row| Subscription { id: row.id, @@ -70,9 +93,9 @@ impl Subscriptions<'_> { sqlx::query!( r#" delete from subscription - where id = $1 + where endpoint = $1 "#, - subscription.id, + subscription.info.endpoint, ) .execute(&mut *self.0) .await?; |
