1
0
Fork 0
forked from gorb/backend
backend-ci-testing/src/api/v1/stats.rs

43 lines
1.1 KiB
Rust

use std::time::SystemTime;
use actix_web::{HttpResponse, Responder, get, web};
use serde::Serialize;
use crate::Data;
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
#[derive(Serialize)]
struct Response {
accounts: usize,
uptime: u64,
version: String,
build_number: String,
}
#[get("/stats")]
pub async fn res(data: web::Data<Data>) -> impl Responder {
let accounts;
if let Ok(users) = sqlx::query("SELECT uuid FROM users")
.fetch_all(&data.pool)
.await
{
accounts = users.len();
} else {
return HttpResponse::InternalServerError().finish();
}
let response = Response {
// TODO: Get number of accounts from db
accounts,
uptime: SystemTime::now()
.duration_since(data.start_time)
.expect("Seriously why dont you have time??")
.as_secs(),
version: String::from(VERSION.unwrap_or("UNKNOWN")),
// TODO: Get build number from git hash or remove this from the spec
build_number: String::from("how do i implement this?"),
};
HttpResponse::Ok().json(response)
}