diff options
Diffstat (limited to 'src/push/handlers')
| -rw-r--r-- | src/push/handlers/echo.rs | 18 | ||||
| -rw-r--r-- | src/push/handlers/mod.rs | 1 | ||||
| -rw-r--r-- | src/push/handlers/unregister.rs | 15 |
3 files changed, 26 insertions, 8 deletions
diff --git a/src/push/handlers/echo.rs b/src/push/handlers/echo.rs index 4b4de57..a6c7be2 100644 --- a/src/push/handlers/echo.rs +++ b/src/push/handlers/echo.rs @@ -1,10 +1,10 @@ use axum::extract::{Json, State}; -use crate::{app::App, push::Id, token::extract::Identity}; +use crate::{app::App, token::extract::Identity}; #[derive(serde::Deserialize)] pub struct Request { - subscription: Id, + endpoint: String, msg: String, } @@ -13,8 +13,18 @@ pub async fn handler( identity: Identity, Json(request): Json<Request>, ) -> Result<(), crate::error::Internal> { - let Request { subscription, msg } = request; - app.push().echo(&identity.user, &subscription, &msg).await?; + let Request { endpoint, msg } = request; + app.push().echo(&identity.user, &endpoint, &msg).await?; + + Ok(()) +} + +pub async fn broadcast( + State(app): State<App>, + Json(request): Json<Request>, +) -> Result<(), crate::error::Internal> { + let Request { endpoint: _, msg } = request; + app.push().broadcast(&msg).await?; Ok(()) } diff --git a/src/push/handlers/mod.rs b/src/push/handlers/mod.rs index 90edaa7..4b27ff5 100644 --- a/src/push/handlers/mod.rs +++ b/src/push/handlers/mod.rs @@ -7,6 +7,7 @@ mod register; mod unregister; pub use echo::handler as echo; +pub use echo::broadcast as broadcast; pub use register::handler as register; pub use unregister::handler as unregister; diff --git a/src/push/handlers/unregister.rs b/src/push/handlers/unregister.rs index a00ee92..b35dbd5 100644 --- a/src/push/handlers/unregister.rs +++ b/src/push/handlers/unregister.rs @@ -1,16 +1,23 @@ use axum::{ - extract::{Path, State}, + extract::{Json, State}, http::StatusCode, }; -use crate::{app::App, error::Internal, push::Id, token::extract::Identity}; +use crate::{app::App, error::Internal, token::extract::Identity}; + + +#[derive(serde::Deserialize)] +pub struct Request { + endpoint: String, +} pub async fn handler( State(app): State<App>, identity: Identity, - Path(subscription): Path<Id>, + Json(request): Json<Request>, ) -> Result<StatusCode, Internal> { - app.push().unregister(&identity.user, &subscription).await?; + let Request { endpoint } = request; + app.push().unregister(&identity.user, &endpoint).await?; Ok(StatusCode::NO_CONTENT) } |
