fix: renew entity models

This commit is contained in:
Namekuji 2023-07-10 02:17:06 -04:00
parent 61f0f52d42
commit 4d36c7f4ed
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
7 changed files with 11 additions and 27 deletions

View file

@ -8,7 +8,6 @@ pub mod ad;
pub mod announcement;
pub mod announcement_read;
pub mod antenna;
pub mod antenna_note;
pub mod app;
pub mod attestation_challenge;
pub mod auth_session;

View file

@ -15,6 +15,10 @@ pub struct Model {
pub image_url: Option<String>,
#[sea_orm(column_name = "updatedAt")]
pub updated_at: Option<DateTimeWithTimeZone>,
#[sea_orm(column_name = "showPopup")]
pub show_popup: bool,
#[sea_orm(column_name = "isGoodNews")]
pub is_good_news: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View file

@ -37,8 +37,6 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::antenna_note::Entity")]
AntennaNote,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
@ -65,12 +63,6 @@ pub enum Relation {
UserList,
}
impl Related<super::antenna_note::Entity> for Entity {
fn to() -> RelationDef {
Relation::AntennaNote.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()

View file

@ -189,6 +189,10 @@ pub struct Model {
pub silenced_hosts: StringVec,
#[sea_orm(column_name = "experimentalFeatures", column_type = "JsonBinary")]
pub experimental_features: Json,
#[sea_orm(column_name = "enableServerMachineStats")]
pub enable_server_machine_stats: bool,
#[sea_orm(column_name = "enableIdenticonGeneration")]
pub enable_identicon_generation: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View file

@ -67,8 +67,6 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::antenna_note::Entity")]
AntennaNote,
#[sea_orm(
belongs_to = "super::channel::Entity",
from = "Column::ChannelId",
@ -131,12 +129,6 @@ pub enum Relation {
UserNotePining,
}
impl Related<super::antenna_note::Entity> for Entity {
fn to() -> RelationDef {
Relation::AntennaNote.def()
}
}
impl Related<super::channel::Entity> for Entity {
fn to() -> RelationDef {
Relation::Channel.def()

View file

@ -6,7 +6,6 @@ pub use super::ad::Entity as Ad;
pub use super::announcement::Entity as Announcement;
pub use super::announcement_read::Entity as AnnouncementRead;
pub use super::antenna::Entity as Antenna;
pub use super::antenna_note::Entity as AntennaNote;
pub use super::app::Entity as App;
pub use super::attestation_challenge::Entity as AttestationChallenge;
pub use super::auth_session::Entity as AuthSession;

View file

@ -1,9 +1,9 @@
use async_trait::async_trait;
use cfg_if::cfg_if;
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
use sea_orm::EntityTrait;
use crate::database;
use crate::model::entity::{antenna, antenna_note, user_group_joining};
use crate::model::entity::{antenna, user_group_joining};
use crate::model::error::Error;
use crate::model::schema::Antenna;
@ -14,12 +14,6 @@ use super::Repository;
impl Repository<Antenna> for antenna::Model {
async fn pack(self) -> Result<Antenna, Error> {
let db = database::get_database()?;
let has_unread_note = antenna_note::Entity::find()
.filter(antenna_note::Column::AntennaId.eq(self.id.to_owned()))
.filter(antenna_note::Column::Read.eq(false))
.one(db)
.await?
.is_some();
let user_group_joining = match self.user_group_joining_id {
None => None,
Some(id) => user_group_joining::Entity::find_by_id(id).one(db).await?,
@ -52,7 +46,7 @@ impl Repository<Antenna> for antenna::Model {
notify: self.notify,
with_replies: self.with_replies,
with_file: self.with_file,
has_unread_note,
has_unread_note: false,
})
}