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 } }