add apibuilder widget to make api callsmore straightforward and data updateable from everywhere through providers
This commit is contained in:
		@@ -1,14 +1,15 @@
 | 
			
		||||
use crate::api::add::okapi_add_operation_for_package_add_;
 | 
			
		||||
use crate::api::add::package_add;
 | 
			
		||||
use crate::api::list::{get_build, okapi_add_operation_for_list_builds_};
 | 
			
		||||
use crate::api::list::okapi_add_operation_for_get_build_;
 | 
			
		||||
use crate::api::list::okapi_add_operation_for_get_package_;
 | 
			
		||||
use crate::api::list::okapi_add_operation_for_stats_;
 | 
			
		||||
use crate::api::list::{build_output, okapi_add_operation_for_package_list_};
 | 
			
		||||
use crate::api::list::{get_build, get_package, okapi_add_operation_for_list_builds_};
 | 
			
		||||
use crate::api::list::{list_builds, okapi_add_operation_for_search_};
 | 
			
		||||
use crate::api::list::{okapi_add_operation_for_build_output_, stats};
 | 
			
		||||
use crate::api::list::{package_list, search};
 | 
			
		||||
use crate::api::remove::okapi_add_operation_for_package_del_;
 | 
			
		||||
use crate::api::remove::okapi_add_operation_for_version_del_;
 | 
			
		||||
use crate::api::list::okapi_add_operation_for_get_build_;
 | 
			
		||||
use crate::api::remove::{package_del, version_del};
 | 
			
		||||
use rocket::Route;
 | 
			
		||||
use rocket_okapi::openapi_get_routes;
 | 
			
		||||
@@ -23,6 +24,7 @@ pub fn build_api() -> Vec<Route> {
 | 
			
		||||
        build_output,
 | 
			
		||||
        list_builds,
 | 
			
		||||
        stats,
 | 
			
		||||
        get_build
 | 
			
		||||
        get_build,
 | 
			
		||||
        get_package
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ use rocket::serde::{Deserialize, Serialize};
 | 
			
		||||
use rocket::{get, State};
 | 
			
		||||
use rocket_okapi::okapi::schemars;
 | 
			
		||||
use rocket_okapi::{openapi, JsonSchema};
 | 
			
		||||
use sea_orm::{PaginatorTrait};
 | 
			
		||||
use sea_orm::PaginatorTrait;
 | 
			
		||||
use sea_orm::{ColumnTrait, QueryFilter};
 | 
			
		||||
use sea_orm::{DatabaseConnection, EntityTrait, FromQueryResult, QuerySelect, RelationTrait};
 | 
			
		||||
 | 
			
		||||
@@ -70,6 +70,32 @@ pub async fn package_list(
 | 
			
		||||
    Ok(Json(all))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[openapi(tag = "test")]
 | 
			
		||||
#[get("/package/<id>")]
 | 
			
		||||
pub async fn get_package(
 | 
			
		||||
    db: &State<DatabaseConnection>,
 | 
			
		||||
    id: u64,
 | 
			
		||||
) -> Result<Json<ListPackageModel>, NotFound<String>> {
 | 
			
		||||
    let db = db as &DatabaseConnection;
 | 
			
		||||
 | 
			
		||||
    let all: ListPackageModel = Packages::find()
 | 
			
		||||
        .join_rev(JoinType::InnerJoin, versions::Relation::Packages.def())
 | 
			
		||||
        .filter(packages::Column::Id.eq(id))
 | 
			
		||||
        .select_only()
 | 
			
		||||
        .column_as(versions::Column::Id.count(), "count")
 | 
			
		||||
        .column(packages::Column::Name)
 | 
			
		||||
        .column(packages::Column::Id)
 | 
			
		||||
        .column(packages::Column::Status)
 | 
			
		||||
        .group_by(packages::Column::Name)
 | 
			
		||||
        .into_model::<ListPackageModel>()
 | 
			
		||||
        .one(db)
 | 
			
		||||
        .await
 | 
			
		||||
        .map_err(|e| NotFound(e.to_string()))?
 | 
			
		||||
        .ok_or(NotFound("id not found".to_string()))?;
 | 
			
		||||
 | 
			
		||||
    Ok(Json(all))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[openapi(tag = "test")]
 | 
			
		||||
#[get("/builds/output?<buildid>&<startline>")]
 | 
			
		||||
pub async fn build_output(
 | 
			
		||||
@@ -172,7 +198,10 @@ pub async fn get_build(
 | 
			
		||||
        .column_as(packages::Column::Name, "pkg_name")
 | 
			
		||||
        .column(versions::Column::Version)
 | 
			
		||||
        .into_model::<ListBuildsModel>()
 | 
			
		||||
        .one(db).await.map_err(|e| NotFound(e.to_string()))?.ok_or(NotFound("no item with id found".to_string()))?;
 | 
			
		||||
        .one(db)
 | 
			
		||||
        .await
 | 
			
		||||
        .map_err(|e| NotFound(e.to_string()))?
 | 
			
		||||
        .ok_or(NotFound("no item with id found".to_string()))?;
 | 
			
		||||
 | 
			
		||||
    Ok(Json(result))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,22 +6,12 @@ use rocket_okapi::okapi::schemars;
 | 
			
		||||
use rocket_okapi::{openapi, JsonSchema};
 | 
			
		||||
use sea_orm::DatabaseConnection;
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize, JsonSchema)]
 | 
			
		||||
#[serde(crate = "rocket::serde")]
 | 
			
		||||
pub struct DelBody {
 | 
			
		||||
    id: i32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[openapi(tag = "test")]
 | 
			
		||||
#[post("/packages/delete", data = "<input>")]
 | 
			
		||||
pub async fn package_del(
 | 
			
		||||
    db: &State<DatabaseConnection>,
 | 
			
		||||
    input: Json<DelBody>,
 | 
			
		||||
) -> Result<(), String> {
 | 
			
		||||
#[post("/package/delete/<id>")]
 | 
			
		||||
pub async fn package_del(db: &State<DatabaseConnection>, id: i32) -> Result<(), String> {
 | 
			
		||||
    let db = db as &DatabaseConnection;
 | 
			
		||||
    let pkg_id = input.id.clone();
 | 
			
		||||
 | 
			
		||||
    remove_pkg(db, pkg_id).await.map_err(|e| e.to_string())?;
 | 
			
		||||
    remove_pkg(db, id).await.map_err(|e| e.to_string())?;
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user