use super::api_error; use super::to_uuid; use super::FallibleApiResponse; use rocket::post; use rocket::serde::json::Json; use serde::Deserialize; use serde_json::json; use crate::library::event::Event; use crate::library::event::EventKind; use crate::library::track::Track; use crate::library::user::User; #[derive(Debug, Clone, Deserialize)] pub struct EventJson { pub kind: EventKind, pub track: String, } #[post("/report", data = "")] pub async fn event_report_route(report: Json, u: User) -> FallibleApiResponse { let track = &report.track; Event::create( report.kind.clone(), &u, Track::get(&to_uuid(&track)?) .await .ok_or_else(|| api_error("Invalid track"))? .id, ) .await; Ok(json!({"ok": 1})) }