35 lines
841 B
Rust
35 lines
841 B
Rust
|
use super::api_error;
|
||
|
use super::FallibleApiResponse;
|
||
|
use mongod::reference_of;
|
||
|
use mongod::Model;
|
||
|
use mongodb::bson::doc;
|
||
|
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;
|
||
|
use mongod::Referencable;
|
||
|
|
||
|
#[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,
|
||
|
reference_of!(Track, track).ok_or_else(|| api_error("Invalid track"))?,
|
||
|
)
|
||
|
.await;
|
||
|
|
||
|
Ok(json!({"ok": 1}))
|
||
|
}
|