This commit is contained in:
pavel 2026-02-13 17:45:29 +01:00
commit c7a592933e
32 changed files with 7871 additions and 0 deletions

32
src/entity/channels.rs Normal file
View file

@ -0,0 +1,32 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "channels")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: Uuid,
pub guild_id: Uuid,
pub name: String,
pub kind: String,
pub created_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::guilds::Entity",
from = "Column::GuildId",
to = "super::guilds::Column::Id"
)]
Guilds,
#[sea_orm(has_many = "super::messages::Entity")]
Messages,
}
impl Related<super::guilds::Entity> for Entity {
fn to() -> RelationDef {
Relation::Guilds.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,31 @@
use sea_orm::entity::prelude::*;
use uuid::Uuid;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "direct_messages")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub sender_user_id: Uuid,
pub recipient_user_id: Uuid,
pub body: String,
pub created_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::SenderUserId",
to = "super::users::Column::Id"
)]
SenderUser,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::RecipientUserId",
to = "super::users::Column::Id"
)]
RecipientUser,
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,41 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "guild_members")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub guild_id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: Uuid,
pub created_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::guilds::Entity",
from = "Column::GuildId",
to = "super::guilds::Column::Id"
)]
Guilds,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id"
)]
Users,
}
impl Related<super::guilds::Entity> for Entity {
fn to() -> RelationDef {
Relation::Guilds.def()
}
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

31
src/entity/guilds.rs Normal file
View file

@ -0,0 +1,31 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "guilds")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: Uuid,
pub name: String,
pub owner_user_id: Uuid,
pub created_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::OwnerUserId",
to = "super::users::Column::Id"
)]
Users,
#[sea_orm(has_many = "super::channels::Entity")]
Channels,
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

44
src/entity/invites.rs Normal file
View file

@ -0,0 +1,44 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "invites")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub code: String,
pub guild_id: Uuid,
pub created_by_user_id: Uuid,
pub created_at: DateTimeWithTimeZone,
pub expires_at: Option<DateTimeWithTimeZone>,
pub max_uses: Option<i32>,
pub use_count: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::guilds::Entity",
from = "Column::GuildId",
to = "super::guilds::Column::Id"
)]
Guilds,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::CreatedByUserId",
to = "super::users::Column::Id"
)]
Users,
}
impl Related<super::guilds::Entity> for Entity {
fn to() -> RelationDef {
Relation::Guilds.def()
}
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

42
src/entity/messages.rs Normal file
View file

@ -0,0 +1,42 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "messages")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: Uuid,
pub channel_id: Uuid,
pub author_user_id: Uuid,
pub body: String,
pub created_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::channels::Entity",
from = "Column::ChannelId",
to = "super::channels::Column::Id"
)]
Channels,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::AuthorUserId",
to = "super::users::Column::Id"
)]
Users,
}
impl Related<super::channels::Entity> for Entity {
fn to() -> RelationDef {
Relation::Channels.def()
}
}
impl Related<super::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

7
src/entity/mod.rs Normal file
View file

@ -0,0 +1,7 @@
pub mod channels;
pub mod direct_messages;
pub mod guild_members;
pub mod guilds;
pub mod invites;
pub mod messages;
pub mod users;

30
src/entity/users.rs Normal file
View file

@ -0,0 +1,30 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: Uuid,
pub oidc_sub: String,
pub email: Option<String>,
pub display_name: String,
pub avatar_url: Option<String>,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::guilds::Entity")]
Guilds,
#[sea_orm(has_many = "super::messages::Entity")]
Messages,
}
impl Related<super::guilds::Entity> for Entity {
fn to() -> RelationDef {
Relation::Guilds.def()
}
}
impl ActiveModelBehavior for ActiveModel {}