mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
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 rauth::entities::{Model, Session, WebPushSubscription};
|
||||
use rocket::serde::json::Json;
|
||||
use rauth::{
|
||||
entities::{Model, Session, WebPushSubscription},
|
||||
logic::Auth,
|
||||
};
|
||||
use rocket::{serde::json::Json, State};
|
||||
|
||||
#[post("/subscribe"/*, data = "<data>"*/)]
|
||||
pub async fn req(/*mut session: Session, data: Json<WebPushSubscription>*/) -> Result<EmptyResponse>
|
||||
{
|
||||
todo!()
|
||||
#[post("/subscribe", data = "<data>")]
|
||||
pub async fn req(
|
||||
auth: &State<Auth>,
|
||||
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 rauth::entities::{Model, Session};
|
||||
use rauth::{
|
||||
entities::{Model, Session},
|
||||
logic::Auth,
|
||||
};
|
||||
use rocket::State;
|
||||
|
||||
#[post("/unsubscribe")]
|
||||
pub async fn req(/*mut session: Session*/) -> Result<EmptyResponse> {
|
||||
todo!()
|
||||
pub async fn req(auth: &State<Auth>, mut session: Session) -> Result<EmptyResponse> {
|
||||
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