Initial commit
This commit is contained in:
94
src/entities/wanted_item.rs
Normal file
94
src/entities/wanted_item.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "Text")]
|
||||
pub enum WantedStatus {
|
||||
#[sea_orm(string_value = "wanted")]
|
||||
Wanted,
|
||||
#[sea_orm(string_value = "available")]
|
||||
Available,
|
||||
#[sea_orm(string_value = "downloaded")]
|
||||
Downloaded,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "Text")]
|
||||
pub enum ItemType {
|
||||
#[sea_orm(string_value = "artist")]
|
||||
Artist,
|
||||
#[sea_orm(string_value = "album")]
|
||||
Album,
|
||||
#[sea_orm(string_value = "track")]
|
||||
Track,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "wanted_items")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub item_type: ItemType,
|
||||
#[sea_orm(nullable)]
|
||||
pub artist_id: Option<i32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub album_id: Option<i32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub track_id: Option<i32>,
|
||||
pub status: WantedStatus,
|
||||
pub added_at: chrono::NaiveDateTime,
|
||||
pub updated_at: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::artist::Entity",
|
||||
from = "Column::ArtistId",
|
||||
to = "super::artist::Column::Id",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Artist,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::album::Entity",
|
||||
from = "Column::AlbumId",
|
||||
to = "super::album::Column::Id",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Album,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::track::Entity",
|
||||
from = "Column::TrackId",
|
||||
to = "super::track::Column::Id",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Track,
|
||||
#[sea_orm(has_many = "super::download_queue::Entity")]
|
||||
Downloads,
|
||||
}
|
||||
|
||||
impl Related<super::artist::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Artist.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::album::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Album.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::track::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Track.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::download_queue::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Downloads.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Reference in New Issue
Block a user