Add a bunch of debugging
This commit is contained in:
parent
5d9184df32
commit
bc95081399
11
src/main.rs
11
src/main.rs
@ -18,6 +18,7 @@ use std::net::SocketAddr;
|
|||||||
use axum::extract::Query;
|
use axum::extract::Query;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
|
use tracing::{debug, instrument};
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
mod db;
|
mod db;
|
||||||
@ -44,17 +45,21 @@ struct Config {
|
|||||||
poll_period: u64,
|
poll_period: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(db, toggl_client))]
|
||||||
pub async fn report(
|
pub async fn report(
|
||||||
Extension(toggl_client): Extension<TogglClient>,
|
Extension(toggl_client): Extension<TogglClient>,
|
||||||
Extension(db): Extension<DatabaseConnection>,
|
Extension(db): Extension<DatabaseConnection>,
|
||||||
Json(query): Json<TogglQuery>,
|
Json(query): Json<TogglQuery>,
|
||||||
) -> Result<Json<Vec<ReportEntry>>> {
|
) -> Result<Json<Vec<ReportEntry>>> {
|
||||||
let report = toggl_client.full_report(&query).await?;
|
let report = toggl_client.full_report(&query).await?;
|
||||||
|
debug!("Returned results: {:?}", report);
|
||||||
|
|
||||||
cache_report(&db, &report).await?;
|
cache_report(&db, &report).await?;
|
||||||
|
|
||||||
Ok(Json(report))
|
Ok(Json(report))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip_all)]
|
||||||
async fn cache_report(db: &DatabaseConnection, models: &Vec<ReportEntry>) -> Result<()> {
|
async fn cache_report(db: &DatabaseConnection, models: &Vec<ReportEntry>) -> Result<()> {
|
||||||
let models = models.iter().flat_map(|entry| entry.as_models());
|
let models = models.iter().flat_map(|entry| entry.as_models());
|
||||||
let models = models.collect::<Vec<_>>();
|
let models = models.collect::<Vec<_>>();
|
||||||
@ -69,15 +74,18 @@ async fn cache_report(db: &DatabaseConnection, models: &Vec<ReportEntry>) -> Res
|
|||||||
.on_conflict(ReportEntry::grafting_conflict_statement())
|
.on_conflict(ReportEntry::grafting_conflict_statement())
|
||||||
.exec(db)
|
.exec(db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(toggl_client))]
|
||||||
pub async fn current(
|
pub async fn current(
|
||||||
Extension(toggl_client): Extension<TogglClient>,
|
Extension(toggl_client): Extension<TogglClient>,
|
||||||
) -> Result<Json<Option<Current>>> {
|
) -> Result<Json<Option<Current>>> {
|
||||||
Ok(toggl_client.get_current().await.map(Json)?)
|
Ok(toggl_client.get_current().await.map(Json)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(toggl_client))]
|
||||||
pub async fn start_time_entry(
|
pub async fn start_time_entry(
|
||||||
Extension(toggl_client): Extension<TogglClient>,
|
Extension(toggl_client): Extension<TogglClient>,
|
||||||
Json(body): Json<HashMap<String, Value>>,
|
Json(body): Json<HashMap<String, Value>>,
|
||||||
@ -87,6 +95,7 @@ pub async fn start_time_entry(
|
|||||||
Ok((StatusCode::OK, "Ok"))
|
Ok((StatusCode::OK, "Ok"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(db, toggl_client))]
|
||||||
async fn projects(
|
async fn projects(
|
||||||
Extension(db): Extension<DatabaseConnection>,
|
Extension(db): Extension<DatabaseConnection>,
|
||||||
Extension(toggl_client): Extension<TogglClient>,
|
Extension(toggl_client): Extension<TogglClient>,
|
||||||
@ -101,6 +110,7 @@ async fn projects(
|
|||||||
Ok(Json(projects))
|
Ok(Json(projects))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(toggl_client, db))]
|
||||||
async fn clients(
|
async fn clients(
|
||||||
Extension(db): Extension<DatabaseConnection>,
|
Extension(db): Extension<DatabaseConnection>,
|
||||||
Extension(toggl_client): Extension<TogglClient>,
|
Extension(toggl_client): Extension<TogglClient>,
|
||||||
@ -127,6 +137,7 @@ struct RefreshQuery {
|
|||||||
start_date: Option<String>,
|
start_date: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(toggl_client, db))]
|
||||||
async fn refresh(
|
async fn refresh(
|
||||||
Extension(toggl_client): Extension<TogglClient>,
|
Extension(toggl_client): Extension<TogglClient>,
|
||||||
Extension(db): Extension<DatabaseConnection>,
|
Extension(db): Extension<DatabaseConnection>,
|
||||||
|
|||||||
89
src/types.rs
89
src/types.rs
@ -81,7 +81,7 @@ pub struct ProjectClient {
|
|||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
pub struct TogglQuery {
|
pub struct TogglQuery {
|
||||||
pub billable: Option<bool>,
|
pub billable: Option<bool>,
|
||||||
pub client_ids: Option<Vec<u64>>,
|
pub client_ids: Option<Vec<u64>>,
|
||||||
@ -111,3 +111,90 @@ pub struct TogglQuery {
|
|||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub rest: HashMap<String, Value>,
|
pub rest: HashMap<String, Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
impl fmt::Debug for TogglQuery {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let mut ds = f.debug_struct("TogglQuery");
|
||||||
|
|
||||||
|
if let Some(billable) = &self.billable {
|
||||||
|
ds.field("billable", billable);
|
||||||
|
}
|
||||||
|
if let Some(client_ids) = &self.client_ids {
|
||||||
|
ds.field("client_ids", client_ids);
|
||||||
|
}
|
||||||
|
if let Some(description) = &self.description {
|
||||||
|
ds.field("description", description);
|
||||||
|
}
|
||||||
|
if let Some(end_date) = &self.end_date {
|
||||||
|
ds.field("end_date", end_date);
|
||||||
|
}
|
||||||
|
if let Some(first_id) = &self.first_id {
|
||||||
|
ds.field("first_id", first_id);
|
||||||
|
}
|
||||||
|
if let Some(first_row_number) = &self.first_row_number {
|
||||||
|
ds.field("first_row_number", first_row_number);
|
||||||
|
}
|
||||||
|
if let Some(first_timestamp) = &self.first_timestamp {
|
||||||
|
ds.field("first_timestamp", first_timestamp);
|
||||||
|
}
|
||||||
|
if let Some(group_ids) = &self.group_ids {
|
||||||
|
ds.field("group_ids", group_ids);
|
||||||
|
}
|
||||||
|
if let Some(grouped) = &self.grouped {
|
||||||
|
ds.field("grouped", grouped);
|
||||||
|
}
|
||||||
|
if let Some(hide_amounts) = &self.hide_amounts {
|
||||||
|
ds.field("hide_amounts", hide_amounts);
|
||||||
|
}
|
||||||
|
if let Some(max_duration_seconds) = &self.max_duration_seconds {
|
||||||
|
ds.field("max_duration_seconds", max_duration_seconds);
|
||||||
|
}
|
||||||
|
if let Some(min_duration_seconds) = &self.min_duration_seconds {
|
||||||
|
ds.field("min_duration_seconds", min_duration_seconds);
|
||||||
|
}
|
||||||
|
if let Some(order_by) = &self.order_by {
|
||||||
|
ds.field("order_by", order_by);
|
||||||
|
}
|
||||||
|
if let Some(order_dir) = &self.order_dir {
|
||||||
|
ds.field("order_dir", order_dir);
|
||||||
|
}
|
||||||
|
if let Some(postedFields) = &self.postedFields {
|
||||||
|
ds.field("postedFields", postedFields);
|
||||||
|
}
|
||||||
|
if let Some(project_ids) = &self.project_ids {
|
||||||
|
ds.field("project_ids", project_ids);
|
||||||
|
}
|
||||||
|
if let Some(rounding) = &self.rounding {
|
||||||
|
ds.field("rounding", rounding);
|
||||||
|
}
|
||||||
|
if let Some(rounding_minutes) = &self.rounding_minutes {
|
||||||
|
ds.field("rounding_minutes", rounding_minutes);
|
||||||
|
}
|
||||||
|
if let Some(startTime) = &self.startTime {
|
||||||
|
ds.field("startTime", startTime);
|
||||||
|
}
|
||||||
|
if let Some(start_date) = &self.start_date {
|
||||||
|
ds.field("start_date", start_date);
|
||||||
|
}
|
||||||
|
if let Some(tag_ids) = &self.tag_ids {
|
||||||
|
ds.field("tag_ids", tag_ids);
|
||||||
|
}
|
||||||
|
if let Some(task_ids) = &self.task_ids {
|
||||||
|
ds.field("task_ids", task_ids);
|
||||||
|
}
|
||||||
|
if let Some(time_entry_ids) = &self.time_entry_ids {
|
||||||
|
ds.field("time_entry_ids", time_entry_ids);
|
||||||
|
}
|
||||||
|
if let Some(user_ids) = &self.user_ids {
|
||||||
|
ds.field("user_ids", user_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.rest.is_empty() {
|
||||||
|
ds.field("rest", &self.rest);
|
||||||
|
}
|
||||||
|
|
||||||
|
ds.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user