use migration::{Migrator, MigratorTrait};
use ui_rs::ui;
-use entity::usersettings;
-use entity::usersettings::Entity as UserSettings;
+use entity::profile;
+use entity::profile::Entity as UserSettings;
pub struct Backend {
rt: Arc<Runtime>,
db: DatabaseConnection,
- pub current_profile: Option<usersettings::Model>,
+ pub current_profile: Option<profile::Model>,
}
impl Backend {
profile_id: Option<i32>,
host: &str,
user: &str,
- ) -> Result<usersettings::Model, DbErr> {
+ ) -> Result<profile::Model, DbErr> {
let host = host.to_string();
let user = user.to_string();
- let profile: usersettings::Model = self.rt.block_on(async {
+ let profile: profile::Model = self.rt.block_on(async {
// If a profile id was specified, we are trying to use that,
// but if it doesn't exist, an error is returned
if let Some(id) = profile_id {
.one(&self.db)
.await?
{
- return Ok::<usersettings::Model, DbErr>(model);
+ return Ok::<profile::Model, DbErr>(model);
} else {
let err = format!("user settings {} not found", id);
- return Err::<usersettings::Model, DbErr>(DbErr::RecordNotFound(err));
+ return Err::<profile::Model, DbErr>(DbErr::RecordNotFound(err));
}
}
// Try to find a profile for the specified host/user
if let Some(model) = UserSettings::find()
- .filter(usersettings::Column::Host.eq(host.clone()))
- .filter(usersettings::Column::User.eq(user.clone()))
+ .filter(profile::Column::Host.eq(host.clone()))
+ .filter(profile::Column::User.eq(user.clone()))
.one(&self.db)
.await?
{
- return Ok::<usersettings::Model, DbErr>(model);
+ return Ok::<profile::Model, DbErr>(model);
}
// Create new profile
let profile_name = format!("{}/{}", host, user);
- let active = usersettings::ActiveModel {
+ let active = profile::ActiveModel {
host: Set(host),
user: Set(user),
profile: Set(profile_name),
- root_id: Set(0),
..Default::default()
};
let inserted = active.insert(&self.db).await?;
- Ok::<usersettings::Model, DbErr>(inserted)
+ Ok::<profile::Model, DbErr>(inserted)
})?;
Ok(profile)
let backend = match init_backend() {
Ok(backend) => backend,
Err(e) => {
- app_run_startup_error(e.title.as_str(), e.message.as_str());
+ ui::app_run_startup_error(e.title.as_str(), e.message.as_str());
return;
}
};
--- /dev/null
+use sea_orm::entity::prelude::*;
+
+#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
+#[sea_orm(table_name = "collection")]
+pub struct Model {
+ #[sea_orm(primary_key)]
+ pub collection_id: i32,
+ pub profile_id: i32,
+
+ pub name: String,
+ pub path: String,
+ pub icon: String,
+ pub kind: CollectionType,
+
+}
+
+#[derive(EnumIter, DeriveActiveEnum, Clone, Debug, PartialEq)]
+#[sea_orm(rs_type = "i32", db_type = "Integer")]
+pub enum CollectionType {
+ Notebook = 0,
+ Files = 1,
+ Feed = 2,
+ Mail = 3,
+}
+
+#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+pub enum Relation {}
+
+impl ActiveModelBehavior for ActiveModel {}
-pub mod usersettings;
-mod prelude;
\ No newline at end of file
+mod prelude;
+pub mod profile;
+pub mod collection;
\ No newline at end of file
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
-#[sea_orm(table_name = "user_settings")]
+#[sea_orm(table_name = "profile")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub host: String,
pub user: String,
pub profile: String,
-
- pub root_id: i32
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
manager
.create_table(
Table::create()
- .table("user_settings")
+ .table("profile")
.if_not_exists()
.col(pk_auto("id"))
.col(string("host"))
.col(string("user"))
.col(string("profile"))
- .col(integer("root_id"))
+ .to_owned(),
+ )
+ .await?;
+
+ manager
+ .create_table(
+ Table::create()
+ .table("collection")
+ .if_not_exists()
+ .col(pk_auto("collection_id"))
+ .col(integer("profile_id"))
+ .col(string("name"))
+ .col(string("path"))
+ .col(string("icon"))
+ .col(integer("kind"))
+ .foreign_key(
+ ForeignKey::create()
+ .name("fk-collection-profile")
+ .from("collection", "profile_id")
+ .to("Profile", "id")
+ .on_delete(ForeignKeyAction::Cascade)
+ .on_update(ForeignKeyAction::Cascade))
.to_owned(),
)
.await
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
- .drop_table(Table::drop().table("user_settings").to_owned())
+ .drop_table(Table::drop().table("collection").to_owned()).await?;
+ manager
+ .drop_table(Table::drop().table("profile").to_owned())
.await
}
}
pub struct NoAppData {}
impl UiModel for NoAppData {
- fn init(&mut self, ctx: &UiContext) {}
+ fn init(&mut self, _ctx: &UiContext) {}
}
impl UiActions for NoAppData {
}
impl<'a> Application<NoAppData> for ErrApp<'a> {
- fn on_startup(&mut self, app: &AppContext<NoAppData>) {
+ fn on_startup(&mut self, _app: &AppContext<NoAppData>) {
dialog(|d| {
d.title(self.title);
d.content(self.message);