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, #[sea_orm(nullable)] pub album_id: Option, #[sea_orm(nullable)] pub track_id: Option, 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 for Entity { fn to() -> RelationDef { Relation::Artist.def() } } impl Related for Entity { fn to() -> RelationDef { Relation::Album.def() } } impl Related for Entity { fn to() -> RelationDef { Relation::Track.def() } } impl Related for Entity { fn to() -> RelationDef { Relation::Downloads.def() } } impl ActiveModelBehavior for ActiveModel {}