Simple notification http server

actually post notifications

vielle.dev 22820805 15123db0

verified
Changed files
+12 -4
src
+12 -4
src/main.rs
··· 1 1 use actix_web::{App, HttpResponse, HttpServer, Responder, post, web}; 2 + use notify_rust::Notification; 2 3 use serde::Deserialize; 3 4 4 5 #[derive(Deserialize)] ··· 9 10 10 11 #[post("/notify")] 11 12 async fn notify(notification: web::Form<NotificationData>) -> impl Responder { 12 - HttpResponse::InternalServerError().body(format!( 13 - "TODO: implement ({}: {})", 14 - notification.name, notification.body 15 - )) 13 + let notification = Notification::new() 14 + .summary(&notification.name) 15 + .body(&notification.body) 16 + .timeout(0) 17 + .show(); 18 + 19 + match notification { 20 + Ok(_) => HttpResponse::Ok().body("{\"status\": \"ok\"}"), 21 + Err(err) => HttpResponse::InternalServerError() 22 + .body(format!("{{\"status\": \"err\", \"err\": \"{}\"}}", err)), 23 + } 16 24 } 17 25 18 26 #[actix_web::main]