+ First pass of rtc notifications
* Some tests need to happen in order to ensure correct behavior
This commit is contained in:
parent
0e607eac1d
commit
634461c591
@ -20,7 +20,13 @@ pub async fn new(p: &Pool, response: &mut Response<Body>, params: HashMap<String
|
|||||||
match db::badges::add(p, &name, color, perms).await {
|
match db::badges::add(p, &name, color, perms).await {
|
||||||
Ok(badge) => {
|
Ok(badge) => {
|
||||||
set_json_body(response, json!({"badge": json!(badge)}));
|
set_json_body(response, json!({"badge": json!(badge)}));
|
||||||
// TODO: add some rtc notification here
|
#[cfg(feature = "rtc")]
|
||||||
|
{
|
||||||
|
use crate::rtc;
|
||||||
|
if let Err(e) = rtc::notify("new-badge", badge).await {
|
||||||
|
eprintln!("[API-RTC] Unable to connect to RTC server {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("[HTTP][ERROR] /badge/new {}", e);
|
eprintln!("[HTTP][ERROR] /badge/new {}", e);
|
||||||
@ -39,10 +45,14 @@ pub async fn update_perms(p: &Pool, response: &mut Response<Body>, params: HashM
|
|||||||
match db::badges::update_perms(p, id, perms).await {
|
match db::badges::update_perms(p, id, perms).await {
|
||||||
// TODO: add rtc update here
|
// TODO: add rtc update here
|
||||||
Ok(true) => {
|
Ok(true) => {
|
||||||
|
let payload = json!({ "id": id, "perms": perms});
|
||||||
|
set_json_body(response, json!({"badge-update": payload}));
|
||||||
#[cfg(feature = "rtc")]
|
#[cfg(feature = "rtc")]
|
||||||
{
|
{
|
||||||
let payload = json!({ "id": id, "perms": perms});
|
use crate::rtc;
|
||||||
set_json_body(response, json!({"badge-update": payload}));
|
if let Err(e) = rtc::notify("badge-update-perms", payload).await {
|
||||||
|
eprintln!("[API-RTC] Unable to connect to RTC server {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
@ -68,10 +78,14 @@ pub async fn update_color(p: &Pool, response: &mut Response<Body>, params: HashM
|
|||||||
// NOTE: this response iss more meant for rtc as the non-rtc mode
|
// NOTE: this response iss more meant for rtc as the non-rtc mode
|
||||||
// isn't supposed respond with anything in particular
|
// isn't supposed respond with anything in particular
|
||||||
// TODO: rtc update here
|
// TODO: rtc update here
|
||||||
|
let payload = json!({"id": id, "color": color});
|
||||||
|
set_json_body(response, json!({"badge-update": payload}));
|
||||||
#[cfg(feature = "rtc")]
|
#[cfg(feature = "rtc")]
|
||||||
{
|
{
|
||||||
let payload = json!({"id": id, "color": color});
|
use crate::rtc;
|
||||||
set_json_body(response, json!({"badge-update": payload}));
|
if let Err(e) = rtc::notify("update-badge", payload).await {
|
||||||
|
eprintln!("[API-RTC] Unable to connect to RTC server {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
@ -94,10 +108,14 @@ pub async fn update_name(p: &Pool, response: &mut Response<Body>, params: HashMa
|
|||||||
if let (Some(id), Some(name)) = (id, name) {
|
if let (Some(id), Some(name)) = (id, name) {
|
||||||
match db::badges::update_name(p, id, &name).await {
|
match db::badges::update_name(p, id, &name).await {
|
||||||
Ok(true) => {
|
Ok(true) => {
|
||||||
|
let payload = json!({"id": id, "name": name});
|
||||||
|
set_json_body(response, json!({"badge-update": payload}));
|
||||||
#[cfg(feature = "rtc")]
|
#[cfg(feature = "rtc")]
|
||||||
{
|
{
|
||||||
let payload = json!({"id": id, "name": name});
|
use crate::rtc;
|
||||||
set_json_body(response, json!({"badge-update": payload}));
|
if let Err(e) = rtc::notify("update-badge", payload).await {
|
||||||
|
eprintln!("[API-RTC] Unable to connect to RTC server {}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
@ -117,8 +135,14 @@ pub async fn update_name(p: &Pool, response: &mut Response<Body>, params: HashMa
|
|||||||
pub async fn delete(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
pub async fn delete(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
||||||
if let Some(id) = qs_param!(params, "badge_id", u64) {
|
if let Some(id) = qs_param!(params, "badge_id", u64) {
|
||||||
match db::badges::delete(p, id).await {
|
match db::badges::delete(p, id).await {
|
||||||
Ok(_id) => {
|
Ok(id) => {
|
||||||
// TODO: add rtc notification here
|
#[cfg(feature = "rtc")]
|
||||||
|
{
|
||||||
|
use crate::rtc;
|
||||||
|
if let Err(e) = rtc::notify("delete-badge", json!({"id": id})).await {
|
||||||
|
eprintln!("[API-RTC] Unable to connect to RTC server {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("[HTTP][ERROR] /badge/delete {}", e);
|
eprintln!("[HTTP][ERROR] /badge/delete {}", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user