Add a basic sync route

This commit is contained in:
2024-07-27 21:18:36 +01:00
parent 5ecd691e41
commit 7f445a24e0
4 changed files with 45 additions and 20 deletions
+17 -1
View File
@@ -1,3 +1,4 @@
use axum::response::IntoResponse;
use sqlx::{Connection, PgPool};
use toggl::TogglApi;
use worker::Worker;
@@ -22,6 +23,19 @@ enum AppError {
IO(#[from] std::io::Error),
}
impl IntoResponse for AppError {
fn into_response(self) -> axum::http::Response<axum::body::Body> {
let status = match &self {
AppError::SqlxError(_) => axum::http::StatusCode::INTERNAL_SERVER_ERROR,
AppError::TogglError(_) => axum::http::StatusCode::INTERNAL_SERVER_ERROR,
AppError::LookBackTooLarge => axum::http::StatusCode::BAD_REQUEST,
AppError::IO(_) => axum::http::StatusCode::INTERNAL_SERVER_ERROR,
};
(status, self.to_string()).into_response()
}
}
struct TableSummary {
client_ids: Vec<u64>,
workspace_ids: Vec<u64>,
@@ -49,5 +63,7 @@ async fn main() {
let worker = Worker { db, toggl_api };
server::serve().await.expect("Failed to start server")
server::serve(
worker
).await.expect("Failed to start server")
}