Added auth
This commit is contained in:
@@ -3,6 +3,7 @@ pub mod artist;
|
||||
pub mod download_queue;
|
||||
pub mod search_cache;
|
||||
pub mod track;
|
||||
pub mod user;
|
||||
pub mod wanted_item;
|
||||
|
||||
pub use album::Entity as Albums;
|
||||
@@ -10,4 +11,5 @@ pub use artist::Entity as Artists;
|
||||
pub use download_queue::Entity as DownloadQueue;
|
||||
pub use search_cache::Entity as SearchCache;
|
||||
pub use track::Entity as Tracks;
|
||||
pub use user::Entity as Users;
|
||||
pub use wanted_item::Entity as WantedItems;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
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 UserRole {
|
||||
#[sea_orm(string_value = "admin")]
|
||||
Admin,
|
||||
#[sea_orm(string_value = "user")]
|
||||
User,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "users")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
#[sea_orm(unique)]
|
||||
pub username: String,
|
||||
#[serde(skip_serializing)]
|
||||
pub password_hash: String,
|
||||
pub role: UserRole,
|
||||
pub created_at: chrono::NaiveDateTime,
|
||||
pub updated_at: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::wanted_item::Entity")]
|
||||
WantedItems,
|
||||
}
|
||||
|
||||
impl Related<super::wanted_item::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::WantedItems.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -37,6 +37,8 @@ pub struct Model {
|
||||
pub album_id: Option<i32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub track_id: Option<i32>,
|
||||
#[sea_orm(nullable)]
|
||||
pub user_id: Option<i32>,
|
||||
pub name: String,
|
||||
#[sea_orm(nullable)]
|
||||
pub musicbrainz_id: Option<String>,
|
||||
@@ -47,6 +49,13 @@ pub struct Model {
|
||||
|
||||
#[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 = "Cascade"
|
||||
)]
|
||||
User,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::artist::Entity",
|
||||
from = "Column::ArtistId",
|
||||
@@ -72,6 +81,12 @@ pub enum Relation {
|
||||
Downloads,
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::User.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::artist::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Artist.def()
|
||||
|
||||
Reference in New Issue
Block a user