diff --git a/Cargo.lock b/Cargo.lock index 7cb62b6..a196382 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2273,6 +2273,18 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "importer" +version = "0.1.0" +dependencies = [ + "orm", + "serde", + "serde_json", + "services", + "tokio", + "types", +] + [[package]] name = "indenter" version = "0.3.4" diff --git a/Cargo.toml b/Cargo.toml index 09032c3..429dcb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "3" -members = ["api", "api/migration", "api/services", "api/orm","libs/client", "libs/types","rpi-checker"] +members = ["api", "api/importer", "api/migration", "api/services", "api/orm","libs/client", "libs/types","rpi-checker"] diff --git a/README.md b/README.md index ab5fa3e..7ff4a98 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ BETTER_AUTH_URL=http://localhost:3000 NUXT_PUBLIC_WEBPUSH_PUBLIC_KEY= -#APi +#Api API_WEBPUSH_PRIVATE_KEY= ``` diff --git a/api/importer/.gitignore b/api/importer/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/api/importer/.gitignore @@ -0,0 +1 @@ +/target diff --git a/api/importer/Cargo.toml b/api/importer/Cargo.toml new file mode 100644 index 0000000..2ec6666 --- /dev/null +++ b/api/importer/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "importer" +version = "0.1.0" +edition = "2024" + +[dependencies] +types = { path = "../../libs/types" } +orm = { path = "../orm" } +services = { path = "../services" } + +tokio = { version = "1.52.1", features = ["fs", "macros", "rt-multi-thread", "signal"] } +serde = { version = "1.0.228", features = ["derive"] } +serde_json = "1.0.149" diff --git a/api/importer/data/categories.json b/api/importer/data/categories.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/api/importer/data/categories.json @@ -0,0 +1 @@ +[] diff --git a/api/importer/data/tags.json b/api/importer/data/tags.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/api/importer/data/tags.json @@ -0,0 +1 @@ +[] diff --git a/api/importer/data/todos.json b/api/importer/data/todos.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/api/importer/data/todos.json @@ -0,0 +1 @@ +[] diff --git a/api/importer/src/main.rs b/api/importer/src/main.rs new file mode 100644 index 0000000..0d2cb29 --- /dev/null +++ b/api/importer/src/main.rs @@ -0,0 +1,44 @@ +use orm::init_db; +use services::{User, categories::CategoryService, tags::TagService, todos::TodoService}; +use tokio::fs::read_to_string; +use types::{Category, Tag, Todo}; + +#[tokio::main] +async fn main() { + let user = User { + id: "id".to_string(), + }; + + let db = init_db("sqlite://../../.data/storage.sqlite?mode=rwc") + .await + .unwrap(); + + let tags: Vec = + serde_json::from_str(&read_to_string("./data/tags.json").await.unwrap()).unwrap(); + + let categories: Vec = + serde_json::from_str(&read_to_string("./data/categories.json").await.unwrap()).unwrap(); + + let todos: Vec = + serde_json::from_str(&read_to_string("./data/todos.json").await.unwrap()).unwrap(); + + for tag in tags { + TagService::create(&user, &db, tag).await.unwrap(); + } + + for category in categories { + CategoryService::create(&user, &db, category).await.unwrap(); + } + + for todo in todos { + TodoService::create( + &user, + &db, + todo, + services::todos::TodoPosition::Bottom, + None, + ) + .await + .unwrap(); + } +}