36 lines
789 B
Rust
36 lines
789 B
Rust
|
use mongod::{
|
||
|
assert_reference_of,
|
||
|
derive::{Model, Referencable},
|
||
|
Referencable, Reference, Validate,
|
||
|
};
|
||
|
use serde::{Deserialize, Serialize};
|
||
|
|
||
|
use crate::library::{track::Track, user::User};
|
||
|
|
||
|
#[derive(Debug, Clone, Serialize, Deserialize, Model, Referencable)]
|
||
|
pub struct Playlist {
|
||
|
pub _id: String,
|
||
|
pub owner: Reference,
|
||
|
pub title: String,
|
||
|
pub visibility: Visibility,
|
||
|
pub tracks: Vec<Reference>,
|
||
|
}
|
||
|
|
||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||
|
pub enum Visibility {
|
||
|
Private,
|
||
|
Public,
|
||
|
}
|
||
|
|
||
|
impl Validate for Playlist {
|
||
|
async fn validate(&self) -> Result<(), String> {
|
||
|
assert_reference_of!(self.owner, User);
|
||
|
|
||
|
for track in &self.tracks {
|
||
|
assert_reference_of!(track, Track);
|
||
|
}
|
||
|
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|