chore: mv routes to separate crate for reusability
This commit is contained in:
parent
d3fde704ff
commit
7b3bc8161e
6 changed files with 359 additions and 332 deletions
600
Cargo.lock
generated
600
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -41,6 +41,8 @@ log = "0.4.16"
|
||||||
pretty_env_logger = "0.4"
|
pretty_env_logger = "0.4"
|
||||||
rust-embed = "6.3.0"
|
rust-embed = "6.3.0"
|
||||||
urlencoding = "2.1.0"
|
urlencoding = "2.1.0"
|
||||||
|
clap = { version = "4.0.32", features = ["derive"] }
|
||||||
|
api_routes = { path ="./api_routes/"}
|
||||||
|
|
||||||
[dependencies.cache-buster]
|
[dependencies.cache-buster]
|
||||||
git = "https://github.com/realaravinth/cache-buster"
|
git = "https://github.com/realaravinth/cache-buster"
|
||||||
|
@ -83,7 +85,7 @@ path = "./federate/publiccodeyml"
|
||||||
|
|
||||||
[dependencies.sqlx]
|
[dependencies.sqlx]
|
||||||
features = ["runtime-actix-rustls", "uuid", "postgres", "time", "offline", "sqlite"]
|
features = ["runtime-actix-rustls", "uuid", "postgres", "time", "offline", "sqlite"]
|
||||||
version = "0.5.11"
|
version = "0.6.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
mktemp = "0.4.1"
|
mktemp = "0.4.1"
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -68,6 +68,7 @@ check: ## Check for syntax errors on all workspaces
|
||||||
cd federate/federate-core && cargo check --tests --all-features
|
cd federate/federate-core && cargo check --tests --all-features
|
||||||
cd federate/publiccodeyml && cargo check --tests --all-features
|
cd federate/publiccodeyml && cargo check --tests --all-features
|
||||||
cd utils/cache-bust && cargo check --tests --all-features
|
cd utils/cache-bust && cargo check --tests --all-features
|
||||||
|
cd api_routes && cargo check --tests --all-features
|
||||||
|
|
||||||
dev-env: ## Download development dependencies
|
dev-env: ## Download development dependencies
|
||||||
$(call launch_test_env)
|
$(call launch_test_env)
|
||||||
|
@ -96,6 +97,7 @@ run: default ## Run debug build
|
||||||
|
|
||||||
migrate: ## run migrations
|
migrate: ## run migrations
|
||||||
@-rm -rf db/db-sqlx-sqlite/tmp && mkdir db/db-sqlx-sqlite/tmp
|
@-rm -rf db/db-sqlx-sqlite/tmp && mkdir db/db-sqlx-sqlite/tmp
|
||||||
|
@-rm -rf db/migrator/target/
|
||||||
cd db/migrator && cargo run
|
cd db/migrator && cargo run
|
||||||
# echo TODO: add migrations
|
# echo TODO: add migrations
|
||||||
|
|
||||||
|
|
17
api_routes/Cargo.toml
Normal file
17
api_routes/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[package]
|
||||||
|
name = "api_routes"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
repository = "https://github.com/forgeflux-org/starchart"
|
||||||
|
authors = ["realaravinth <realaravinth@batsense.net>"]
|
||||||
|
description = "ForgeFlux StarChart - Federated forge spider"
|
||||||
|
documentation = "https://forgeflux.org/"
|
||||||
|
license = "AGPLv3 or later version"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
features = ["derive"]
|
||||||
|
version = "1"
|
37
api_routes/src/lib.rs
Normal file
37
api_routes/src/lib.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* ForgeFlux StarChart - A federated software forge spider
|
||||||
|
* Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub const ROUTES: Api = Api::new();
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct Api {
|
||||||
|
pub get_latest: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Api {
|
||||||
|
const fn new() -> Api {
|
||||||
|
let get_latest = "/api/v1/federated/latest";
|
||||||
|
Api { get_latest }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct LatestResp {
|
||||||
|
pub latest: String,
|
||||||
|
}
|
31
src/api.rs
31
src/api.rs
|
@ -18,40 +18,15 @@
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
use actix_web::{HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder};
|
||||||
use actix_web_codegen_const_routes::get;
|
use actix_web_codegen_const_routes::get;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
pub use api_routes::*;
|
||||||
|
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::WebFederate;
|
use crate::WebFederate;
|
||||||
|
|
||||||
pub const ROUTES: Api = Api::new();
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub struct Api {
|
|
||||||
pub get_latest: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Api {
|
|
||||||
const fn new() -> Api {
|
|
||||||
let get_latest = "/api/v1/federated/latest";
|
|
||||||
Api { get_latest }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub struct LatestResp {
|
|
||||||
pub latest: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LatestResp {
|
|
||||||
pub async fn new(federate: &WebFederate) -> Self {
|
|
||||||
let latest = federate.latest_tar().await.unwrap();
|
|
||||||
LatestResp { latest }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get(path = "ROUTES.get_latest")]
|
#[get(path = "ROUTES.get_latest")]
|
||||||
pub async fn lastest(federate: WebFederate) -> ServiceResult<impl Responder> {
|
pub async fn lastest(federate: WebFederate) -> ServiceResult<impl Responder> {
|
||||||
let latest = LatestResp::new(&federate).await;
|
let latest = federate.latest_tar_json().await.unwrap();
|
||||||
Ok(HttpResponse::Ok().json(latest))
|
Ok(HttpResponse::Ok().json(latest))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue