Stash changes

This commit is contained in:
Joshua Coles 2024-03-02 09:14:27 +00:00
parent f08397ab15
commit ac049beff7
4 changed files with 23 additions and 5 deletions

3
.env
View File

@ -1 +1,4 @@
DATABASE_URL=postgres://postgres@localhost:5432/toggl_portal
TOGGL_API_TOKEN=237918c4e008f5aeefe886c9112ab560
TOGGL_WORKSPACE_ID=2837131
WORKSPACE_ID=${TOGGL_WORKSPACE_ID}

10
GRAFTING.md Normal file
View File

@ -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

View File

@ -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(),

View File

@ -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()