playlists
This commit is contained in:
parent
bd8d0b407e
commit
7e6b65392e
7 changed files with 122 additions and 4 deletions
34
src/route/event.rs
Normal file
34
src/route/event.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
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}))
|
||||
}
|
|
@ -8,6 +8,7 @@ use serde_json::json;
|
|||
pub mod admin;
|
||||
pub mod album;
|
||||
pub mod artist;
|
||||
pub mod event;
|
||||
pub mod playlist;
|
||||
pub mod track;
|
||||
pub mod user;
|
||||
|
|
|
@ -87,7 +87,8 @@ pub async fn playlist_route(id: &str, u: User) -> FallibleApiResponse {
|
|||
#[get("/playlist/<id>/tracks")]
|
||||
pub async fn playlist_tracks_route(id: &str, u: User) -> FallibleApiResponse {
|
||||
if id == "recents" {
|
||||
// todo : recently played
|
||||
let tracks = Track::get_latest_of_user(&u).await;
|
||||
return Ok(json!(to_api(&tracks).await));
|
||||
}
|
||||
|
||||
if id == "recentlyAdded" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue