diff --git a/.env b/.env index e733ce7..2c713ad 100644 --- a/.env +++ b/.env @@ -1 +1,4 @@ DATABASE_URL=postgres://postgres@localhost:5432/toggl_portal +TOGGL_API_TOKEN=237918c4e008f5aeefe886c9112ab560 +TOGGL_WORKSPACE_ID=2837131 +WORKSPACE_ID=${TOGGL_WORKSPACE_ID} diff --git a/GRAFTING.md b/GRAFTING.md new file mode 100644 index 0000000..2fd38b2 --- /dev/null +++ b/GRAFTING.md @@ -0,0 +1,10 @@ +- Possible sources + - report + - me/time_enries + - This will need to filter by `workspace_id` if don't want to deal with multiple workspaces. + - csv + - This can give us a complete picture of the time entries, but it lacks an `id` field so cannot be easily updated +- The first two contain `at` which is when the time entry was last updated, useful for grafting +- `me/time_entries` can get anything **updated** since a given time + - This is incredibly useful for updating the time entries +- Most historic time entries are not ever changed so a csv of say, 2023 is probably alwasy going to be valid diff --git a/src/main.rs b/src/main.rs index c468dcd..558a20d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,6 @@ use axum::http::StatusCode; use axum::response::IntoResponse; use axum::routing::{get, post}; use axum::{Extension, Json, Router}; -use base64::engine::general_purpose::STANDARD; -use base64::Engine; use utils::{shutdown_signal, Result}; use chrono::{NaiveDate, NaiveTime}; use clap::Parser; @@ -229,14 +227,16 @@ async fn main() -> Result<()> { let config = Config::parse(); let toggl_client = TogglApiClient::new( &config.workspace_id.to_string(), - &STANDARD.encode(&format!("{}:api_token", config.toggl_api_token)), + &config.toggl_api_token, ); let db = sea_orm::Database::connect(config.database_url) .await .unwrap(); - Migrator::up(&db, None).await.expect("Failed to migrate"); + Migrator::up(&db, None) + .await + .expect("Failed to migrate"); tokio::spawn(poll::poll_job( toggl_client.clone(), diff --git a/src/toggl_api/api_client.rs b/src/toggl_api/api_client.rs index 07b8b75..309557f 100644 --- a/src/toggl_api/api_client.rs +++ b/src/toggl_api/api_client.rs @@ -2,7 +2,10 @@ use reqwest::Client; use serde_json::Value; use std::collections::HashMap; use std::time::Duration; +use base64::Engine; +use base64::engine::general_purpose::STANDARD; use hyper::HeaderMap; +use migration::cli::Cli; use tracing::instrument; use tracing::log::debug; use crate::toggl_api::types::{Current, Project, ProjectClient, ReportEntry, TogglQuery}; @@ -22,7 +25,9 @@ impl TogglApiClient { true } - pub fn new(workspace_id: &str, toggl_auth: &str) -> Self { + pub fn new(workspace_id: &str, api_token: &str) -> Self { + let toggl_auth = &STANDARD.encode(&format!("{}:api_token", api_token)); + let client = Client::builder() .default_headers(Self::default_headers(toggl_auth)) .build()