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:
Wyatt Verchere
2023-12-19 10:20:32 -08:00
committed by GitHub
parent 9f798559cf
commit d59c522f7f
20 changed files with 636 additions and 78 deletions

View File

@@ -939,8 +939,8 @@ pub async fn project_get_check(
}
}
#[derive(Serialize)]
struct DependencyInfo {
#[derive(Serialize, Deserialize)]
pub struct DependencyInfo {
pub projects: Vec<Project>,
pub versions: Vec<models::projects::Version>,
}

View File

@@ -1,12 +1,19 @@
use crate::routes::ApiError;
use actix_web::{web, HttpResponse};
use serde_json::json;
use sqlx::PgPool;
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.route("statistics", web::get().to(get_stats));
}
#[derive(serde::Serialize, serde::Deserialize)]
pub struct V3Stats {
pub projects: Option<i64>,
pub versions: Option<i64>,
pub authors: Option<i64>,
pub files: Option<i64>,
}
pub async fn get_stats(pool: web::Data<PgPool>) -> Result<HttpResponse, ApiError> {
let projects = sqlx::query!(
"
@@ -74,12 +81,12 @@ pub async fn get_stats(pool: web::Data<PgPool>) -> Result<HttpResponse, ApiError
.fetch_one(&**pool)
.await?;
let json = json!({
"projects": projects.count,
"versions": versions.count,
"authors": authors.count,
"files": files.count,
});
let v3_stats = V3Stats {
projects: projects.count,
versions: versions.count,
authors: authors.count,
files: files.count,
};
Ok(HttpResponse::Ok().json(json))
Ok(HttpResponse::Ok().json(v3_stats))
}

View File

@@ -166,10 +166,10 @@ pub async fn loader_fields_list(
Ok(HttpResponse::Ok().json(results))
}
#[derive(serde::Serialize)]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct License {
short: String,
name: String,
pub short: String,
pub name: String,
}
pub async fn license_list() -> HttpResponse {
@@ -186,10 +186,10 @@ pub async fn license_list() -> HttpResponse {
HttpResponse::Ok().json(results)
}
#[derive(serde::Serialize)]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct LicenseText {
title: String,
body: String,
pub title: String,
pub body: String,
}
pub async fn license_text(params: web::Path<(String,)>) -> Result<HttpResponse, ApiError> {