forked from didirus/AstralRinth
Sanity checked all of V2 route conversions (#803)
* follows * all v2 routes now either convert or have a comment * added common structs, clippy * merge fix --------- Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
use crate::routes::{v2_reroute, v3, ApiError};
|
||||
use crate::routes::{
|
||||
v2_reroute,
|
||||
v3::{self, statistics::V3Stats},
|
||||
ApiError,
|
||||
};
|
||||
use actix_web::{get, web, HttpResponse};
|
||||
use sqlx::PgPool;
|
||||
|
||||
@@ -6,9 +10,30 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(get_stats);
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct V2Stats {
|
||||
pub projects: Option<i64>,
|
||||
pub versions: Option<i64>,
|
||||
pub authors: Option<i64>,
|
||||
pub files: Option<i64>,
|
||||
}
|
||||
|
||||
#[get("statistics")]
|
||||
pub async fn get_stats(pool: web::Data<PgPool>) -> Result<HttpResponse, ApiError> {
|
||||
v3::statistics::get_stats(pool)
|
||||
let response = v3::statistics::get_stats(pool)
|
||||
.await
|
||||
.or_else(v2_reroute::flatten_404_error)
|
||||
.or_else(v2_reroute::flatten_404_error)?;
|
||||
|
||||
match v2_reroute::extract_ok_json::<V3Stats>(response).await {
|
||||
Ok(stats) => {
|
||||
let stats = V2Stats {
|
||||
projects: stats.projects,
|
||||
versions: stats.versions,
|
||||
authors: stats.authors,
|
||||
files: stats.files,
|
||||
};
|
||||
Ok(HttpResponse::Ok().json(stats))
|
||||
}
|
||||
Err(response) => Ok(response),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user