swarm / companies/starter/work/project/src/api/status.rs

raw file 584 bytes
use actix_web::{web, HttpResponse, HttpMessage};
use sqlx::PgPool;
use std::time::Duration;

pub struct StatusData {
    pub status: String,
    pub last_sync: chrono::DateTime<chrono::Utc>,
}

pub async fn get_status(
    pool: web::Data<PgPool>,
) -> Result<HttpResponse, actix_web::Error> {
    // Query the last successful sync time
    let last_sync: Option<chrono::DateTime<chrono::Utc>> = sqlx::query_scalar(
        "SELECT MAX(completed_at) FROM sync_batches WHERE status = 'success'"
    )
    .fetch_optional(&pool)
    .await
    .map_err(|e| {
        log::error!("Failed