feat(web push): sub / unsub routes
This commit is contained in:
@@ -1,11 +1,25 @@
|
|||||||
use revolt_quark::{EmptyResponse, Result};
|
use revolt_quark::{EmptyResponse, Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rauth::entities::{Model, Session, WebPushSubscription};
|
use rauth::{
|
||||||
use rocket::serde::json::Json;
|
entities::{Model, Session, WebPushSubscription},
|
||||||
|
logic::Auth,
|
||||||
|
};
|
||||||
|
use rocket::{serde::json::Json, State};
|
||||||
|
|
||||||
#[post("/subscribe"/*, data = "<data>"*/)]
|
#[post("/subscribe", data = "<data>")]
|
||||||
pub async fn req(/*mut session: Session, data: Json<WebPushSubscription>*/) -> Result<EmptyResponse>
|
pub async fn req(
|
||||||
{
|
auth: &State<Auth>,
|
||||||
todo!()
|
mut session: Session,
|
||||||
|
data: Json<WebPushSubscription>,
|
||||||
|
) -> Result<EmptyResponse> {
|
||||||
|
session.subscription = Some(data.into_inner());
|
||||||
|
session
|
||||||
|
.save(&auth.db, None)
|
||||||
|
.await
|
||||||
|
.map(|_| EmptyResponse)
|
||||||
|
.map_err(|_| Error::DatabaseError {
|
||||||
|
operation: "save",
|
||||||
|
with: "session",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
use revolt_quark::{EmptyResponse, Result};
|
use revolt_quark::{EmptyResponse, Error, Result};
|
||||||
|
|
||||||
use mongodb::bson::doc;
|
use mongodb::bson::doc;
|
||||||
use rauth::entities::{Model, Session};
|
use rauth::{
|
||||||
|
entities::{Model, Session},
|
||||||
|
logic::Auth,
|
||||||
|
};
|
||||||
|
use rocket::State;
|
||||||
|
|
||||||
#[post("/unsubscribe")]
|
#[post("/unsubscribe")]
|
||||||
pub async fn req(/*mut session: Session*/) -> Result<EmptyResponse> {
|
pub async fn req(auth: &State<Auth>, mut session: Session) -> Result<EmptyResponse> {
|
||||||
todo!()
|
session.subscription = None;
|
||||||
|
session
|
||||||
|
.save(&auth.db, None)
|
||||||
|
.await
|
||||||
|
.map(|_| EmptyResponse)
|
||||||
|
.map_err(|_| Error::DatabaseError {
|
||||||
|
operation: "save",
|
||||||
|
with: "session",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user