display api stuff in frontend
This commit is contained in:
		@@ -20,6 +20,5 @@ pub fn build_api() -> Vec<Route> {
 | 
			
		||||
        version_del,
 | 
			
		||||
        build_output,
 | 
			
		||||
        list_builds,
 | 
			
		||||
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@ use rocket::http::uri::Segments;
 | 
			
		||||
use rocket::http::{ContentType, Method, Status};
 | 
			
		||||
use rocket::route::{Handler, Outcome};
 | 
			
		||||
use rocket::{Data, Request, Response, Route};
 | 
			
		||||
use rust_embed::{RustEmbed};
 | 
			
		||||
use rust_embed::RustEmbed;
 | 
			
		||||
use std::io::Cursor;
 | 
			
		||||
 | 
			
		||||
#[derive(RustEmbed)]
 | 
			
		||||
 
 | 
			
		||||
@@ -115,34 +115,37 @@ pub async fn build_output(
 | 
			
		||||
#[serde(crate = "rocket::serde")]
 | 
			
		||||
pub struct ListBuildsModel {
 | 
			
		||||
    id: i32,
 | 
			
		||||
    pkg_id: i32,
 | 
			
		||||
    version_id: i32,
 | 
			
		||||
    status: Option<i32>,
 | 
			
		||||
    pkg_name: String,
 | 
			
		||||
    version: String,
 | 
			
		||||
    status: i32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[openapi(tag = "test")]
 | 
			
		||||
#[get("/builds?<pkgid>")]
 | 
			
		||||
pub async fn list_builds(
 | 
			
		||||
    db: &State<DatabaseConnection>,
 | 
			
		||||
    pkgid: i32,
 | 
			
		||||
    pkgid: Option<i32>,
 | 
			
		||||
) -> Result<Json<Vec<ListBuildsModel>>, NotFound<String>> {
 | 
			
		||||
    let db = db as &DatabaseConnection;
 | 
			
		||||
 | 
			
		||||
    let build = Builds::find()
 | 
			
		||||
        .filter(builds::Column::PkgId.eq(pkgid))
 | 
			
		||||
        .all(db)
 | 
			
		||||
        .await
 | 
			
		||||
        .map_err(|e| NotFound(e.to_string()))?;
 | 
			
		||||
    let basequery = Builds::find()
 | 
			
		||||
        .join_rev(JoinType::InnerJoin, packages::Relation::Builds.def())
 | 
			
		||||
        .join_rev(JoinType::InnerJoin, versions::Relation::Builds.def())
 | 
			
		||||
        .select_only()
 | 
			
		||||
        .column_as(builds::Column::Id, "id")
 | 
			
		||||
        .column(builds::Column::Status)
 | 
			
		||||
        .column_as(packages::Column::Name, "pkg_name")
 | 
			
		||||
        .column(versions::Column::Version);
 | 
			
		||||
 | 
			
		||||
    Ok(Json(
 | 
			
		||||
        build
 | 
			
		||||
            .iter()
 | 
			
		||||
            .map(|x| ListBuildsModel {
 | 
			
		||||
                id: x.id,
 | 
			
		||||
                status: x.status,
 | 
			
		||||
                pkg_id: x.pkg_id,
 | 
			
		||||
                version_id: x.version_id,
 | 
			
		||||
            })
 | 
			
		||||
            .collect::<Vec<_>>(),
 | 
			
		||||
    ))
 | 
			
		||||
    let build = match pkgid {
 | 
			
		||||
        None => basequery.into_model::<ListBuildsModel>().all(db),
 | 
			
		||||
        Some(pkgid) => basequery
 | 
			
		||||
            .filter(builds::Column::PkgId.eq(pkgid))
 | 
			
		||||
            .into_model::<ListBuildsModel>()
 | 
			
		||||
            .all(db),
 | 
			
		||||
    }
 | 
			
		||||
    .await
 | 
			
		||||
    .map_err(|e| NotFound(e.to_string()))?;
 | 
			
		||||
 | 
			
		||||
    Ok(Json(build))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
mod add;
 | 
			
		||||
pub mod backend;
 | 
			
		||||
mod list;
 | 
			
		||||
mod remove;
 | 
			
		||||
#[cfg(feature = "static")]
 | 
			
		||||
pub mod embed;
 | 
			
		||||
mod list;
 | 
			
		||||
mod remove;
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,6 @@ pub async fn init(db: DatabaseConnection, tx: Sender<Action>) {
 | 
			
		||||
 | 
			
		||||
                                new_build.status = Set(Some(1));
 | 
			
		||||
                                let _ = new_build.update(&db).await;
 | 
			
		||||
 | 
			
		||||
                            }
 | 
			
		||||
                            Err(e) => {
 | 
			
		||||
                                let _ = set_pkg_status(
 | 
			
		||||
@@ -82,7 +81,7 @@ pub async fn init(db: DatabaseConnection, tx: Sender<Action>) {
 | 
			
		||||
                                .await;
 | 
			
		||||
                                let _ = version_model.update(&db).await;
 | 
			
		||||
 | 
			
		||||
                                new_build.status = Set(Some(1));
 | 
			
		||||
                                new_build.status = Set(Some(2));
 | 
			
		||||
                                let _ = new_build.update(&db).await;
 | 
			
		||||
 | 
			
		||||
                                println!("Error: {e}")
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,30 @@ pub struct Model {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
 | 
			
		||||
pub enum Relation {}
 | 
			
		||||
pub enum Relation {
 | 
			
		||||
    #[sea_orm(
 | 
			
		||||
        belongs_to = "super::versions::Entity",
 | 
			
		||||
        from = "Column::VersionId",
 | 
			
		||||
        to = "super::versions::Column::Id"
 | 
			
		||||
    )]
 | 
			
		||||
    Versions,
 | 
			
		||||
    #[sea_orm(
 | 
			
		||||
        belongs_to = "super::packages::Entity",
 | 
			
		||||
        from = "Column::PkgId",
 | 
			
		||||
        to = "super::packages::Column::Id"
 | 
			
		||||
    )]
 | 
			
		||||
    Packages,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Related<super::versions::Entity> for Entity {
 | 
			
		||||
    fn to() -> RelationDef {
 | 
			
		||||
        Relation::Versions.def()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Related<super::packages::Entity> for Entity {
 | 
			
		||||
    fn to() -> RelationDef {
 | 
			
		||||
        Relation::Packages.def()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
impl ActiveModelBehavior for ActiveModel {}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,16 +14,24 @@ pub struct Model {
 | 
			
		||||
    pub status: i32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl ActiveModelBehavior for ActiveModel {}
 | 
			
		||||
 | 
			
		||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
 | 
			
		||||
pub enum Relation {
 | 
			
		||||
    #[sea_orm(has_many = "super::versions::Entity")]
 | 
			
		||||
    Versions,
 | 
			
		||||
    #[sea_orm(has_many = "super::builds::Entity")]
 | 
			
		||||
    Builds,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl ActiveModelBehavior for ActiveModel {}
 | 
			
		||||
 | 
			
		||||
impl Related<super::versions::Entity> for Entity {
 | 
			
		||||
    fn to() -> RelationDef {
 | 
			
		||||
        Relation::Versions.def()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Related<super::builds::Entity> for crate::db::versions::Entity {
 | 
			
		||||
    fn to() -> RelationDef {
 | 
			
		||||
        crate::db::versions::Relation::Builds.def()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,8 @@ pub enum Relation {
 | 
			
		||||
        to = "super::packages::Column::Id"
 | 
			
		||||
    )]
 | 
			
		||||
    Packages,
 | 
			
		||||
    #[sea_orm(has_many = "super::builds::Entity")]
 | 
			
		||||
    Builds,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// `Related` trait has to be implemented by hand
 | 
			
		||||
@@ -32,4 +34,10 @@ impl Related<super::packages::Entity> for Entity {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// impl Related<super::builds::Entity> for Entity {
 | 
			
		||||
//     fn to() -> RelationDef {
 | 
			
		||||
//         Relation::Builds.def()
 | 
			
		||||
//     }
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
impl ActiveModelBehavior for ActiveModel {}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,8 @@ mod pkgbuild;
 | 
			
		||||
mod repo;
 | 
			
		||||
 | 
			
		||||
use crate::api::backend;
 | 
			
		||||
#[cfg(feature = "static")]
 | 
			
		||||
use crate::api::embed::CustomHandler;
 | 
			
		||||
use crate::builder::types::Action;
 | 
			
		||||
use crate::db::migration::Migrator;
 | 
			
		||||
use rocket::config::Config;
 | 
			
		||||
@@ -16,8 +18,6 @@ use sea_orm::{Database, DatabaseConnection};
 | 
			
		||||
use sea_orm_migration::MigratorTrait;
 | 
			
		||||
use std::fs;
 | 
			
		||||
use tokio::sync::broadcast;
 | 
			
		||||
#[cfg(feature = "static")]
 | 
			
		||||
use crate::api::embed::CustomHandler;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    let t = tokio::runtime::Runtime::new().unwrap();
 | 
			
		||||
@@ -56,7 +56,6 @@ fn main() {
 | 
			
		||||
                .manage(db)
 | 
			
		||||
                .manage(tx)
 | 
			
		||||
                .mount("/", backend::build_api())
 | 
			
		||||
 | 
			
		||||
                .mount(
 | 
			
		||||
                    "/docs/",
 | 
			
		||||
                    make_swagger_ui(&SwaggerUIConfig {
 | 
			
		||||
@@ -67,9 +66,7 @@ fn main() {
 | 
			
		||||
            #[cfg(feature = "static")]
 | 
			
		||||
            let rock = rock.mount("/", CustomHandler {});
 | 
			
		||||
 | 
			
		||||
            let rock = rock
 | 
			
		||||
                .launch()
 | 
			
		||||
                .await;
 | 
			
		||||
            let rock = rock.launch().await;
 | 
			
		||||
            match rock {
 | 
			
		||||
                Ok(_) => println!("Rocket shut down gracefully."),
 | 
			
		||||
                Err(err) => println!("Rocket had an error: {}", err),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user