]> uap-core.de Git - note.git/commitdiff
add collection entity main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 10 May 2026 11:12:32 +0000 (13:12 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 10 May 2026 11:12:32 +0000 (13:12 +0200)
application/src/backend.rs
application/src/main.rs
entity/src/collection.rs [new file with mode: 0644]
entity/src/lib.rs
entity/src/profile.rs [moved from entity/src/usersettings.rs with 84% similarity]
migration/src/m20260502_184134_create_settings.rs
ui-rs/src/ui/application.rs

index fa8c4d8a478e76f96754df0d6b515a09031aeadd..7691741cd4ec3fdc07da86266bfbe97c6cfa1b84 100644 (file)
@@ -4,14 +4,14 @@ use std::sync::{Arc};
 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 {
@@ -50,12 +50,12 @@ 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 {
@@ -63,37 +63,36 @@ impl Backend {
                     .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)
index 537c18deae3eb9e40e22bc1ac878ccd622cb455e..c055206864af55ddcb06dfd7ed0669f9aae266e3 100644 (file)
@@ -41,7 +41,7 @@ fn main() {
     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;
         }
     };
diff --git a/entity/src/collection.rs b/entity/src/collection.rs
new file mode 100644 (file)
index 0000000..ecc0c1a
--- /dev/null
@@ -0,0 +1,29 @@
+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 {}
index 082e97c0dde47049dcf0c06338274ad2ed8a900d..8a998bb6cc62b8fe80e51ffa88315e184b3539b1 100644 (file)
@@ -1,2 +1,3 @@
-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
similarity index 84%
rename from entity/src/usersettings.rs
rename to entity/src/profile.rs
index ec1aba70215ca87e72e68fb6b97ea9b5f59a3e7b..660ebc2af9f496a594b9611d467bb0a599ee808c 100644 (file)
@@ -1,7 +1,7 @@
 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,
@@ -9,8 +9,6 @@ pub struct Model {
     pub host: String,
     pub user: String,
     pub profile: String,
-
-    pub root_id: i32
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
index 442746bd8c2162ae514c54a40cc4018b7b146e03..5f66a189bc674afef76f10f1216e228a26e120f7 100644 (file)
@@ -9,13 +9,34 @@ impl MigrationTrait for Migration {
         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
@@ -23,7 +44,9 @@ impl MigrationTrait for Migration {
 
     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
     }
 }
index af70f6500d368acf43518b0a74c8fc7a43975bce..fea2cbaf09c337b6706f4ad12c20381a4bd9cb93 100644 (file)
@@ -48,7 +48,7 @@ pub struct AppContext<T: UiModel + UiActions> {
 pub struct NoAppData {}
 
 impl UiModel for NoAppData {
-    fn init(&mut self, ctx: &UiContext) {}
+    fn init(&mut self, _ctx: &UiContext) {}
 }
 
 impl UiActions for NoAppData {
@@ -108,7 +108,7 @@ struct ErrApp<'a> {
 }
 
 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);