playlists
This commit is contained in:
parent
74b32003d0
commit
428aa6e066
5 changed files with 59 additions and 3 deletions
|
@ -5,7 +5,7 @@ use mongod::{
|
|||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::library::{track::Track, user::User};
|
||||
use crate::{library::{track::Track, user::User}, route::ToAPI};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Model, Referencable)]
|
||||
pub struct Playlist {
|
||||
|
@ -33,3 +33,14 @@ impl Validate for Playlist {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAPI for Playlist {
|
||||
async fn api(&self) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"id": self._id,
|
||||
"owner": self.owner.id(),
|
||||
"title": self.title,
|
||||
"tracks": self.tracks.iter().map(|x| x.id()).collect::<Vec<_>>()
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue