@@ -5,5 +5,5 @@ mod subscribe;
|
||||
mod unsubscribe;
|
||||
|
||||
pub fn routes() -> (Vec<Route>, OpenApi) {
|
||||
openapi_get_routes_spec![subscribe::req, unsubscribe::req]
|
||||
openapi_get_routes_spec![subscribe::subscribe, unsubscribe::unsubscribe]
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use revolt_quark::{
|
||||
authifier::{
|
||||
models::{Session, WebPushSubscription},
|
||||
Authifier,
|
||||
},
|
||||
EmptyResponse, Error, Result,
|
||||
use authifier::{
|
||||
models::{Session, WebPushSubscription},
|
||||
Authifier,
|
||||
};
|
||||
|
||||
use revolt_result::{create_database_error, Result};
|
||||
use rocket::{serde::json::Json, State};
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
/// # Push Subscribe
|
||||
///
|
||||
@@ -15,7 +13,7 @@ use rocket::{serde::json::Json, State};
|
||||
/// If an existing subscription exists on this session, it will be removed.
|
||||
#[openapi(tag = "Web Push")]
|
||||
#[post("/subscribe", data = "<data>")]
|
||||
pub async fn req(
|
||||
pub async fn subscribe(
|
||||
authifier: &State<Authifier>,
|
||||
mut session: Session,
|
||||
data: Json<WebPushSubscription>,
|
||||
@@ -25,8 +23,5 @@ pub async fn req(
|
||||
.save(authifier)
|
||||
.await
|
||||
.map(|_| EmptyResponse)
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "save",
|
||||
with: "session",
|
||||
})
|
||||
.map_err(|_| create_database_error!("save", "session"))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use revolt_quark::{
|
||||
authifier::{models::Session, Authifier},
|
||||
EmptyResponse, Error, Result,
|
||||
};
|
||||
use authifier::{models::Session, Authifier};
|
||||
|
||||
use revolt_result::{create_database_error, Result};
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
use rocket::State;
|
||||
|
||||
@@ -10,14 +10,14 @@ use rocket::State;
|
||||
/// Remove the Web Push subscription associated with the current session.
|
||||
#[openapi(tag = "Web Push")]
|
||||
#[post("/unsubscribe")]
|
||||
pub async fn req(authifier: &State<Authifier>, mut session: Session) -> Result<EmptyResponse> {
|
||||
pub async fn unsubscribe(
|
||||
authifier: &State<Authifier>,
|
||||
mut session: Session,
|
||||
) -> Result<EmptyResponse> {
|
||||
session.subscription = None;
|
||||
session
|
||||
.save(authifier)
|
||||
.await
|
||||
.map(|_| EmptyResponse)
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "save",
|
||||
with: "session",
|
||||
})
|
||||
.map_err(|_| create_database_error!("save", "session"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user