synthwave/src/route/event.rs

35 lines
816 B
Rust
Raw Normal View History

2024-08-16 23:25:41 +00:00
use super::api_error;
2024-10-04 12:38:35 +00:00
use super::to_uuid;
2024-08-16 23:25:41 +00:00
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 = "<report>")]
pub async fn event_report_route(report: Json<EventJson>, u: User) -> FallibleApiResponse {
let track = &report.track;
Event::create(
report.kind.clone(),
&u,
2024-10-04 12:38:35 +00:00
Track::get(&to_uuid(&track)?)
.await
.ok_or_else(|| api_error("Invalid track"))?
.id,
2024-08-16 23:25:41 +00:00
)
.await;
Ok(json!({"ok": 1}))
}