diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-07-24 22:32:27 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-07-24 22:32:27 -0400 |
| commit | b63380b251d04dd92f06aa5bbc22a72ca3e4bf8e (patch) | |
| tree | 3956ec457131ce049fd91f2f53309bc0620fffe2 /src/push/handlers/register.rs | |
| parent | 2e42057694851b82574e0a406ded429fb95a07fa (diff) | |
wip: 83B78D40-D7CB-4419-9FE7-E7D858909443
Diffstat (limited to 'src/push/handlers/register.rs')
| -rw-r--r-- | src/push/handlers/register.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/push/handlers/register.rs b/src/push/handlers/register.rs new file mode 100644 index 0000000..201928b --- /dev/null +++ b/src/push/handlers/register.rs @@ -0,0 +1,40 @@ +use axum::extract::{Json, State}; +use web_push::SubscriptionInfo; + +use crate::{app::App, error::Internal, push::Id, token::extract::Identity}; + +#[derive(serde::Deserialize)] +pub struct Request { + endpoint: String, + p256dh: String, + auth: String, +} + +#[derive(serde::Serialize)] +pub struct Response { + id: Id, +} + +pub async fn handler( + State(app): State<App>, + identity: Identity, + Json(request): Json<Request>, +) -> Result<Json<Response>, Internal> { + let subscription = request.into(); + + let id = app.push().register(&identity.user, &subscription).await?; + + Ok(Json(Response { id })) +} + +impl From<Request> for SubscriptionInfo { + fn from(request: Request) -> Self { + let Request { + endpoint, + p256dh, + auth, + } = request; + let info = Self::new(endpoint, p256dh, auth); + info + } +} |
