Simple notification http server

actually post notifications

vielle.dev 22820805 15123db0

verified
Changed files
+12 -4
src
+12 -4
src/main.rs
··· 1 use actix_web::{App, HttpResponse, HttpServer, Responder, post, web}; 2 use serde::Deserialize; 3 4 #[derive(Deserialize)] ··· 9 10 #[post("/notify")] 11 async fn notify(notification: web::Form<NotificationData>) -> impl Responder { 12 - HttpResponse::InternalServerError().body(format!( 13 - "TODO: implement ({}: {})", 14 - notification.name, notification.body 15 - )) 16 } 17 18 #[actix_web::main]
··· 1 use actix_web::{App, HttpResponse, HttpServer, Responder, post, web}; 2 + use notify_rust::Notification; 3 use serde::Deserialize; 4 5 #[derive(Deserialize)] ··· 10 11 #[post("/notify")] 12 async fn notify(notification: web::Form<NotificationData>) -> impl Responder { 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 + } 24 } 25 26 #[actix_web::main]