a
This commit is contained in:
parent
4933079276
commit
883cda2bee
6 changed files with 150 additions and 7 deletions
67
core/migration/src/m20230001_000001_create_mail_account.rs
Normal file
67
core/migration/src/m20230001_000001_create_mail_account.rs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.create_table(
|
||||||
|
Table::create()
|
||||||
|
.table(MailAccount::Table)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(MailAccount::Id)
|
||||||
|
.integer()
|
||||||
|
.not_null()
|
||||||
|
.auto_increment()
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(MailAccount::Email).string().not_null())
|
||||||
|
.col(ColumnDef::new(MailAccount::DisplayName).string().not_null())
|
||||||
|
.col(ColumnDef::new(MailAccount::ImapHost).string().not_null())
|
||||||
|
.col(ColumnDef::new(MailAccount::ImapPort).integer().not_null())
|
||||||
|
.col(ColumnDef::new(MailAccount::SmtpHost).string().not_null())
|
||||||
|
.col(ColumnDef::new(MailAccount::SmtpPort).integer().not_null())
|
||||||
|
.col(ColumnDef::new(MailAccount::Username).string().not_null())
|
||||||
|
.col(ColumnDef::new(MailAccount::Password).string().not_null())
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(MailAccount::CreatedAt)
|
||||||
|
.timestamp_with_time_zone()
|
||||||
|
.not_null()
|
||||||
|
.default(Expr::current_timestamp()),
|
||||||
|
)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(MailAccount::UpdatedAt)
|
||||||
|
.timestamp_with_time_zone()
|
||||||
|
.not_null()
|
||||||
|
.default(Expr::current_timestamp()),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(MailAccount::Table).to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum MailAccount {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
Email,
|
||||||
|
DisplayName,
|
||||||
|
ImapHost,
|
||||||
|
ImapPort,
|
||||||
|
SmtpHost,
|
||||||
|
SmtpPort,
|
||||||
|
Username,
|
||||||
|
Password,
|
||||||
|
CreatedAt,
|
||||||
|
UpdatedAt,
|
||||||
|
}
|
|
@ -1,15 +1,61 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
pub struct PanoramaDatabase(SqlitePool);
|
use crate::entity::mail_account;
|
||||||
|
use sea_orm::{DatabaseConnection, EntityTrait};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct EnsureMailAccount {
|
#[derive(Default)]
|
||||||
imap_server_host: String,
|
pub struct MailAccountOptions {
|
||||||
imap_server_port: u16,
|
pub id: Option<Uuid>,
|
||||||
|
pub email: Option<String>,
|
||||||
|
pub display_name: Option<String>,
|
||||||
|
pub imap_host: Option<String>,
|
||||||
|
pub imap_port: Option<i32>,
|
||||||
|
pub smtp_host: Option<String>,
|
||||||
|
pub smtp_port: Option<i32>,
|
||||||
|
pub username: Option<String>,
|
||||||
|
pub password: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PanoramaDatabase {
|
||||||
|
connection: DatabaseConnection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PanoramaDatabase {
|
impl PanoramaDatabase {
|
||||||
pub async fn ensure_mail_account(&self) -> Result<()> {
|
pub async fn new(connection: DatabaseConnection) -> Self {
|
||||||
Ok(())
|
Self { connection }
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn ensure_mail_account(
|
||||||
|
&self,
|
||||||
|
options: MailAccountOptions,
|
||||||
|
) -> Result<mail_account::Model, sea_orm::DbErr> {
|
||||||
|
let account = mail_account::ActiveModel {
|
||||||
|
id: Set(options.id.unwrap_or_else(Uuid::new_v4)),
|
||||||
|
email: Set(options.email.unwrap_or_default()),
|
||||||
|
display_name: Set(options.display_name.unwrap_or_default()),
|
||||||
|
imap_host: Set(options.imap_host.unwrap_or_default()),
|
||||||
|
imap_port: Set(options.imap_port.unwrap_or(993)),
|
||||||
|
smtp_host: Set(options.smtp_host.unwrap_or_default()),
|
||||||
|
smtp_port: Set(options.smtp_port.unwrap_or(587)),
|
||||||
|
username: Set(options.username.unwrap_or_default()),
|
||||||
|
password: Set(options.password.unwrap_or_default()),
|
||||||
|
};
|
||||||
|
|
||||||
|
mail_account::Entity::insert(account).exec(&self.connection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub struct PanoramaDatabase(SqlitePool);
|
||||||
|
|
||||||
|
// pub struct EnsureMailAccount {
|
||||||
|
// imap_server_host: String,
|
||||||
|
// imap_server_port: u16,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// impl PanoramaDatabase {
|
||||||
|
// pub async fn ensure_mail_account(&self) -> Result<()> {
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
23
core/src/entity/mail_account.rs
Normal file
23
core/src/entity/mail_account.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "mail_accounts")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub id: i32,
|
||||||
|
pub email: String,
|
||||||
|
pub display_name: String,
|
||||||
|
pub imap_host: String,
|
||||||
|
pub imap_port: i32,
|
||||||
|
pub smtp_host: String,
|
||||||
|
pub smtp_port: i32,
|
||||||
|
pub username: String,
|
||||||
|
pub password: String, // Note: In production, consider encryption
|
||||||
|
pub created_at: DateTimeWithTimeZone,
|
||||||
|
pub updated_at: DateTimeWithTimeZone,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
0
core/src/entity/mod.rs
Normal file
0
core/src/entity/mod.rs
Normal file
|
@ -1,4 +1,5 @@
|
||||||
use tonic::{Request, Response, Result};
|
use tonic::{Request, Response, Result};
|
||||||
|
use sea_orm::DatabaseConnection;
|
||||||
|
|
||||||
use crate::dal::PanoramaDatabase;
|
use crate::dal::PanoramaDatabase;
|
||||||
use crate::server_proto::panorama_server::Panorama as PanoramaServerProto;
|
use crate::server_proto::panorama_server::Panorama as PanoramaServerProto;
|
||||||
|
@ -8,7 +9,13 @@ pub struct Panorama {
|
||||||
db: PanoramaDatabase,
|
db: PanoramaDatabase,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Panorama {}
|
impl Panorama {
|
||||||
|
pub async fn new(connection: DatabaseConnection) -> Self {
|
||||||
|
Self {
|
||||||
|
db: PanoramaDatabase::new(connection).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tonic::async_trait]
|
#[tonic::async_trait]
|
||||||
impl PanoramaServerProto for Panorama {
|
impl PanoramaServerProto for Panorama {
|
||||||
|
|
0
src/components/HorizontalPanels/HorizontalPanels.tsx
Normal file
0
src/components/HorizontalPanels/HorizontalPanels.tsx
Normal file
Loading…
Reference in a new issue