Added the playlist generator
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
pub mod album;
|
||||
pub mod artist;
|
||||
pub mod download_queue;
|
||||
pub mod playlist;
|
||||
pub mod playlist_track;
|
||||
pub mod search_cache;
|
||||
pub mod track;
|
||||
pub mod user;
|
||||
@@ -9,6 +11,8 @@ pub mod wanted_item;
|
||||
pub use album::Entity as Albums;
|
||||
pub use artist::Entity as Artists;
|
||||
pub use download_queue::Entity as DownloadQueue;
|
||||
pub use playlist::Entity as Playlists;
|
||||
pub use playlist_track::Entity as PlaylistTracks;
|
||||
pub use search_cache::Entity as SearchCache;
|
||||
pub use track::Entity as Tracks;
|
||||
pub use user::Entity as Users;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "playlists")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
#[sea_orm(nullable)]
|
||||
pub description: Option<String>,
|
||||
#[sea_orm(nullable)]
|
||||
pub user_id: Option<i32>,
|
||||
pub created_at: chrono::NaiveDateTime,
|
||||
pub updated_at: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::user::Column::Id",
|
||||
on_delete = "SetNull"
|
||||
)]
|
||||
User,
|
||||
#[sea_orm(has_many = "super::playlist_track::Entity")]
|
||||
PlaylistTracks,
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::User.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::playlist_track::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::PlaylistTracks.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -0,0 +1,43 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "playlist_tracks")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub playlist_id: i32,
|
||||
pub track_id: i32,
|
||||
pub position: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::playlist::Entity",
|
||||
from = "Column::PlaylistId",
|
||||
to = "super::playlist::Column::Id",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Playlist,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::track::Entity",
|
||||
from = "Column::TrackId",
|
||||
to = "super::track::Column::Id"
|
||||
)]
|
||||
Track,
|
||||
}
|
||||
|
||||
impl Related<super::playlist::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Playlist.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::track::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Track.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Reference in New Issue
Block a user