From b63380b251d04dd92f06aa5bbc22a72ca3e4bf8e Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 24 Jul 2025 22:32:27 -0400 Subject: wip: 83B78D40-D7CB-4419-9FE7-E7D858909443 --- src/push/handlers/register.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/push/handlers/register.rs (limited to 'src/push/handlers/register.rs') 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, + identity: Identity, + Json(request): Json, +) -> Result, Internal> { + let subscription = request.into(); + + let id = app.push().register(&identity.user, &subscription).await?; + + Ok(Json(Response { id })) +} + +impl From for SubscriptionInfo { + fn from(request: Request) -> Self { + let Request { + endpoint, + p256dh, + auth, + } = request; + let info = Self::new(endpoint, p256dh, auth); + info + } +} -- cgit v1.2.3