1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-07-11 10:02:48 +00:00

Start to configure Firebase access token

This commit is contained in:
2021-04-11 19:14:59 +02:00
parent c8c03d11e4
commit 6eb153eefa
3 changed files with 44 additions and 0 deletions

@ -5,6 +5,8 @@
use crate::api_data::push_notifications_status_api::PushNotificationsStatusAPI;
use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::data::user_token::PushNotificationToken;
use crate::helpers::account_helper;
use crate::routes::RequestResult;
/// Get current push notifications status for a connection
@ -12,4 +14,31 @@ pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult {
let status = &r.user_access_token().unwrap().push_notifications_token.clone();
r.set_response(PushNotificationsStatusAPI::new(status))
}
/// Configure push notifications for a client
pub fn configure(r: &mut HttpRequestHandler) -> RequestResult {
let status = r.post_string("status")?;
// TODO : check availability of each option
let status = match status.as_str() {
"disabled" => PushNotificationToken::NONE,
"firebase" => {
PushNotificationToken::FIREBASE(r.post_string("firebase_token")?)
}
"independent" => {
unimplemented!();
}
_ => {
return r.bad_request(format!("Unknown status: {}", status));
}
};
account_helper::set_push_notification_token(r.user_access_token().unwrap(), status)?;
r.ok()
}