chore(api/user): update user notification endpoint
This commit is contained in:
parent
26c86f0796
commit
0e4631ec75
@ -55,6 +55,14 @@ pub fn init_user_routes(cfg: &mut web::ServiceConfig) {
|
|||||||
"/me/notifications/preferences",
|
"/me/notifications/preferences",
|
||||||
web::patch().to(notification::update_notification_preferences),
|
web::patch().to(notification::update_notification_preferences),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
"/me/notifications/push/vapid-key",
|
||||||
|
web::get().to(notification::get_vapid_public_key),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/me/notifications/push/subscription",
|
||||||
|
web::delete().to(notification::unsubscribe_push),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
"/me/heatmap",
|
"/me/heatmap",
|
||||||
web::get().to(chpc::get_my_contribution_heatmap),
|
web::get().to(chpc::get_my_contribution_heatmap),
|
||||||
|
|||||||
@ -1,8 +1,57 @@
|
|||||||
use crate::{ApiResponse, error::ApiError};
|
|
||||||
use actix_web::{HttpResponse, Result, web};
|
use actix_web::{HttpResponse, Result, web};
|
||||||
|
use service::error::AppError;
|
||||||
use service::AppService;
|
use service::AppService;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
|
|
||||||
|
use crate::{error::ApiError, ApiResponse};
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct VapidKeyResponse {
|
||||||
|
pub public_key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/api/users/me/notifications/push/vapid-key",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Get VAPID public key for push subscription", body = ApiResponse<VapidKeyResponse>),
|
||||||
|
(status = 503, description = "Push notifications not configured"),
|
||||||
|
),
|
||||||
|
tag = "User"
|
||||||
|
)]
|
||||||
|
pub async fn get_vapid_public_key(
|
||||||
|
service: web::Data<AppService>,
|
||||||
|
) -> Result<HttpResponse, ApiError> {
|
||||||
|
let public_key = service
|
||||||
|
.config
|
||||||
|
.vapid_public_key();
|
||||||
|
let public_key = match public_key {
|
||||||
|
Some(k) => k,
|
||||||
|
None => {
|
||||||
|
let err: AppError = AppError::InternalError;
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(ApiResponse::ok(VapidKeyResponse { public_key }).to_response())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/api/users/me/notifications/push/subscription",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Unsubscribe from push notifications", body = ApiResponse<serde_json::Value>),
|
||||||
|
(status = 401, description = "Unauthorized"),
|
||||||
|
),
|
||||||
|
tag = "User"
|
||||||
|
)]
|
||||||
|
pub async fn unsubscribe_push(
|
||||||
|
service: web::Data<AppService>,
|
||||||
|
session: Session,
|
||||||
|
) -> Result<HttpResponse, ApiError> {
|
||||||
|
service.user_unsubscribe_push(&session).await?;
|
||||||
|
Ok(ApiResponse::ok(serde_json::json!({ "success": true })).to_response())
|
||||||
|
}
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
get,
|
get,
|
||||||
path = "/api/users/me/notifications/preferences",
|
path = "/api/users/me/notifications/preferences",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user